diff options
146 files changed, 18752 insertions, 18491 deletions
diff --git a/mesalib/Android.common.mk b/mesalib/Android.common.mk index 83177a0cb..f28ddc2ef 100644 --- a/mesalib/Android.common.mk +++ b/mesalib/Android.common.mk @@ -24,6 +24,12 @@ LOCAL_C_INCLUDES += \ $(MESA_TOP)/include +# define ANDROID_VERSION (e.g., 4.0.x => 0x0400) +major := $(word 1, $(subst ., , $(PLATFORM_VERSION))) +minor := $(word 2, $(subst ., , $(PLATFORM_VERSION))) +LOCAL_CFLAGS += \ + -DANDROID_VERSION=0x0$(major)0$(minor) + LOCAL_CFLAGS += \ -DPTHREADS \ -fvisibility=hidden \ diff --git a/mesalib/include/EGL/eglext.h b/mesalib/include/EGL/eglext.h index 0449ae2cd..9484b83c6 100644 --- a/mesalib/include/EGL/eglext.h +++ b/mesalib/include/EGL/eglext.h @@ -392,7 +392,6 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EG #ifndef EGL_ANDROID_image_native_buffer #define EGL_ANDROID_image_native_buffer 1 -struct android_native_buffer_t; #define EGL_NATIVE_BUFFER_ANDROID 0x3140 /* eglCreateImageKHR target */ #endif diff --git a/mesalib/src/gallium/auxiliary/util/u_caps.c b/mesalib/src/gallium/auxiliary/util/u_caps.c index fbe265d0e..623070755 100644 --- a/mesalib/src/gallium/auxiliary/util/u_caps.c +++ b/mesalib/src/gallium/auxiliary/util/u_caps.c @@ -1,270 +1,269 @@ -/**************************************************************************
- *
- * Copyright 2010 Vmware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#include "pipe/p_screen.h"
-#include "util/u_format.h"
-#include "util/u_debug.h"
-#include "u_caps.h"
-
-/**
- * Iterates over a list of caps checks as defined in u_caps.h. Should
- * all checks pass returns TRUE and out is set to the last element of
- * the list (TERMINATE). Should any check fail returns FALSE and set
- * out to the index of the start of the first failing check.
- */
-boolean
-util_check_caps_out(struct pipe_screen *screen, const unsigned *list, int *out)
-{
- int i, tmpi;
- float tmpf;
-
- for (i = 0; list[i];) {
- switch(list[i++]) {
- case UTIL_CAPS_CHECK_CAP:
- if (!screen->get_param(screen, list[i++])) {
- *out = i - 2;
- return FALSE;
- }
- break;
- case UTIL_CAPS_CHECK_INT:
- tmpi = screen->get_param(screen, list[i++]);
- if (tmpi < (int)list[i++]) {
- *out = i - 3;
- return FALSE;
- }
- break;
- case UTIL_CAPS_CHECK_FLOAT:
- tmpf = screen->get_paramf(screen, list[i++]);
- if (tmpf < (float)list[i++]) {
- *out = i - 3;
- return FALSE;
- }
- break;
- case UTIL_CAPS_CHECK_FORMAT:
- if (!screen->is_format_supported(screen,
- list[i++],
- PIPE_TEXTURE_2D,
- 0,
- PIPE_BIND_SAMPLER_VIEW)) {
- *out = i - 2;
- return FALSE;
- }
- break;
- case UTIL_CAPS_CHECK_SHADER:
- tmpi = screen->get_shader_param(screen, list[i] >> 24, list[i] & ((1 << 24) - 1));
- ++i;
- if (tmpi < (int)list[i++]) {
- *out = i - 3;
- return FALSE;
- }
- break;
- case UTIL_CAPS_CHECK_UNIMPLEMENTED:
- *out = i - 1;
- return FALSE;
- default:
- assert(!"Unsupported check");
- return FALSE;
- }
- }
-
- *out = i;
- return TRUE;
-}
-
-/**
- * Iterates over a list of caps checks as defined in u_caps.h.
- * Returns TRUE if all caps checks pass returns FALSE otherwise.
- */
-boolean
-util_check_caps(struct pipe_screen *screen, const unsigned *list)
-{
- int out;
- return util_check_caps_out(screen, list, &out);
-}
-
-
-/*
- * Below follows some demo lists.
- *
- * None of these lists are exhausting lists of what is
- * actually needed to support said API and more here for
- * as example on how to uses the above functions. Especially
- * for DX10 and DX11 where Gallium is missing features.
- */
-
-/* DX 9_1 */
-static unsigned caps_dx_9_1[] = {
- UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
- UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
- UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
- UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
- UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 2),
- UTIL_CHECK_TERMINATE
-};
-
-/* DX 9_2 */
-static unsigned caps_dx_9_2[] = {
- UTIL_CHECK_CAP(OCCLUSION_QUERY),
- UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
- UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
- UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
- UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
- UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
- UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
- UTIL_CHECK_TERMINATE
-};
-
-/* DX 9_3 */
-static unsigned caps_dx_9_3[] = {
- UTIL_CHECK_CAP(SM3),
- //UTIL_CHECK_CAP(INSTANCING),
- UTIL_CHECK_CAP(OCCLUSION_QUERY),
- UTIL_CHECK_INT(MAX_RENDER_TARGETS, 4),
- UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 13), /* 4096 */
- UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
- UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
- UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
- UTIL_CHECK_TERMINATE
-};
-
-/* DX 10 */
-static unsigned caps_dx_10[] = {
- UTIL_CHECK_CAP(SM3),
- //UTIL_CHECK_CAP(INSTANCING),
- UTIL_CHECK_CAP(OCCLUSION_QUERY),
- UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8),
- UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 8192 */
- UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */
- UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 8192 */
- UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
- UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */
- UTIL_CHECK_TERMINATE
-};
-
-/* DX11 */
-static unsigned caps_dx_11[] = {
- UTIL_CHECK_CAP(SM3),
- //UTIL_CHECK_CAP(INSTANCING),
- UTIL_CHECK_CAP(OCCLUSION_QUERY),
- UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8),
- UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 16384 */
- UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */
- UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 16384 */
- UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16),
- UTIL_CHECK_FORMAT(B8G8R8A8_UNORM),
- UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */
- UTIL_CHECK_TERMINATE
-};
-
-/* OpenGL 2.1 */
-static unsigned caps_opengl_2_1[] = {
- UTIL_CHECK_CAP(GLSL),
- UTIL_CHECK_CAP(OCCLUSION_QUERY),
- UTIL_CHECK_CAP(TWO_SIDED_STENCIL),
- UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
- UTIL_CHECK_INT(MAX_RENDER_TARGETS, 2),
- UTIL_CHECK_TERMINATE
-};
-
-/* OpenGL 3.0 */
-/* UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), */
-
-/* Shader Model 3 */
-static unsigned caps_sm3[] = {
- UTIL_CHECK_SHADER(FRAGMENT, MAX_INSTRUCTIONS, 512),
- UTIL_CHECK_SHADER(FRAGMENT, MAX_INPUTS, 10),
- UTIL_CHECK_SHADER(FRAGMENT, MAX_TEMPS, 32),
- UTIL_CHECK_SHADER(FRAGMENT, MAX_ADDRS, 1),
- UTIL_CHECK_SHADER(FRAGMENT, MAX_CONSTS, 224),
-
- UTIL_CHECK_SHADER(VERTEX, MAX_INSTRUCTIONS, 512),
- UTIL_CHECK_SHADER(VERTEX, MAX_INPUTS, 16),
- UTIL_CHECK_SHADER(VERTEX, MAX_TEMPS, 32),
- UTIL_CHECK_SHADER(VERTEX, MAX_ADDRS, 2),
- UTIL_CHECK_SHADER(VERTEX, MAX_CONSTS, 256),
-
- UTIL_CHECK_TERMINATE
-};
-
-/**
- * Demo function which checks against theoretical caps needed for different APIs.
- */
-void util_caps_demo_print(struct pipe_screen *screen)
-{
- struct {
- char* name;
- unsigned *list;
- } list[] = {
- {"DX 9.1", caps_dx_9_1},
- {"DX 9.2", caps_dx_9_2},
- {"DX 9.3", caps_dx_9_3},
- {"DX 10", caps_dx_10},
- {"DX 11", caps_dx_11},
- {"OpenGL 2.1", caps_opengl_2_1},
-/* {"OpenGL 3.0", caps_opengl_3_0},*/
- {"SM3", caps_sm3},
- {NULL, NULL}
- };
- int i, out = 0;
-
- for (i = 0; list[i].name; i++) {
- if (util_check_caps_out(screen, list[i].list, &out)) {
- debug_printf("%s: %s yes\n", __FUNCTION__, list[i].name);
- continue;
- }
- switch (list[i].list[out]) {
- case UTIL_CAPS_CHECK_CAP:
- debug_printf("%s: %s no (cap %u not supported)\n", __FUNCTION__,
- list[i].name,
- list[i].list[out + 1]);
- break;
- case UTIL_CAPS_CHECK_INT:
- debug_printf("%s: %s no (cap %u less then %u)\n", __FUNCTION__,
- list[i].name,
- list[i].list[out + 1],
- list[i].list[out + 2]);
- break;
- case UTIL_CAPS_CHECK_FLOAT:
- debug_printf("%s: %s no (cap %u less then %f)\n", __FUNCTION__,
- list[i].name,
- list[i].list[out + 1],
- (double)(int)list[i].list[out + 2]);
- break;
- case UTIL_CAPS_CHECK_FORMAT:
- debug_printf("%s: %s no (format %s not supported)\n", __FUNCTION__,
- list[i].name,
- util_format_name(list[i].list[out + 1]) + 12);
- break;
- case UTIL_CAPS_CHECK_UNIMPLEMENTED:
- debug_printf("%s: %s no (not implemented in gallium or state tracker)\n",
- __FUNCTION__, list[i].name);
- break;
- default:
- assert(!"Unsupported check");
- }
- }
-}
+/************************************************************************** + * + * Copyright 2010 Vmware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_screen.h" +#include "util/u_format.h" +#include "util/u_debug.h" +#include "u_caps.h" + +/** + * Iterates over a list of caps checks as defined in u_caps.h. Should + * all checks pass returns TRUE and out is set to the last element of + * the list (TERMINATE). Should any check fail returns FALSE and set + * out to the index of the start of the first failing check. + */ +boolean +util_check_caps_out(struct pipe_screen *screen, const unsigned *list, int *out) +{ + int i, tmpi; + float tmpf; + + for (i = 0; list[i];) { + switch(list[i++]) { + case UTIL_CAPS_CHECK_CAP: + if (!screen->get_param(screen, list[i++])) { + *out = i - 2; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_INT: + tmpi = screen->get_param(screen, list[i++]); + if (tmpi < (int)list[i++]) { + *out = i - 3; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_FLOAT: + tmpf = screen->get_paramf(screen, list[i++]); + if (tmpf < (float)list[i++]) { + *out = i - 3; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_FORMAT: + if (!screen->is_format_supported(screen, + list[i++], + PIPE_TEXTURE_2D, + 0, + PIPE_BIND_SAMPLER_VIEW)) { + *out = i - 2; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_SHADER: + tmpi = screen->get_shader_param(screen, list[i] >> 24, list[i] & ((1 << 24) - 1)); + ++i; + if (tmpi < (int)list[i++]) { + *out = i - 3; + return FALSE; + } + break; + case UTIL_CAPS_CHECK_UNIMPLEMENTED: + *out = i - 1; + return FALSE; + default: + assert(!"Unsupported check"); + return FALSE; + } + } + + *out = i; + return TRUE; +} + +/** + * Iterates over a list of caps checks as defined in u_caps.h. + * Returns TRUE if all caps checks pass returns FALSE otherwise. + */ +boolean +util_check_caps(struct pipe_screen *screen, const unsigned *list) +{ + int out; + return util_check_caps_out(screen, list, &out); +} + + +/* + * Below follows some demo lists. + * + * None of these lists are exhausting lists of what is + * actually needed to support said API and more here for + * as example on how to uses the above functions. Especially + * for DX10 and DX11 where Gallium is missing features. + */ + +/* DX 9_1 */ +static unsigned caps_dx_9_1[] = { + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 2), + UTIL_CHECK_TERMINATE +}; + +/* DX 9_2 */ +static unsigned caps_dx_9_2[] = { + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16), + UTIL_CHECK_TERMINATE +}; + +/* DX 9_3 */ +static unsigned caps_dx_9_3[] = { + UTIL_CHECK_CAP(SM3), + //UTIL_CHECK_CAP(INSTANCING), + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 4), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 13), /* 4096 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16), + UTIL_CHECK_TERMINATE +}; + +/* DX 10 */ +static unsigned caps_dx_10[] = { + UTIL_CHECK_CAP(SM3), + //UTIL_CHECK_CAP(INSTANCING), + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 8192 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 8192 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16), + UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */ + UTIL_CHECK_TERMINATE +}; + +/* DX11 */ +static unsigned caps_dx_11[] = { + UTIL_CHECK_CAP(SM3), + //UTIL_CHECK_CAP(INSTANCING), + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), + UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 14), /* 16384 */ + UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 12), /* 2048 */ + UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 14), /* 16384 */ + UTIL_CHECK_FLOAT(MAX_TEXTURE_ANISOTROPY, 16), + UTIL_CHECK_FORMAT(B8G8R8A8_UNORM), + UTIL_CHECK_UNIMPLEMENTED, /* XXX Unimplemented features in Gallium */ + UTIL_CHECK_TERMINATE +}; + +/* OpenGL 2.1 */ +static unsigned caps_opengl_2_1[] = { + UTIL_CHECK_CAP(OCCLUSION_QUERY), + UTIL_CHECK_CAP(TWO_SIDED_STENCIL), + UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE), + UTIL_CHECK_INT(MAX_RENDER_TARGETS, 2), + UTIL_CHECK_TERMINATE +}; + +/* OpenGL 3.0 */ +/* UTIL_CHECK_INT(MAX_RENDER_TARGETS, 8), */ + +/* Shader Model 3 */ +static unsigned caps_sm3[] = { + UTIL_CHECK_SHADER(FRAGMENT, MAX_INSTRUCTIONS, 512), + UTIL_CHECK_SHADER(FRAGMENT, MAX_INPUTS, 10), + UTIL_CHECK_SHADER(FRAGMENT, MAX_TEMPS, 32), + UTIL_CHECK_SHADER(FRAGMENT, MAX_ADDRS, 1), + UTIL_CHECK_SHADER(FRAGMENT, MAX_CONSTS, 224), + + UTIL_CHECK_SHADER(VERTEX, MAX_INSTRUCTIONS, 512), + UTIL_CHECK_SHADER(VERTEX, MAX_INPUTS, 16), + UTIL_CHECK_SHADER(VERTEX, MAX_TEMPS, 32), + UTIL_CHECK_SHADER(VERTEX, MAX_ADDRS, 2), + UTIL_CHECK_SHADER(VERTEX, MAX_CONSTS, 256), + + UTIL_CHECK_TERMINATE +}; + +/** + * Demo function which checks against theoretical caps needed for different APIs. + */ +void util_caps_demo_print(struct pipe_screen *screen) +{ + struct { + char* name; + unsigned *list; + } list[] = { + {"DX 9.1", caps_dx_9_1}, + {"DX 9.2", caps_dx_9_2}, + {"DX 9.3", caps_dx_9_3}, + {"DX 10", caps_dx_10}, + {"DX 11", caps_dx_11}, + {"OpenGL 2.1", caps_opengl_2_1}, +/* {"OpenGL 3.0", caps_opengl_3_0},*/ + {"SM3", caps_sm3}, + {NULL, NULL} + }; + int i, out = 0; + + for (i = 0; list[i].name; i++) { + if (util_check_caps_out(screen, list[i].list, &out)) { + debug_printf("%s: %s yes\n", __FUNCTION__, list[i].name); + continue; + } + switch (list[i].list[out]) { + case UTIL_CAPS_CHECK_CAP: + debug_printf("%s: %s no (cap %u not supported)\n", __FUNCTION__, + list[i].name, + list[i].list[out + 1]); + break; + case UTIL_CAPS_CHECK_INT: + debug_printf("%s: %s no (cap %u less then %u)\n", __FUNCTION__, + list[i].name, + list[i].list[out + 1], + list[i].list[out + 2]); + break; + case UTIL_CAPS_CHECK_FLOAT: + debug_printf("%s: %s no (cap %u less then %f)\n", __FUNCTION__, + list[i].name, + list[i].list[out + 1], + (double)(int)list[i].list[out + 2]); + break; + case UTIL_CAPS_CHECK_FORMAT: + debug_printf("%s: %s no (format %s not supported)\n", __FUNCTION__, + list[i].name, + util_format_name(list[i].list[out + 1]) + 12); + break; + case UTIL_CAPS_CHECK_UNIMPLEMENTED: + debug_printf("%s: %s no (not implemented in gallium or state tracker)\n", + __FUNCTION__, list[i].name); + break; + default: + assert(!"Unsupported check"); + } + } +} diff --git a/mesalib/src/gallium/auxiliary/util/u_caps.h b/mesalib/src/gallium/auxiliary/util/u_caps.h index 32a3aca5c..038efc9f1 100644 --- a/mesalib/src/gallium/auxiliary/util/u_caps.h +++ b/mesalib/src/gallium/auxiliary/util/u_caps.h @@ -1,71 +1,71 @@ -/**************************************************************************
- *
- * Copyright 2010 Vmware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#ifndef U_CAPS_H
-#define U_CAPS_H
-
-#include "pipe/p_compiler.h"
-
-struct pipe_screen;
-
-enum u_caps_check_enum {
- UTIL_CAPS_CHECK_TERMINATE = 0,
- UTIL_CAPS_CHECK_CAP,
- UTIL_CAPS_CHECK_INT,
- UTIL_CAPS_CHECK_FLOAT,
- UTIL_CAPS_CHECK_FORMAT,
- UTIL_CAPS_CHECK_SHADER,
- UTIL_CAPS_CHECK_UNIMPLEMENTED,
-};
-
-#define UTIL_CHECK_CAP(cap) \
- UTIL_CAPS_CHECK_CAP, PIPE_CAP_##cap
-
-#define UTIL_CHECK_INT(cap, higher) \
- UTIL_CAPS_CHECK_INT, PIPE_CAP_##cap, (unsigned)(higher)
-
-/* Floats currently lose precision */
-#define UTIL_CHECK_FLOAT(cap, higher) \
- UTIL_CAPS_CHECK_FLOAT, PIPE_CAP_##cap, (unsigned)(int)(higher)
-
-#define UTIL_CHECK_FORMAT(format) \
- UTIL_CAPS_CHECK_FORMAT, PIPE_FORMAT_##format
-
-#define UTIL_CHECK_SHADER(shader, cap, higher) \
- UTIL_CAPS_CHECK_SHADER, (PIPE_SHADER_##shader << 24) | PIPE_SHADER_CAP_##cap, (unsigned)(higher)
-
-#define UTIL_CHECK_UNIMPLEMENTED \
- UTIL_CAPS_CHECK_UNIMPLEMENTED
-
-#define UTIL_CHECK_TERMINATE \
- UTIL_CAPS_CHECK_TERMINATE
-
-boolean util_check_caps(struct pipe_screen *screen, const unsigned *list);
-boolean util_check_caps_out(struct pipe_screen *screen, const unsigned *list, int *out);
-void util_caps_demo_print(struct pipe_screen *screen);
-
-#endif
+/************************************************************************** + * + * Copyright 2010 Vmware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_CAPS_H +#define U_CAPS_H + +#include "pipe/p_compiler.h" + +struct pipe_screen; + +enum u_caps_check_enum { + UTIL_CAPS_CHECK_TERMINATE = 0, + UTIL_CAPS_CHECK_CAP, + UTIL_CAPS_CHECK_INT, + UTIL_CAPS_CHECK_FLOAT, + UTIL_CAPS_CHECK_FORMAT, + UTIL_CAPS_CHECK_SHADER, + UTIL_CAPS_CHECK_UNIMPLEMENTED, +}; + +#define UTIL_CHECK_CAP(cap) \ + UTIL_CAPS_CHECK_CAP, PIPE_CAP_##cap + +#define UTIL_CHECK_INT(cap, higher) \ + UTIL_CAPS_CHECK_INT, PIPE_CAP_##cap, (unsigned)(higher) + +/* Floats currently lose precision */ +#define UTIL_CHECK_FLOAT(cap, higher) \ + UTIL_CAPS_CHECK_FLOAT, PIPE_CAPF_##cap, (unsigned)(int)(higher) + +#define UTIL_CHECK_FORMAT(format) \ + UTIL_CAPS_CHECK_FORMAT, PIPE_FORMAT_##format + +#define UTIL_CHECK_SHADER(shader, cap, higher) \ + UTIL_CAPS_CHECK_SHADER, (PIPE_SHADER_##shader << 24) | PIPE_SHADER_CAP_##cap, (unsigned)(higher) + +#define UTIL_CHECK_UNIMPLEMENTED \ + UTIL_CAPS_CHECK_UNIMPLEMENTED + +#define UTIL_CHECK_TERMINATE \ + UTIL_CAPS_CHECK_TERMINATE + +boolean util_check_caps(struct pipe_screen *screen, const unsigned *list); +boolean util_check_caps_out(struct pipe_screen *screen, const unsigned *list, int *out); +void util_caps_demo_print(struct pipe_screen *screen); + +#endif diff --git a/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.c b/mesalib/src/gallium/auxiliary/util/u_vbuf.c index 7e36018a0..f6da91203 100644 --- a/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.c +++ b/mesalib/src/gallium/auxiliary/util/u_vbuf.c @@ -25,7 +25,7 @@ * **************************************************************************/ -#include "util/u_vbuf_mgr.h" +#include "util/u_vbuf.h" #include "util/u_format.h" #include "util/u_inlines.h" @@ -55,13 +55,10 @@ struct u_vbuf_elements { }; struct u_vbuf_priv { - struct u_vbuf_mgr b; + struct u_vbuf b; struct pipe_context *pipe; struct translate_cache *translate_cache; - /* Whether there is any user buffer. */ - boolean any_user_vbs; - /* Vertex element state bound by the state tracker. */ void *saved_ve; /* and its associated helper structure for this module. */ @@ -74,11 +71,13 @@ struct u_vbuf_priv { void *fallback_ve; /* The vertex buffer slot index where translated vertices have been * stored in. */ - unsigned translate_vb_slot; + unsigned fallback_vb_slot; /* When binding the fallback vertex element state, we don't want to * change saved_ve and ve. This is set to TRUE in such cases. */ boolean ve_binding_lock; + /* Whether there is any user buffer. */ + boolean any_user_vbs; /* Whether there is a buffer with a non-native layout. */ boolean incompatible_vb_layout; /* Per-buffer flags. */ @@ -114,7 +113,7 @@ static void u_vbuf_init_format_caps(struct u_vbuf_priv *mgr) 0, PIPE_BIND_VERTEX_BUFFER); } -struct u_vbuf_mgr * +struct u_vbuf * u_vbuf_create(struct pipe_context *pipe, unsigned upload_buffer_size, unsigned upload_buffer_alignment, @@ -125,7 +124,7 @@ u_vbuf_create(struct pipe_context *pipe, mgr->pipe = pipe; mgr->translate_cache = translate_cache_create(); - mgr->translate_vb_slot = ~0; + mgr->fallback_vb_slot = ~0; mgr->b.uploader = u_upload_create(pipe, upload_buffer_size, upload_buffer_alignment, @@ -139,7 +138,7 @@ u_vbuf_create(struct pipe_context *pipe, return &mgr->b; } -void u_vbuf_destroy(struct u_vbuf_mgr *mgrb) +void u_vbuf_destroy(struct u_vbuf *mgrb) { struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb; unsigned i; @@ -157,6 +156,32 @@ void u_vbuf_destroy(struct u_vbuf_mgr *mgrb) } +static unsigned u_vbuf_get_free_real_vb_slot(struct u_vbuf_priv *mgr) +{ + unsigned i, nr = mgr->ve->count; + boolean used_vb[PIPE_MAX_ATTRIBS] = {0}; + + for (i = 0; i < nr; i++) { + if (!mgr->ve->incompatible_layout_elem[i]) { + unsigned index = mgr->ve->ve[i].vertex_buffer_index; + + if (!mgr->incompatible_vb[index]) { + used_vb[index] = TRUE; + } + } + } + + for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { + if (!used_vb[i]) { + if (i >= mgr->b.nr_real_vertex_buffers) { + mgr->b.nr_real_vertex_buffers = i+1; + } + return i; + } + } + return ~0; +} + static void u_vbuf_translate_begin(struct u_vbuf_priv *mgr, int min_index, int max_index) @@ -166,7 +191,7 @@ u_vbuf_translate_begin(struct u_vbuf_priv *mgr, unsigned tr_elem_index[PIPE_MAX_ATTRIBS]; struct translate *tr; boolean vb_translated[PIPE_MAX_ATTRIBS] = {0}; - uint8_t *vb_map[PIPE_MAX_ATTRIBS] = {0}, *out_map; + uint8_t *out_map; struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {0}; struct pipe_resource *out_buffer = NULL; unsigned i, num_verts, out_offset; @@ -175,9 +200,14 @@ u_vbuf_translate_begin(struct u_vbuf_priv *mgr, memset(&key, 0, sizeof(key)); memset(tr_elem_index, 0xff, sizeof(tr_elem_index)); - /* Initialize the translate key, i.e. the recipe how vertices should be - * translated. */ - memset(&key, 0, sizeof key); + /* Get a new vertex buffer slot. */ + mgr->fallback_vb_slot = u_vbuf_get_free_real_vb_slot(mgr); + + if (mgr->fallback_vb_slot == ~0) { + return; /* XXX error, not enough attribs */ + } + + /* Initialize the description of how vertices should be translated. */ for (i = 0; i < mgr->ve->count; i++) { enum pipe_format output_format = mgr->ve->native_format[i]; unsigned output_format_size = mgr->ve->native_format_size[i]; @@ -211,8 +241,8 @@ u_vbuf_translate_begin(struct u_vbuf_priv *mgr, /* Add this vertex element. */ te = &key.element[key.nr_elements]; - /*te->type; - te->instance_divisor;*/ + te->type = TRANSLATE_ELEMENT_NORMAL; + te->instance_divisor = 0; te->input_buffer = mgr->ve->ve[i].vertex_buffer_index; te->input_format = mgr->ve->ve[i].src_format; te->input_offset = mgr->ve->ve[i].src_offset; @@ -233,11 +263,11 @@ u_vbuf_translate_begin(struct u_vbuf_priv *mgr, if (vb_translated[i]) { struct pipe_vertex_buffer *vb = &mgr->b.vertex_buffer[i]; - vb_map[i] = pipe_buffer_map(mgr->pipe, vb->buffer, - PIPE_TRANSFER_READ, &vb_transfer[i]); + uint8_t *map = pipe_buffer_map(mgr->pipe, vb->buffer, + PIPE_TRANSFER_READ, &vb_transfer[i]); tr->set_buffer(tr, i, - vb_map[i] + vb->buffer_offset + vb->stride * min_index, + map + vb->buffer_offset + vb->stride * min_index, vb->stride, ~0); } } @@ -263,51 +293,39 @@ u_vbuf_translate_begin(struct u_vbuf_priv *mgr, } } - /* Setup the new vertex buffer in the first free slot. */ - mgr->translate_vb_slot = ~0; - for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { - if (!mgr->b.vertex_buffer[i].buffer) { - mgr->translate_vb_slot = i; + /* Setup the new vertex buffer. */ + mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].buffer_offset = out_offset; + mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].stride = key.output_stride; - if (i >= mgr->b.nr_vertex_buffers) { - mgr->b.nr_real_vertex_buffers = i+1; - } - break; - } - } + /* Move the buffer reference. */ + pipe_resource_reference( + &mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].buffer, NULL); + mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].buffer = out_buffer; + out_buffer = NULL; - if (mgr->translate_vb_slot != ~0) { - /* Setup the new vertex buffer. */ - pipe_resource_reference( - &mgr->b.real_vertex_buffer[mgr->translate_vb_slot].buffer, out_buffer); - mgr->b.real_vertex_buffer[mgr->translate_vb_slot].buffer_offset = out_offset; - mgr->b.real_vertex_buffer[mgr->translate_vb_slot].stride = key.output_stride; - - /* Setup new vertex elements. */ - for (i = 0; i < mgr->ve->count; i++) { - if (tr_elem_index[i] < key.nr_elements) { - te = &key.element[tr_elem_index[i]]; - mgr->fallback_velems[i].instance_divisor = mgr->ve->ve[i].instance_divisor; - mgr->fallback_velems[i].src_format = te->output_format; - mgr->fallback_velems[i].src_offset = te->output_offset; - mgr->fallback_velems[i].vertex_buffer_index = mgr->translate_vb_slot; - } else { - memcpy(&mgr->fallback_velems[i], &mgr->ve->ve[i], - sizeof(struct pipe_vertex_element)); - } + /* Setup new vertex elements. */ + for (i = 0; i < mgr->ve->count; i++) { + if (tr_elem_index[i] < key.nr_elements) { + te = &key.element[tr_elem_index[i]]; + mgr->fallback_velems[i].instance_divisor = mgr->ve->ve[i].instance_divisor; + mgr->fallback_velems[i].src_format = te->output_format; + mgr->fallback_velems[i].src_offset = te->output_offset; + mgr->fallback_velems[i].vertex_buffer_index = mgr->fallback_vb_slot; + } else { + memcpy(&mgr->fallback_velems[i], &mgr->ve->ve[i], + sizeof(struct pipe_vertex_element)); } + } - mgr->fallback_ve = - mgr->pipe->create_vertex_elements_state(mgr->pipe, mgr->ve->count, - mgr->fallback_velems); - /* Preserve saved_ve. */ - mgr->ve_binding_lock = TRUE; - mgr->pipe->bind_vertex_elements_state(mgr->pipe, mgr->fallback_ve); - mgr->ve_binding_lock = FALSE; - } + mgr->fallback_ve = + mgr->pipe->create_vertex_elements_state(mgr->pipe, mgr->ve->count, + mgr->fallback_velems); - pipe_resource_reference(&out_buffer, NULL); + /* Preserve saved_ve. */ + mgr->ve_binding_lock = TRUE; + mgr->pipe->bind_vertex_elements_state(mgr->pipe, mgr->fallback_ve); + mgr->ve_binding_lock = FALSE; } static void u_vbuf_translate_end(struct u_vbuf_priv *mgr) @@ -323,9 +341,9 @@ static void u_vbuf_translate_end(struct u_vbuf_priv *mgr) mgr->fallback_ve = NULL; /* Delete the now-unused VBO. */ - pipe_resource_reference(&mgr->b.real_vertex_buffer[mgr->translate_vb_slot].buffer, + pipe_resource_reference(&mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].buffer, NULL); - mgr->translate_vb_slot = ~0; + mgr->fallback_vb_slot = ~0; mgr->b.nr_real_vertex_buffers = mgr->b.nr_vertex_buffers; } @@ -333,7 +351,7 @@ static void u_vbuf_translate_end(struct u_vbuf_priv *mgr) case PIPE_FORMAT_##what: format = PIPE_FORMAT_##withwhat; break struct u_vbuf_elements * -u_vbuf_create_vertex_elements(struct u_vbuf_mgr *mgrb, +u_vbuf_create_vertex_elements(struct u_vbuf *mgrb, unsigned count, const struct pipe_vertex_element *attribs, struct pipe_vertex_element *native_attribs) @@ -438,7 +456,7 @@ u_vbuf_create_vertex_elements(struct u_vbuf_mgr *mgrb, return ve; } -void u_vbuf_bind_vertex_elements(struct u_vbuf_mgr *mgrb, +void u_vbuf_bind_vertex_elements(struct u_vbuf *mgrb, void *cso, struct u_vbuf_elements *ve) { @@ -454,13 +472,13 @@ void u_vbuf_bind_vertex_elements(struct u_vbuf_mgr *mgrb, } } -void u_vbuf_destroy_vertex_elements(struct u_vbuf_mgr *mgr, +void u_vbuf_destroy_vertex_elements(struct u_vbuf *mgr, struct u_vbuf_elements *ve) { FREE(ve); } -void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgrb, +void u_vbuf_set_vertex_buffers(struct u_vbuf *mgrb, unsigned count, const struct pipe_vertex_buffer *bufs) { @@ -495,7 +513,8 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgrb, mgr->b.real_vertex_buffer[i].stride = mgr->b.vertex_buffer[i].stride = vb->stride; - if (!vb->buffer) { + if (!vb->buffer || + mgr->incompatible_vb[i]) { pipe_resource_reference(&mgr->b.real_vertex_buffer[i].buffer, NULL); continue; } @@ -520,7 +539,7 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgrb, mgr->b.nr_real_vertex_buffers = count; } -void u_vbuf_set_index_buffer(struct u_vbuf_mgr *mgr, +void u_vbuf_set_index_buffer(struct u_vbuf *mgr, const struct pipe_index_buffer *ib) { if (ib && ib->buffer) { @@ -555,7 +574,7 @@ u_vbuf_upload_buffers(struct u_vbuf_priv *mgr, unsigned instance_div, first, size; /* Skip the buffer generated by translate. */ - if (index == mgr->translate_vb_slot) { + if (index == mgr->fallback_vb_slot) { continue; } @@ -617,7 +636,7 @@ u_vbuf_upload_buffers(struct u_vbuf_priv *mgr, } } -unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf_mgr *mgrb) +unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf *mgrb) { struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb; unsigned i, nr = mgr->ve->count; @@ -797,7 +816,7 @@ static void u_vbuf_get_minmax_index(struct pipe_context *pipe, } enum u_vbuf_return_flags -u_vbuf_draw_begin(struct u_vbuf_mgr *mgrb, +u_vbuf_draw_begin(struct u_vbuf *mgrb, const struct pipe_draw_info *info) { struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb; @@ -839,7 +858,7 @@ u_vbuf_draw_begin(struct u_vbuf_mgr *mgrb, return U_VBUF_BUFFERS_UPDATED; } -void u_vbuf_draw_end(struct u_vbuf_mgr *mgrb) +void u_vbuf_draw_end(struct u_vbuf *mgrb) { struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb; diff --git a/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.h b/mesalib/src/gallium/auxiliary/util/u_vbuf.h index 42ca0ac35..57b93ddea 100644 --- a/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.h +++ b/mesalib/src/gallium/auxiliary/util/u_vbuf.h @@ -55,7 +55,7 @@ struct u_vbuf_caps { /* The manager. * This structure should also be used to access vertex buffers * from a driver. */ -struct u_vbuf_mgr { +struct u_vbuf { /* This is what was set in set_vertex_buffers. * May contain user buffers. */ struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; @@ -100,41 +100,41 @@ enum u_vbuf_return_flags { }; -struct u_vbuf_mgr * +struct u_vbuf * u_vbuf_create(struct pipe_context *pipe, unsigned upload_buffer_size, unsigned upload_buffer_alignment, unsigned upload_buffer_bind, enum u_fetch_alignment fetch_alignment); -void u_vbuf_destroy(struct u_vbuf_mgr *mgr); +void u_vbuf_destroy(struct u_vbuf *mgr); struct u_vbuf_elements * -u_vbuf_create_vertex_elements(struct u_vbuf_mgr *mgr, +u_vbuf_create_vertex_elements(struct u_vbuf *mgr, unsigned count, const struct pipe_vertex_element *attrs, struct pipe_vertex_element *native_attrs); -void u_vbuf_bind_vertex_elements(struct u_vbuf_mgr *mgr, +void u_vbuf_bind_vertex_elements(struct u_vbuf *mgr, void *cso, struct u_vbuf_elements *ve); -void u_vbuf_destroy_vertex_elements(struct u_vbuf_mgr *mgr, +void u_vbuf_destroy_vertex_elements(struct u_vbuf *mgr, struct u_vbuf_elements *ve); -void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgr, +void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, unsigned count, const struct pipe_vertex_buffer *bufs); -void u_vbuf_set_index_buffer(struct u_vbuf_mgr *mgr, +void u_vbuf_set_index_buffer(struct u_vbuf *mgr, const struct pipe_index_buffer *ib); -enum u_vbuf_return_flags u_vbuf_draw_begin(struct u_vbuf_mgr *mgr, +enum u_vbuf_return_flags u_vbuf_draw_begin(struct u_vbuf *mgr, const struct pipe_draw_info *info); -unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf_mgr *mgr); +unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf *mgr); -void u_vbuf_draw_end(struct u_vbuf_mgr *mgr); +void u_vbuf_draw_end(struct u_vbuf *mgr); static INLINE struct u_vbuf_resource *u_vbuf_resource(struct pipe_resource *r) diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp index ac090c315..d5b04e9d7 100644 --- a/mesalib/src/glsl/ast_to_hir.cpp +++ b/mesalib/src/glsl/ast_to_hir.cpp @@ -2090,6 +2090,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, * The following extension do not allow the deprecated keywords: * * GL_AMD_conservative_depth + * GL_ARB_conservative_depth * GL_ARB_gpu_shader5 * GL_ARB_separate_shader_objects * GL_ARB_tesselation_shader @@ -2122,9 +2123,11 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, + qual->flags.q.depth_less + qual->flags.q.depth_unchanged; if (depth_layout_count > 0 - && !state->AMD_conservative_depth_enable) { + && !state->AMD_conservative_depth_enable + && !state->ARB_conservative_depth_enable) { _mesa_glsl_error(loc, state, - "extension GL_AMD_conservative_depth must be enabled " + "extension GL_AMD_conservative_depth or " + "GL_ARB_conservative_depth must be enabled " "to use depth layout qualifiers"); } else if (depth_layout_count > 0 && strcmp(var->name, "gl_FragDepth") != 0) { @@ -2237,7 +2240,8 @@ get_variable_being_redeclared(ir_variable *var, ast_declaration *decl, earlier->interpolation = var->interpolation; /* Layout qualifiers for gl_FragDepth. */ - } else if (state->AMD_conservative_depth_enable + } else if ((state->AMD_conservative_depth_enable || + state->ARB_conservative_depth_enable) && strcmp(var->name, "gl_FragDepth") == 0 && earlier->type == var->type && earlier->mode == var->mode) { diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y index c0457b057..2b7e65cd4 100644 --- a/mesalib/src/glsl/glcpp/glcpp-parse.y +++ b/mesalib/src/glsl/glcpp/glcpp-parse.y @@ -1135,7 +1135,7 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api) if (extensions->ARB_draw_instanced) add_builtin_define(parser, "GL_ARB_draw_instanced", 1); - if (extensions->AMD_conservative_depth) { + if (extensions->ARB_conservative_depth) { add_builtin_define(parser, "GL_AMD_conservative_depth", 1); add_builtin_define(parser, "GL_ARB_conservative_depth", 1); } diff --git a/mesalib/src/glsl/glsl_lexer.ll b/mesalib/src/glsl/glsl_lexer.ll index 49f3bc82e..c7cfedd42 100644 --- a/mesalib/src/glsl/glsl_lexer.ll +++ b/mesalib/src/glsl/glsl_lexer.ll @@ -310,6 +310,7 @@ void return VOID_TOK; layout { if ((yyextra->language_version >= 140) || yyextra->AMD_conservative_depth_enable + || yyextra->ARB_conservative_depth_enable || yyextra->ARB_explicit_attrib_location_enable || yyextra->ARB_fragment_coord_conventions_enable) { return LAYOUT_TOK; diff --git a/mesalib/src/glsl/glsl_parser.yy b/mesalib/src/glsl/glsl_parser.yy index 836390453..71ab039d6 100644 --- a/mesalib/src/glsl/glsl_parser.yy +++ b/mesalib/src/glsl/glsl_parser.yy @@ -1124,7 +1124,9 @@ layout_qualifier_id: } /* Layout qualifiers for AMD/ARB_conservative_depth. */ - if (!got_one && state->AMD_conservative_depth_enable) { + if (!got_one && + (state->AMD_conservative_depth_enable || + state->ARB_conservative_depth_enable)) { if (strcmp($1, "depth_any") == 0) { got_one = true; $$.flags.q.depth_any = 1; @@ -1141,6 +1143,11 @@ layout_qualifier_id: if (got_one && state->AMD_conservative_depth_warn) { _mesa_glsl_warning(& @1, state, + "GL_AMD_conservative_depth " + "layout qualifier `%s' is used\n", $1); + } + if (got_one && state->ARB_conservative_depth_warn) { + _mesa_glsl_warning(& @1, state, "GL_ARB_conservative_depth " "layout qualifier `%s' is used\n", $1); } diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp index 23aadb143..0b4ccac53 100644 --- a/mesalib/src/glsl/glsl_parser_extras.cpp +++ b/mesalib/src/glsl/glsl_parser_extras.cpp @@ -256,7 +256,7 @@ struct _mesa_glsl_extension { static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = { /* target availability API availability */ /* name VS GS FS GL ES supported flag */ - EXT(ARB_conservative_depth, true, false, true, true, false, AMD_conservative_depth), + EXT(ARB_conservative_depth, false, false, true, true, false, ARB_conservative_depth), EXT(ARB_draw_buffers, false, false, true, true, false, dummy_true), EXT(ARB_draw_instanced, true, false, false, true, false, ARB_draw_instanced), EXT(ARB_explicit_attrib_location, true, false, true, true, false, ARB_explicit_attrib_location), @@ -265,7 +265,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = { EXT(EXT_texture_array, true, false, true, true, false, EXT_texture_array), EXT(ARB_shader_texture_lod, true, false, true, true, false, ARB_shader_texture_lod), EXT(ARB_shader_stencil_export, false, false, true, true, false, ARB_shader_stencil_export), - EXT(AMD_conservative_depth, true, false, true, true, false, AMD_conservative_depth), + EXT(AMD_conservative_depth, false, false, true, true, false, ARB_conservative_depth), EXT(AMD_shader_stencil_export, false, false, true, true, false, ARB_shader_stencil_export), EXT(OES_texture_3D, true, false, true, false, true, EXT_texture3D), EXT(OES_EGL_image_external, true, false, true, false, true, OES_EGL_image_external), diff --git a/mesalib/src/glsl/link_uniforms.cpp b/mesalib/src/glsl/link_uniforms.cpp index ca5da3040..c7de480a5 100644 --- a/mesalib/src/glsl/link_uniforms.cpp +++ b/mesalib/src/glsl/link_uniforms.cpp @@ -114,7 +114,7 @@ class count_uniform_size : public uniform_field_visitor { public: count_uniform_size(struct string_to_uint_map *map) : num_active_uniforms(0), num_values(0), num_shader_samplers(0), - num_shader_uniforms(0), map(map) + num_shader_uniform_components(0), map(map) { /* empty */ } @@ -122,7 +122,7 @@ public: void start_shader() { this->num_shader_samplers = 0; - this->num_shader_uniforms = 0; + this->num_shader_uniform_components = 0; } /** @@ -143,7 +143,7 @@ public: /** * Number of uniforms used in the current shader */ - unsigned num_shader_uniforms; + unsigned num_shader_uniform_components; private: virtual void visit_field(const glsl_type *type, const char *name) @@ -165,7 +165,7 @@ private: * Note that samplers do not count against this limit because they * don't use any storage on current hardware. */ - this->num_shader_uniforms += values; + this->num_shader_uniform_components += values; } /* If the uniform is already in the map, there's nothing more to do. @@ -321,7 +321,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog) prog->_LinkedShaders[i]->num_samplers = uniform_size.num_shader_samplers; prog->_LinkedShaders[i]->num_uniform_components = - uniform_size.num_shader_uniforms * 4; + uniform_size.num_shader_uniform_components; } const unsigned num_user_uniforms = uniform_size.num_active_uniforms; diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c index d5a891435..8ebc05139 100644 --- a/mesalib/src/mesa/main/extensions.c +++ b/mesalib/src/mesa/main/extensions.c @@ -81,7 +81,7 @@ static const struct extension extension_table[] = { { "GL_ARB_blend_func_extended", o(ARB_blend_func_extended), GL, 2009 }, { "GL_ARB_color_buffer_float", o(ARB_color_buffer_float), GL, 2004 }, { "GL_ARB_copy_buffer", o(ARB_copy_buffer), GL, 2008 }, - { "GL_ARB_conservative_depth", o(AMD_conservative_depth), GL, 2011 }, + { "GL_ARB_conservative_depth", o(ARB_conservative_depth), GL, 2011 }, { "GL_ARB_depth_buffer_float", o(ARB_depth_buffer_float), GL, 2008 }, { "GL_ARB_depth_clamp", o(ARB_depth_clamp), GL, 2003 }, { "GL_ARB_depth_texture", o(ARB_depth_texture), GL, 2001 }, @@ -257,7 +257,7 @@ static const struct extension extension_table[] = { /* Vendor extensions */ { "GL_3DFX_texture_compression_FXT1", o(TDFX_texture_compression_FXT1), GL, 1999 }, - { "GL_AMD_conservative_depth", o(AMD_conservative_depth), GL, 2009 }, + { "GL_AMD_conservative_depth", o(ARB_conservative_depth), GL, 2009 }, { "GL_AMD_draw_buffers_blend", o(ARB_draw_buffers_blend), GL, 2009 }, { "GL_AMD_seamless_cubemap_per_texture", o(AMD_seamless_cubemap_per_texture), GL, 2009 }, { "GL_AMD_shader_stencil_export", o(ARB_shader_stencil_export), GL, 2009 }, diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c index 6e2ce7a05..080392f2b 100644 --- a/mesalib/src/mesa/main/format_unpack.c +++ b/mesalib/src/mesa/main/format_unpack.c @@ -936,7 +936,7 @@ unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n) dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = - dst[i][ACOMP] = s[i]; + dst[i][ACOMP] = _mesa_half_to_float(s[i]); } } @@ -1751,6 +1751,12 @@ unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst) } static void +unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst) +{ + memcpy(dst, src, n * sizeof(float)); +} + +static void unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst) { const GLfloat *s = ((const GLfloat *) src); @@ -1783,6 +1789,9 @@ _mesa_unpack_float_z_row(gl_format format, GLuint n, case MESA_FORMAT_Z32: unpack = unpack_float_z_Z32; break; + case MESA_FORMAT_Z32_FLOAT: + unpack = unpack_float_z_Z32F; + break; case MESA_FORMAT_Z32_FLOAT_X24S8: unpack = unpack_float_z_Z32X24S8; break; @@ -1959,7 +1968,8 @@ _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n, unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n); break; default: - _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row", + _mesa_problem(NULL, + "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row", _mesa_get_format_name(format)); return; } diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c index c6febb0e5..b934bd4d8 100644 --- a/mesalib/src/mesa/main/formats.c +++ b/mesalib/src/mesa/main/formats.c @@ -414,7 +414,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = MESA_FORMAT_Z24_S8, /* Name */ "MESA_FORMAT_Z24_S8", /* StrName */ GL_DEPTH_STENCIL, /* BaseFormat */ - GL_UNSIGNED_INT, /* DataType */ + GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 4 /* BlockWidth/Height,Bytes */ @@ -423,7 +423,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = MESA_FORMAT_S8_Z24, /* Name */ "MESA_FORMAT_S8_Z24", /* StrName */ GL_DEPTH_STENCIL, /* BaseFormat */ - GL_UNSIGNED_INT, /* DataType */ + GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 4 /* BlockWidth/Height,Bytes */ @@ -432,7 +432,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = MESA_FORMAT_Z16, /* Name */ "MESA_FORMAT_Z16", /* StrName */ GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_INT, /* DataType */ + GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 2 /* BlockWidth/Height,Bytes */ @@ -441,7 +441,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = MESA_FORMAT_X8_Z24, /* Name */ "MESA_FORMAT_X8_Z24", /* StrName */ GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_INT, /* DataType */ + GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 4 /* BlockWidth/Height,Bytes */ @@ -450,7 +450,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = MESA_FORMAT_Z24_X8, /* Name */ "MESA_FORMAT_Z24_X8", /* StrName */ GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_INT, /* DataType */ + GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 4 /* BlockWidth/Height,Bytes */ @@ -459,7 +459,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] = MESA_FORMAT_Z32, /* Name */ "MESA_FORMAT_Z32", /* StrName */ GL_DEPTH_COMPONENT, /* BaseFormat */ - GL_UNSIGNED_INT, /* DataType */ + GL_UNSIGNED_NORMALIZED, /* DataType */ 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */ 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */ 1, 1, 4 /* BlockWidth/Height,Bytes */ diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index b3427dac1..96a44266c 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -2844,6 +2844,7 @@ struct gl_extensions GLboolean ARB_ES2_compatibility; GLboolean ARB_blend_func_extended; GLboolean ARB_color_buffer_float; + GLboolean ARB_conservative_depth; GLboolean ARB_copy_buffer; GLboolean ARB_depth_buffer_float; GLboolean ARB_depth_clamp; @@ -2942,7 +2943,6 @@ struct gl_extensions GLboolean EXT_vertex_array_bgra; GLboolean OES_standard_derivatives; /* vendor extensions */ - GLboolean AMD_conservative_depth; GLboolean AMD_seamless_cubemap_per_texture; GLboolean APPLE_packed_pixels; GLboolean APPLE_vertex_array_object; diff --git a/mesalib/src/mesa/main/readpix.c b/mesalib/src/mesa/main/readpix.c index 8048a7286..a7b7ed7f2 100644 --- a/mesalib/src/mesa/main/readpix.c +++ b/mesalib/src/mesa/main/readpix.c @@ -60,7 +60,7 @@ fast_read_depth_pixels( struct gl_context *ctx, if (packing->SwapBytes) return GL_FALSE; - if (_mesa_get_format_datatype(rb->Format) != GL_UNSIGNED_INT) + if (_mesa_get_format_datatype(rb->Format) != GL_UNSIGNED_NORMALIZED) return GL_FALSE; if (!((type == GL_UNSIGNED_SHORT && rb->Format == MESA_FORMAT_Z16) || @@ -381,7 +381,7 @@ fast_read_depth_stencil_pixels_separate(struct gl_context *ctx, GLubyte *depthMap, *stencilMap; int depthStride, stencilStride, i, j; - if (_mesa_get_format_datatype(depthRb->Format) != GL_UNSIGNED_INT) + if (_mesa_get_format_datatype(depthRb->Format) != GL_UNSIGNED_NORMALIZED) return GL_FALSE; ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height, diff --git a/mesalib/src/mesa/main/texformat.c b/mesalib/src/mesa/main/texformat.c index aebe38ee0..ee9552bc0 100644 --- a/mesalib/src/mesa/main/texformat.c +++ b/mesalib/src/mesa/main/texformat.c @@ -326,6 +326,8 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat, case GL_ALPHA32F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32); RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); + RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); break; case GL_LUMINANCE16F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16); @@ -335,6 +337,8 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat, case GL_LUMINANCE32F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32); RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); + RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); break; case GL_LUMINANCE_ALPHA16F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16); @@ -344,6 +348,8 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat, case GL_LUMINANCE_ALPHA32F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32); RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); + RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); break; case GL_INTENSITY16F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16); @@ -353,15 +359,20 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat, case GL_INTENSITY32F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32); RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); + RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); break; case GL_RGB16F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32); RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); break; case GL_RGB32F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32); RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); break; case GL_RGBA16F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); @@ -369,6 +380,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat, break; case GL_RGBA32F_ARB: RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); break; default: ; /* fallthrough */ diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c index c8ea4329f..56335ad10 100644 --- a/mesalib/src/mesa/main/teximage.c +++ b/mesalib/src/mesa/main/teximage.c @@ -1021,15 +1021,8 @@ make_null_texture(GLint width, GLint height, GLint depth, GLenum format) /** - * Reset the fields of a gl_texture_image struct to zero. - * - * \param img texture image structure. - * - * This is called when a proxy texture test fails, we set all the - * image members (except DriverData) to zero. - * It's also used in glTexImage[123]D as a safeguard to be sure all - * required fields get initialized properly by the Driver.TexImage[123]D - * functions. + * Set the size and format-related fields of a gl_texture_image struct + * to zero. This is used when a proxy texture test fails. */ static void clear_teximage_fields(struct gl_texture_image *img) diff --git a/mesalib/src/mesa/main/texparam.c b/mesalib/src/mesa/main/texparam.c index 17eac5fc9..0081c3b52 100644 --- a/mesalib/src/mesa/main/texparam.c +++ b/mesalib/src/mesa/main/texparam.c @@ -884,6 +884,70 @@ _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params) } +static GLboolean +base_format_has_channel(GLenum base_format, GLenum pname) +{ + switch (pname) { + case GL_TEXTURE_RED_SIZE: + case GL_TEXTURE_RED_TYPE: + if (base_format == GL_RED || + base_format == GL_RG || + base_format == GL_RGB || + base_format == GL_RGBA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_GREEN_SIZE: + case GL_TEXTURE_GREEN_TYPE: + if (base_format == GL_RG || + base_format == GL_RGB || + base_format == GL_RGBA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_BLUE_SIZE: + case GL_TEXTURE_BLUE_TYPE: + if (base_format == GL_RGB || + base_format == GL_RGBA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_ALPHA_SIZE: + case GL_TEXTURE_ALPHA_TYPE: + if (base_format == GL_RGBA || + base_format == GL_ALPHA || + base_format == GL_LUMINANCE_ALPHA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_LUMINANCE_SIZE: + case GL_TEXTURE_LUMINANCE_TYPE: + if (base_format == GL_LUMINANCE || + base_format == GL_LUMINANCE_ALPHA) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_INTENSITY_SIZE: + case GL_TEXTURE_INTENSITY_TYPE: + if (base_format == GL_INTENSITY) { + return GL_TRUE; + } + return GL_FALSE; + case GL_TEXTURE_DEPTH_SIZE: + case GL_TEXTURE_DEPTH_TYPE: + if (base_format == GL_DEPTH_STENCIL || + base_format == GL_DEPTH_COMPONENT) { + return GL_TRUE; + } + return GL_FALSE; + default: + _mesa_warning(NULL, "%s: Unexpected channel token 0x%x\n", + __FUNCTION__, pname); + return GL_FALSE; + } + + return GL_FALSE; +} void GLAPIENTRY @@ -981,27 +1045,10 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level, *params = img->Border; break; case GL_TEXTURE_RED_SIZE: - if (img->_BaseFormat == GL_RED) { - *params = _mesa_get_format_bits(texFormat, pname); - break; - } - /* FALLTHROUGH */ case GL_TEXTURE_GREEN_SIZE: - if (img->_BaseFormat == GL_RG) { - *params = _mesa_get_format_bits(texFormat, pname); - break; - } - /* FALLTHROUGH */ case GL_TEXTURE_BLUE_SIZE: - if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA) - *params = _mesa_get_format_bits(texFormat, pname); - else - *params = 0; - break; case GL_TEXTURE_ALPHA_SIZE: - if (img->_BaseFormat == GL_ALPHA || - img->_BaseFormat == GL_LUMINANCE_ALPHA || - img->_BaseFormat == GL_RGBA) + if (base_format_has_channel(img->_BaseFormat, pname)) *params = _mesa_get_format_bits(texFormat, pname); else *params = 0; @@ -1067,46 +1114,18 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level, /* GL_ARB_texture_float */ case GL_TEXTURE_RED_TYPE_ARB: - if (!ctx->Extensions.ARB_texture_float) - goto invalid_pname; - *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_RED_SIZE) ? - _mesa_get_format_datatype(texFormat) : GL_NONE; - break; case GL_TEXTURE_GREEN_TYPE_ARB: - if (!ctx->Extensions.ARB_texture_float) - goto invalid_pname; - *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_GREEN_SIZE) ? - _mesa_get_format_datatype(texFormat) : GL_NONE; - break; case GL_TEXTURE_BLUE_TYPE_ARB: - if (!ctx->Extensions.ARB_texture_float) - goto invalid_pname; - *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_BLUE_SIZE) ? - _mesa_get_format_datatype(texFormat) : GL_NONE; - break; case GL_TEXTURE_ALPHA_TYPE_ARB: - if (!ctx->Extensions.ARB_texture_float) - goto invalid_pname; - *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_ALPHA_SIZE) ? - _mesa_get_format_datatype(texFormat) : GL_NONE; - break; case GL_TEXTURE_LUMINANCE_TYPE_ARB: - if (!ctx->Extensions.ARB_texture_float) - goto invalid_pname; - *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_LUMINANCE_SIZE) ? - _mesa_get_format_datatype(texFormat) : GL_NONE; - break; case GL_TEXTURE_INTENSITY_TYPE_ARB: - if (!ctx->Extensions.ARB_texture_float) - goto invalid_pname; - *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_INTENSITY_SIZE) ? - _mesa_get_format_datatype(texFormat) : GL_NONE; - break; case GL_TEXTURE_DEPTH_TYPE_ARB: if (!ctx->Extensions.ARB_texture_float) goto invalid_pname; - *params = _mesa_get_format_bits(texFormat, GL_TEXTURE_DEPTH_SIZE) ? - _mesa_get_format_datatype(texFormat) : GL_NONE; + if (base_format_has_channel(img->_BaseFormat, pname)) + *params = _mesa_get_format_datatype(texFormat); + else + *params = GL_NONE; break; default: diff --git a/mesalib/src/mesa/main/texstore.c b/mesalib/src/mesa/main/texstore.c index 05c1964d6..aae6b4b3b 100644 --- a/mesalib/src/mesa/main/texstore.c +++ b/mesalib/src/mesa/main/texstore.c @@ -986,12 +986,17 @@ _mesa_texstore_z32(TEXSTORE_PARAMS) { const GLuint depthScale = 0xffffffff; const GLuint texelBytes = _mesa_get_format_bytes(dstFormat); - const GLenum dstType = _mesa_get_format_datatype(dstFormat); + GLenum dstType; (void) dims; ASSERT(dstFormat == MESA_FORMAT_Z32 || dstFormat == MESA_FORMAT_Z32_FLOAT); ASSERT(texelBytes == sizeof(GLuint)); + if (dstFormat == MESA_FORMAT_Z32) + dstType = GL_UNSIGNED_INT; + else + dstType = GL_FLOAT; + if (ctx->Pixel.DepthScale == 1.0f && ctx->Pixel.DepthBias == 0.0f && !srcPacking->SwapBytes && diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c index 95805fd3c..912241b35 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c @@ -1441,6 +1441,13 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, st_validate_state(st); + if (type == GL_DEPTH_STENCIL) { + /* XXX make this more efficient */ + st_CopyPixels(ctx, srcx, srcy, width, height, dstx, dsty, GL_STENCIL); + st_CopyPixels(ctx, srcx, srcy, width, height, dstx, dsty, GL_DEPTH); + return; + } + if (type == GL_STENCIL) { /* can't use texturing to do stencil */ copy_stencil_pixels(ctx, srcx, srcy, width, height, dstx, dsty); diff --git a/mesalib/src/mesa/state_tracker/st_cb_fbo.c b/mesalib/src/mesa/state_tracker/st_cb_fbo.c index a351d1197..1e8ec0556 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_fbo.c +++ b/mesalib/src/mesa/state_tracker/st_cb_fbo.c @@ -75,8 +75,18 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx, enum pipe_format format; struct pipe_surface surf_tmpl; - format = st_choose_renderbuffer_format(screen, internalFormat, - rb->NumSamples); + if (internalFormat == GL_RGBA16_SNORM && strb->software) { + /* Special case for software accum buffers. Otherwise, if the + * call to st_choose_renderbuffer_format() fails (because the + * driver doesn't support signed 16-bit/channel colors) we'd + * just return without allocating the software accum buffer. + */ + format = PIPE_FORMAT_R16G16B16A16_SNORM; + } + else { + format = st_choose_renderbuffer_format(screen, internalFormat, + rb->NumSamples); + } if (format == PIPE_FORMAT_NONE) { return FALSE; diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c index 3563e1d9b..25a6cdc75 100644 --- a/mesalib/src/mesa/state_tracker/st_extensions.c +++ b/mesalib/src/mesa/state_tracker/st_extensions.c @@ -113,14 +113,18 @@ void st_init_limits(struct st_context *st) 1, MAX_DRAW_BUFFERS); c->MaxLineWidth - = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH)); + = _maxf(1.0f, screen->get_paramf(screen, + PIPE_CAPF_MAX_LINE_WIDTH)); c->MaxLineWidthAA - = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH_AA)); + = _maxf(1.0f, screen->get_paramf(screen, + PIPE_CAPF_MAX_LINE_WIDTH_AA)); c->MaxPointSize - = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH)); + = _maxf(1.0f, screen->get_paramf(screen, + PIPE_CAPF_MAX_POINT_WIDTH)); c->MaxPointSizeAA - = _maxf(1.0f, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH_AA)); + = _maxf(1.0f, screen->get_paramf(screen, + PIPE_CAPF_MAX_POINT_WIDTH_AA)); /* called after _mesa_create_context/_mesa_init_point, fix default user * settable max point size up */ @@ -132,10 +136,11 @@ void st_init_limits(struct st_context *st) c->MinPointSizeAA = 0.0f; c->MaxTextureMaxAnisotropy - = _maxf(2.0f, screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_ANISOTROPY)); + = _maxf(2.0f, screen->get_paramf(screen, + PIPE_CAPF_MAX_TEXTURE_ANISOTROPY)); c->MaxTextureLodBias - = screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_LOD_BIAS); + = screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_LOD_BIAS); c->MaxDrawBuffers = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS), @@ -213,15 +218,10 @@ void st_init_limits(struct st_context *st) c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_MAX_INPUTS) - 2; c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING); - /* XXX we'll need a better query here someday */ - if (screen->get_param(screen, PIPE_CAP_GLSL)) { - c->MinProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MIN_TEXEL_OFFSET); - c->MaxProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MAX_TEXEL_OFFSET); + c->MinProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MIN_TEXEL_OFFSET); + c->MaxProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MAX_TEXEL_OFFSET); - c->GLSLVersion = 120; - _mesa_override_glsl_version(st->ctx); - c->UniformBooleanTrue = ~0; - } + c->UniformBooleanTrue = ~0; c->StripTextureBorder = GL_TRUE; } @@ -249,16 +249,23 @@ void st_init_extensions(struct st_context *st) struct gl_context *ctx = st->ctx; int i; + ctx->Const.GLSLVersion = 120; + _mesa_override_glsl_version(st->ctx); + /* * Extensions that are supported by all Gallium drivers: */ ctx->Extensions.ARB_copy_buffer = GL_TRUE; ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE; + ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE; ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE; ctx->Extensions.ARB_fragment_program = GL_TRUE; + ctx->Extensions.ARB_fragment_shader = GL_TRUE; ctx->Extensions.ARB_half_float_pixel = GL_TRUE; ctx->Extensions.ARB_map_buffer_range = GL_TRUE; ctx->Extensions.ARB_sampler_objects = GL_TRUE; + ctx->Extensions.ARB_shader_objects = GL_TRUE; + ctx->Extensions.ARB_shading_language_100 = GL_TRUE; ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */ ctx->Extensions.ARB_texture_cube_map = GL_TRUE; ctx->Extensions.ARB_texture_env_combine = GL_TRUE; @@ -267,6 +274,7 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.ARB_texture_storage = GL_TRUE; ctx->Extensions.ARB_vertex_array_object = GL_TRUE; ctx->Extensions.ARB_vertex_program = GL_TRUE; + ctx->Extensions.ARB_vertex_shader = GL_TRUE; ctx->Extensions.ARB_window_pos = GL_TRUE; ctx->Extensions.EXT_blend_color = GL_TRUE; @@ -281,6 +289,7 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.EXT_point_parameters = GL_TRUE; ctx->Extensions.EXT_provoking_vertex = GL_TRUE; ctx->Extensions.EXT_secondary_color = GL_TRUE; + ctx->Extensions.EXT_separate_shader_objects = GL_TRUE; ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE; ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE; @@ -317,15 +326,6 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.EXT_texture_swizzle = GL_TRUE; } - if (screen->get_param(screen, PIPE_CAP_GLSL)) { - ctx->Extensions.ARB_fragment_shader = GL_TRUE; - ctx->Extensions.ARB_vertex_shader = GL_TRUE; - ctx->Extensions.ARB_shader_objects = GL_TRUE; - ctx->Extensions.ARB_shading_language_100 = GL_TRUE; - ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE; - ctx->Extensions.EXT_separate_shader_objects = GL_TRUE; - } - if (screen->get_param(screen, PIPE_CAP_BLEND_EQUATION_SEPARATE)) { ctx->Extensions.EXT_blend_equation_separate = GL_TRUE; } diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 929c7af01..74b8fa7c7 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -4803,6 +4803,8 @@ get_mesa_program(struct gl_context *ctx, { glsl_to_tgsi_visitor* v = new glsl_to_tgsi_visitor(); struct gl_program *prog; + struct pipe_screen * screen = st_context(ctx)->pipe->screen; + unsigned pipe_shader_type; GLenum target; const char *target_string; bool progress; @@ -4813,14 +4815,17 @@ get_mesa_program(struct gl_context *ctx, case GL_VERTEX_SHADER: target = GL_VERTEX_PROGRAM_ARB; target_string = "vertex"; + pipe_shader_type = PIPE_SHADER_VERTEX; break; case GL_FRAGMENT_SHADER: target = GL_FRAGMENT_PROGRAM_ARB; target_string = "fragment"; + pipe_shader_type = PIPE_SHADER_FRAGMENT; break; case GL_GEOMETRY_SHADER: target = GL_GEOMETRY_PROGRAM_NV; target_string = "geometry"; + pipe_shader_type = PIPE_SHADER_GEOMETRY; break; default: assert(!"should not be reached"); @@ -4889,10 +4894,13 @@ get_mesa_program(struct gl_context *ctx, } #endif - /* Remove reads to output registers, and to varyings in vertex shaders. */ - v->remove_output_reads(PROGRAM_OUTPUT); - if (target == GL_VERTEX_PROGRAM_ARB) - v->remove_output_reads(PROGRAM_VARYING); + if (!screen->get_shader_param(screen, pipe_shader_type, + PIPE_SHADER_CAP_OUTPUT_READ)) { + /* Remove reads to output registers, and to varyings in vertex shaders. */ + v->remove_output_reads(PROGRAM_OUTPUT); + if (target == GL_VERTEX_PROGRAM_ARB) + v->remove_output_reads(PROGRAM_VARYING); + } /* Perform optimizations on the instructions in the glsl_to_tgsi_visitor. */ v->simplify_cmp(); diff --git a/mesalib/src/mesa/swrast/s_texcombine.c b/mesalib/src/mesa/swrast/s_texcombine.c index a7cbb4424..1fce5c565 100644 --- a/mesalib/src/mesa/swrast/s_texcombine.c +++ b/mesalib/src/mesa/swrast/s_texcombine.c @@ -69,17 +69,18 @@ get_texel_array(SWcontext *swrast, GLuint unit) * * \param ctx rendering context * \param unit the texture combiner unit - * \param n number of fragments to process (span width) * \param primary_rgba incoming fragment color array * \param texelBuffer pointer to texel colors for all texture units * - * \param rgba incoming/result fragment colors + * \param span two fields are used in this function: + * span->end: number of fragments to process + * span->array->rgba: incoming/result fragment colors */ static void -texture_combine( struct gl_context *ctx, GLuint unit, GLuint n, +texture_combine( struct gl_context *ctx, GLuint unit, const float4_array primary_rgba, const GLfloat *texelBuffer, - GLchan (*rgbaChan)[4] ) + SWspan *span ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); const struct gl_texture_unit *textureUnit = &(ctx->Texture.Unit[unit]); @@ -92,6 +93,8 @@ texture_combine( struct gl_context *ctx, GLuint unit, GLuint n, const GLuint numArgsA = combine->_NumArgsA; float4_array ccolor[4], rgba; GLuint i, term; + GLuint n = span->end; + GLchan (*rgbaChan)[4] = span->array->rgba; /* alloc temp pixel buffers */ rgba = (float4_array) malloc(4 * n * sizeof(GLfloat)); @@ -542,6 +545,10 @@ texture_combine( struct gl_context *ctx, GLuint unit, GLuint n, UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][BCOMP], rgba[i][BCOMP]); UNCLAMPED_FLOAT_TO_CHAN(rgbaChan[i][ACOMP], rgba[i][ACOMP]); } + /* The span->array->rgba values are of CHAN type so set + * span->array->ChanType field accordingly. + */ + span->array->ChanType = CHAN_TYPE; end: for (i = 0; i < numArgsRGB || i < numArgsA; i++) { @@ -764,12 +771,8 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) * We modify the span->color.rgba values. */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { - if (ctx->Texture.Unit[unit]._ReallyEnabled) { - texture_combine( ctx, unit, span->end, - primary_rgba, - swrast->TexelBuffer, - span->array->rgba ); - } + if (ctx->Texture.Unit[unit]._ReallyEnabled) + texture_combine(ctx, unit, primary_rgba, swrast->TexelBuffer, span); } free(primary_rgba); diff --git a/mesalib/src/mesa/vbo/vbo_noop.h b/mesalib/src/mesa/vbo/vbo_noop.h index f9180374f..92f61d356 100644 --- a/mesalib/src/mesa/vbo/vbo_noop.h +++ b/mesalib/src/mesa/vbo/vbo_noop.h @@ -38,6 +38,12 @@ _mesa_noop_vtxfmt_init(GLvertexformat *vfmt); extern GLboolean _mesa_using_noop_vtxfmt(const struct _glapi_table *dispatch); +#else + +static inline void +_mesa_noop_vtxfmt_init(GLvertexformat *vfmt) +{ +} #endif /* FEATURE_beginend */ diff --git a/pixman/configure.ac b/pixman/configure.ac index 79cf21154..2eded7056 100644 --- a/pixman/configure.ac +++ b/pixman/configure.ac @@ -150,7 +150,7 @@ AC_CHECK_DECL([__amd64], [AMD64_ABI="yes"], [AMD64_ABI="no"]) # if we're using Sun Studio and neither the user nor a config.site # has set CFLAGS. if test $SUNCC = yes && \ - test "$test_CFLAGS" == "" && \ + test "x$test_CFLAGS" = "x" && \ test "$CFLAGS" = "-g" then CFLAGS="-O -g" diff --git a/xorg-server/Xext/security.c b/xorg-server/Xext/security.c index 08d8158e3..0a63aa280 100644 --- a/xorg-server/Xext/security.c +++ b/xorg-server/Xext/security.c @@ -62,7 +62,7 @@ typedef struct { } SecurityStateRec; /* Extensions that untrusted clients shouldn't have access to */ -static char *SecurityTrustedExtensions[] = { +static const char *SecurityTrustedExtensions[] = { "XC-MISC", "BIG-REQUESTS", "XpExtension", @@ -98,7 +98,7 @@ static const Mask SecurityClientMask = DixGetAttrAccess; */ static void -SecurityAudit(char *format, ...) +SecurityAudit(const char *format, ...) { va_list args; diff --git a/xorg-server/Xext/sync.c b/xorg-server/Xext/sync.c index 3b257f73b..23360f002 100644 --- a/xorg-server/Xext/sync.c +++ b/xorg-server/Xext/sync.c @@ -971,7 +971,7 @@ static int FreeCounter(void *, XID); pointer SyncCreateSystemCounter( - char *name, + const char *name, CARD64 initial, CARD64 resolution, SyncCounterType counterType, @@ -1308,7 +1308,7 @@ ProcSyncListSystemCounters(ClientPtr client) for (i = len = 0; i < SyncNumSystemCounters; i++) { - char *name = SysCounterList[i]->pSysCounterInfo->name; + const char *name = SysCounterList[i]->pSysCounterInfo->name; /* pad to 4 byte boundary */ len += pad_to_int32(sz_xSyncSystemCounter + strlen(name)); } diff --git a/xorg-server/Xext/syncsrv.h b/xorg-server/Xext/syncsrv.h index 6fe9cd123..2b7077364 100644 --- a/xorg-server/Xext/syncsrv.h +++ b/xorg-server/Xext/syncsrv.h @@ -1,146 +1,146 @@ -/*
-
-Copyright 1991, 1993, 1994, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-*/
-
-/***********************************************************
-Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
-and Olivetti Research Limited, Cambridge, England.
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the names of Digital or Olivetti
-not be used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
-******************************************************************/
-
-#ifndef _SYNCSRV_H_
-#define _SYNCSRV_H_
-
-#include "misync.h"
-#include "misyncstr.h"
-
-/*
- * The System Counter interface
- */
-
-typedef enum {
- XSyncCounterNeverChanges,
- XSyncCounterNeverIncreases,
- XSyncCounterNeverDecreases,
- XSyncCounterUnrestricted
-} SyncCounterType;
-
-typedef struct _SysCounterInfo {
- char *name;
- CARD64 resolution;
- CARD64 bracket_greater;
- CARD64 bracket_less;
- SyncCounterType counterType; /* how can this counter change */
- void (*QueryValue)(
- pointer /*pCounter*/,
- CARD64 * /*freshvalue*/
-);
- void (*BracketValues)(
- pointer /*pCounter*/,
- CARD64 * /*lessthan*/,
- CARD64 * /*greaterthan*/
-);
-} SysCounterInfo;
-
-
-
-typedef struct _SyncAlarmClientList {
- ClientPtr client;
- XID delete_id;
- struct _SyncAlarmClientList *next;
-} SyncAlarmClientList;
-
-typedef struct _SyncAlarm {
- SyncTrigger trigger;
- ClientPtr client;
- XSyncAlarm alarm_id;
- CARD64 delta;
- int events;
- int state;
- SyncAlarmClientList *pEventClients;
-} SyncAlarm;
-
-typedef struct {
- ClientPtr client;
- CARD32 delete_id;
- int num_waitconditions;
-} SyncAwaitHeader;
-
-typedef struct {
- SyncTrigger trigger;
- CARD64 event_threshold;
- SyncAwaitHeader *pHeader;
-} SyncAwait;
-
-typedef union {
- SyncAwaitHeader header;
- SyncAwait await;
-} SyncAwaitUnion;
-
-extern pointer SyncCreateSystemCounter(
- char * /* name */,
- CARD64 /* inital_value */,
- CARD64 /* resolution */,
- SyncCounterType /* change characterization */,
- void (* /*QueryValue*/ ) (
- pointer /* pCounter */,
- CARD64 * /* pValue_return */), /* XXX prototype */
- void (* /*BracketValues*/) (
- pointer /* pCounter */,
- CARD64 * /* pbracket_less */,
- CARD64 * /* pbracket_greater */)
-);
-
-extern void SyncChangeCounter(
- SyncCounter * /* pCounter*/,
- CARD64 /* new_value */
-);
-
-extern void SyncDestroySystemCounter(
- pointer pCounter
-);
-
-extern void InitServertime(void);
-
-extern void SyncExtensionInit(void);
-#endif /* _SYNCSRV_H_ */
+/* + +Copyright 1991, 1993, 1994, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ + +/*********************************************************** +Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts, +and Olivetti Research Limited, Cambridge, England. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Digital or Olivetti +not be used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS +SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. + +******************************************************************/ + +#ifndef _SYNCSRV_H_ +#define _SYNCSRV_H_ + +#include "misync.h" +#include "misyncstr.h" + +/* + * The System Counter interface + */ + +typedef enum { + XSyncCounterNeverChanges, + XSyncCounterNeverIncreases, + XSyncCounterNeverDecreases, + XSyncCounterUnrestricted +} SyncCounterType; + +typedef struct _SysCounterInfo { + const char *name; + CARD64 resolution; + CARD64 bracket_greater; + CARD64 bracket_less; + SyncCounterType counterType; /* how can this counter change */ + void (*QueryValue)( + pointer /*pCounter*/, + CARD64 * /*freshvalue*/ +); + void (*BracketValues)( + pointer /*pCounter*/, + CARD64 * /*lessthan*/, + CARD64 * /*greaterthan*/ +); +} SysCounterInfo; + + + +typedef struct _SyncAlarmClientList { + ClientPtr client; + XID delete_id; + struct _SyncAlarmClientList *next; +} SyncAlarmClientList; + +typedef struct _SyncAlarm { + SyncTrigger trigger; + ClientPtr client; + XSyncAlarm alarm_id; + CARD64 delta; + int events; + int state; + SyncAlarmClientList *pEventClients; +} SyncAlarm; + +typedef struct { + ClientPtr client; + CARD32 delete_id; + int num_waitconditions; +} SyncAwaitHeader; + +typedef struct { + SyncTrigger trigger; + CARD64 event_threshold; + SyncAwaitHeader *pHeader; +} SyncAwait; + +typedef union { + SyncAwaitHeader header; + SyncAwait await; +} SyncAwaitUnion; + +extern pointer SyncCreateSystemCounter( + const char */* name */, + CARD64 /* inital_value */, + CARD64 /* resolution */, + SyncCounterType /* change characterization */, + void (* /*QueryValue*/ ) ( + pointer /* pCounter */, + CARD64 * /* pValue_return */), /* XXX prototype */ + void (* /*BracketValues*/) ( + pointer /* pCounter */, + CARD64 * /* pbracket_less */, + CARD64 * /* pbracket_greater */) +); + +extern void SyncChangeCounter( + SyncCounter * /* pCounter*/, + CARD64 /* new_value */ +); + +extern void SyncDestroySystemCounter( + pointer pCounter +); + +extern void InitServertime(void); + +extern void SyncExtensionInit(void); +#endif /* _SYNCSRV_H_ */ diff --git a/xorg-server/Xext/xtest.c b/xorg-server/Xext/xtest.c index 945e202d6..bd8e1d3a7 100644 --- a/xorg-server/Xext/xtest.c +++ b/xorg-server/Xext/xtest.c @@ -603,17 +603,16 @@ DeviceSetXTestProperty(DeviceIntPtr dev, Atom property, * This only creates the pair, Activate/Enable Device * still need to be called. */ -int AllocXTestDevice (ClientPtr client, char* name, +int AllocXTestDevice (ClientPtr client, const char* name, DeviceIntPtr* ptr, DeviceIntPtr* keybd, DeviceIntPtr master_ptr, DeviceIntPtr master_keybd) { int retval; - int len = strlen(name); - char *xtestname = calloc(len + 7, 1 ); + char *xtestname; char dummy = 1; - strncpy( xtestname, name, len); - strncat( xtestname, " XTEST", 6 ); + if (asprintf(&xtestname, "%s XTEST", name) == -1) + return BadAlloc; retval = AllocDevicePair( client, xtestname, ptr, keybd, CorePointerProc, CoreKeyboardProc, FALSE); if ( retval == Success ){ diff --git a/xorg-server/Xext/xvmc.c b/xorg-server/Xext/xvmc.c index bc78b55ae..47b9f476e 100644 --- a/xorg-server/Xext/xvmc.c +++ b/xorg-server/Xext/xvmc.c @@ -777,14 +777,12 @@ xf86XvMCRegisterDRInfo(ScreenPtr pScreen, char *name, int patchLevel) { XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pScreen); - strncpy(pScreenPriv->clientDriverName, name, + strlcpy(pScreenPriv->clientDriverName, name, DR_CLIENT_DRIVER_NAME_SIZE); - strncpy(pScreenPriv->busID, busID, DR_BUSID_SIZE); + strlcpy(pScreenPriv->busID, busID, DR_BUSID_SIZE); pScreenPriv->major = major; pScreenPriv->minor = minor; pScreenPriv->patchLevel = patchLevel; - pScreenPriv->clientDriverName[DR_CLIENT_DRIVER_NAME_SIZE-1] = 0; - pScreenPriv->busID[DR_BUSID_SIZE-1] = 0; return Success; } diff --git a/xorg-server/Xi/extinit.c b/xorg-server/Xi/extinit.c index 7724f5f5a..a2c807b46 100644 --- a/xorg-server/Xi/extinit.c +++ b/xorg-server/Xi/extinit.c @@ -162,7 +162,7 @@ Mask ExtExclusiveMasks[EMASKSIZE]; static struct dev_type { Atom type; - char *name; + const char *name; } dev_type[] = { { 0, XI_KEYBOARD}, { @@ -1127,7 +1127,7 @@ IResetProc(ExtensionEntry * unused) */ void -AssignTypeAndName(DeviceIntPtr dev, Atom type, char *name) +AssignTypeAndName(DeviceIntPtr dev, Atom type, const char *name) { dev->xinput_type = type; dev->name = strdup(name); diff --git a/xorg-server/Xi/xiproperty.c b/xorg-server/Xi/xiproperty.c index 14f1491b6..88de11959 100644 --- a/xorg-server/Xi/xiproperty.c +++ b/xorg-server/Xi/xiproperty.c @@ -48,7 +48,7 @@ static struct dev_properties { Atom type; - char *name; + const char *name; } dev_properties[] = { {0, XI_PROP_ENABLED}, {0, XI_PROP_XTEST_DEVICE}, @@ -386,7 +386,7 @@ change_property(ClientPtr client, DeviceIntPtr dev, Atom property, Atom type, * If name is NULL, None is returned. */ Atom -XIGetKnownProperty(char *name) +XIGetKnownProperty(const char *name) { int i; diff --git a/xorg-server/configure.ac b/xorg-server/configure.ac index e80403075..e4fcba4a5 100644 --- a/xorg-server/configure.ac +++ b/xorg-server/configure.ac @@ -45,7 +45,7 @@ XORG_WITH_XMLTO(0.0.20) XORG_WITH_FOP XORG_WITH_XSLTPROC XORG_ENABLE_UNIT_TESTS -XORG_LD_WRAP +XORG_LD_WRAP([optional]) m4_ifndef([XORG_FONT_MACROS_VERSION], [m4_fatal([must install fontutil 1.1 or later before running autoconf/autogen])]) XORG_FONT_MACROS_VERSION(1.1) @@ -218,6 +218,8 @@ AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr \ strtol getopt getopt_long vsnprintf walkcontext backtrace \ getisax getzoneid shmctl64 strcasestr ffs vasprintf]) AC_FUNC_ALLOCA +AC_CHECK_FUNCS([strndup], [HAVE_STRNDUP=yes], [HAVE_STRNDUP=no]) +AM_CONDITIONAL(NEED_STRNDUP, [test x$HAVE_STRNDUP = xno]) dnl Old HAS_* names used in os/*.c. AC_CHECK_FUNC([getdtablesize], AC_DEFINE(HAS_GETDTABLESIZE, 1, [Have the 'getdtablesize' function.])) diff --git a/xorg-server/dix/atom.c b/xorg-server/dix/atom.c index 210641bd4..83ff71a7d 100644 --- a/xorg-server/dix/atom.c +++ b/xorg-server/dix/atom.c @@ -1,218 +1,215 @@ -/***********************************************************
-
-Copyright 1987, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>
-#include <X11/Xatom.h>
-#include <stdio.h>
-#include <string.h>
-#include "misc.h"
-#include "resource.h"
-#include "dix.h"
-
-#define InitialTableSize 100
-
-typedef struct _Node {
- struct _Node *left, *right;
- Atom a;
- unsigned int fingerPrint;
- const char *string;
-} NodeRec, *NodePtr;
-
-static Atom lastAtom = None;
-static NodePtr atomRoot = NULL;
-static unsigned long tableLength;
-static NodePtr *nodeTable;
-
-void FreeAtom(NodePtr patom);
-
-Atom
-MakeAtom(const char *string, unsigned len, Bool makeit)
-{
- NodePtr * np;
- unsigned i;
- int comp;
- unsigned int fp = 0;
-
- np = &atomRoot;
- for (i = 0; i < (len+1)/2; i++)
- {
- fp = fp * 27 + string[i];
- fp = fp * 27 + string[len - 1 - i];
- }
- while (*np != NULL)
- {
- if (fp < (*np)->fingerPrint)
- np = &((*np)->left);
- else if (fp > (*np)->fingerPrint)
- np = &((*np)->right);
- else
- { /* now start testing the strings */
- comp = strncmp(string, (*np)->string, (int)len);
- if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string))))
- np = &((*np)->left);
- else if (comp > 0)
- np = &((*np)->right);
- else
- return(*np)->a;
- }
- }
- if (makeit)
- {
- NodePtr nd;
-
- nd = malloc(sizeof(NodeRec));
- if (!nd)
- return BAD_RESOURCE;
- if (lastAtom < XA_LAST_PREDEFINED)
- {
- nd->string = string;
- }
- else
- {
- char *newstring = malloc(len + 1);
- if (!newstring) {
- free(nd);
- return BAD_RESOURCE;
- }
- strncpy(newstring, string, (int)len);
- newstring[len] = 0;
- nd->string = newstring;
- }
- if ((lastAtom + 1) >= tableLength) {
- NodePtr *table;
-
- table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr)));
- if (!table) {
- if (nd->string != string) {
- /* nd->string has been strdup'ed */
- free((char *)nd->string);
- }
- free(nd);
- return BAD_RESOURCE;
- }
- tableLength <<= 1;
- nodeTable = table;
- }
- *np = nd;
- nd->left = nd->right = NULL;
- nd->fingerPrint = fp;
- nd->a = ++lastAtom;
- nodeTable[lastAtom] = nd;
- return nd->a;
- }
- else
- return None;
-}
-
-Bool
-ValidAtom(Atom atom)
-{
- return (atom != None) && (atom <= lastAtom);
-}
-
-const char *
-NameForAtom(Atom atom)
-{
- NodePtr node;
- if (atom > lastAtom) return 0;
- if ((node = nodeTable[atom]) == NULL) return 0;
- return node->string;
-}
-
-void
-AtomError(void)
-{
- FatalError("initializing atoms");
-}
-
-void
-FreeAtom(NodePtr patom)
-{
- if(patom->left)
- FreeAtom(patom->left);
- if(patom->right)
- FreeAtom(patom->right);
- if (patom->a > XA_LAST_PREDEFINED) {
- /*
- * All strings above XA_LAST_PREDEFINED are strdup'ed, so it's safe to
- * cast here
- */
- free((char *)patom->string);
- }
- free(patom);
-}
-
-void
-FreeAllAtoms(void)
-{
- if (atomRoot == NULL)
- return;
- FreeAtom(atomRoot);
- atomRoot = NULL;
- free(nodeTable);
- nodeTable = NULL;
- lastAtom = None;
-}
-
-void
-InitAtoms(void)
-{
- FreeAllAtoms();
- tableLength = InitialTableSize;
- nodeTable = malloc(InitialTableSize * sizeof(NodePtr));
- if (!nodeTable)
- AtomError();
- nodeTable[None] = NULL;
- MakePredeclaredAtoms();
- if (lastAtom != XA_LAST_PREDEFINED)
- AtomError();
-}
+/*********************************************************** + +Copyright 1987, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + + +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ + + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <X11/X.h> +#include <X11/Xatom.h> +#include <stdio.h> +#include <string.h> +#include "misc.h" +#include "resource.h" +#include "dix.h" + +#define InitialTableSize 100 + +typedef struct _Node { + struct _Node *left, *right; + Atom a; + unsigned int fingerPrint; + const char *string; +} NodeRec, *NodePtr; + +static Atom lastAtom = None; +static NodePtr atomRoot = NULL; +static unsigned long tableLength; +static NodePtr *nodeTable; + +void FreeAtom(NodePtr patom); + +Atom +MakeAtom(const char *string, unsigned len, Bool makeit) +{ + NodePtr * np; + unsigned i; + int comp; + unsigned int fp = 0; + + np = &atomRoot; + for (i = 0; i < (len+1)/2; i++) + { + fp = fp * 27 + string[i]; + fp = fp * 27 + string[len - 1 - i]; + } + while (*np != NULL) + { + if (fp < (*np)->fingerPrint) + np = &((*np)->left); + else if (fp > (*np)->fingerPrint) + np = &((*np)->right); + else + { /* now start testing the strings */ + comp = strncmp(string, (*np)->string, (int)len); + if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string)))) + np = &((*np)->left); + else if (comp > 0) + np = &((*np)->right); + else + return(*np)->a; + } + } + if (makeit) + { + NodePtr nd; + + nd = malloc(sizeof(NodeRec)); + if (!nd) + return BAD_RESOURCE; + if (lastAtom < XA_LAST_PREDEFINED) + { + nd->string = string; + } + else + { + nd->string = strndup(string, len); + if (!nd->string) { + free(nd); + return BAD_RESOURCE; + } + } + if ((lastAtom + 1) >= tableLength) { + NodePtr *table; + + table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr))); + if (!table) { + if (nd->string != string) { + /* nd->string has been strdup'ed */ + free((char *)nd->string); + } + free(nd); + return BAD_RESOURCE; + } + tableLength <<= 1; + nodeTable = table; + } + *np = nd; + nd->left = nd->right = NULL; + nd->fingerPrint = fp; + nd->a = ++lastAtom; + nodeTable[lastAtom] = nd; + return nd->a; + } + else + return None; +} + +Bool +ValidAtom(Atom atom) +{ + return (atom != None) && (atom <= lastAtom); +} + +const char * +NameForAtom(Atom atom) +{ + NodePtr node; + if (atom > lastAtom) return 0; + if ((node = nodeTable[atom]) == NULL) return 0; + return node->string; +} + +void +AtomError(void) +{ + FatalError("initializing atoms"); +} + +void +FreeAtom(NodePtr patom) +{ + if(patom->left) + FreeAtom(patom->left); + if(patom->right) + FreeAtom(patom->right); + if (patom->a > XA_LAST_PREDEFINED) { + /* + * All strings above XA_LAST_PREDEFINED are strdup'ed, so it's safe to + * cast here + */ + free((char *)patom->string); + } + free(patom); +} + +void +FreeAllAtoms(void) +{ + if (atomRoot == NULL) + return; + FreeAtom(atomRoot); + atomRoot = NULL; + free(nodeTable); + nodeTable = NULL; + lastAtom = None; +} + +void +InitAtoms(void) +{ + FreeAllAtoms(); + tableLength = InitialTableSize; + nodeTable = malloc(InitialTableSize * sizeof(NodePtr)); + if (!nodeTable) + AtomError(); + nodeTable[None] = NULL; + MakePredeclaredAtoms(); + if (lastAtom != XA_LAST_PREDEFINED) + AtomError(); +} diff --git a/xorg-server/dix/devices.c b/xorg-server/dix/devices.c index da817a8af..37cbcdb78 100644 --- a/xorg-server/dix/devices.c +++ b/xorg-server/dix/devices.c @@ -2554,7 +2554,7 @@ GetMaster(DeviceIntPtr dev, int which) * the value for master. */ int -AllocDevicePair (ClientPtr client, char* name, +AllocDevicePair (ClientPtr client, const char* name, DeviceIntPtr* ptr, DeviceIntPtr* keybd, DeviceProc ptr_proc, diff --git a/xorg-server/dix/extension.c b/xorg-server/dix/extension.c index c7bbac5ff..53aaf051f 100644 --- a/xorg-server/dix/extension.c +++ b/xorg-server/dix/extension.c @@ -71,7 +71,7 @@ static int lastError = FirstExtensionError; static unsigned int NumExtensions = 0; ExtensionEntry * -AddExtension(char *name, int NumEvents, int NumErrors, +AddExtension(const char *name, int NumEvents, int NumErrors, int (*MainProc)(ClientPtr c1), int (*SwappedMainProc)(ClientPtr c2), void (*CloseDownProc)(ExtensionEntry *e), @@ -151,7 +151,7 @@ AddExtension(char *name, int NumEvents, int NumErrors, return ext; } -Bool AddExtensionAlias(char *alias, ExtensionEntry *ext) +Bool AddExtensionAlias(const char *alias, ExtensionEntry *ext) { char *name; char **aliases; @@ -172,7 +172,7 @@ Bool AddExtensionAlias(char *alias, ExtensionEntry *ext) } static int -FindExtension(char *extname, int len) +FindExtension(const char *extname, int len) { int i, j; @@ -201,7 +201,7 @@ CheckExtension(const char *extname) { int n; - n = FindExtension((char*)extname, strlen(extname)); + n = FindExtension(extname, strlen(extname)); if (n != -1) return extensions[n]; else diff --git a/xorg-server/doc/Xinput.xml b/xorg-server/doc/Xinput.xml index 0a7ec8dc0..7f576a135 100644 --- a/xorg-server/doc/Xinput.xml +++ b/xorg-server/doc/Xinput.xml @@ -15,7 +15,7 @@ <affiliation><orgname>Hewlett-Packard</orgname></affiliation> </author> </authorgroup> - <releaseinfo>X server version &xserver.version;</releaseinfo> + <releaseinfo>X Server Version &xserver.version;</releaseinfo> <copyright><year>1989</year><year>1990</year><year>1991</year> <holder>Hewlett-Packard Company</holder> </copyright> diff --git a/xorg-server/doc/Xserver-spec.xml b/xorg-server/doc/Xserver-spec.xml index 2bf4fb3b7..2b11828fc 100644 --- a/xorg-server/doc/Xserver-spec.xml +++ b/xorg-server/doc/Xserver-spec.xml @@ -43,7 +43,7 @@ </author> <publisher><publishername>The X.Org Foundation</publishername></publisher> <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo> - <releaseinfo>X server version &xserver.version;</releaseinfo> + <releaseinfo>X Server Version &xserver.version;</releaseinfo> <copyright><year>1994</year><holder>X Consortium, Inc.</holder></copyright> <copyright><year>2004</year><holder>X.org Foundation, Inc.</holder></copyright> <legalnotice> @@ -565,7 +565,7 @@ should be called by InitExtensions. ExtensionEntry *AddExtension(name, NumEvents,NumErrors, MainProc, SwappedMainProc, CloseDownProc, MinorOpcodeProc) - char *name; /*Null terminate string; case matters*/ + const char *name; /*Null terminate string; case matters*/ int NumEvents; int NumErrors; int (* MainProc)(ClientPtr);/*Called if client matches server order*/ diff --git a/xorg-server/doc/dtrace/Xserver-DTrace.xml b/xorg-server/doc/dtrace/Xserver-DTrace.xml index fa8bc809a..5ef062980 100644 --- a/xorg-server/doc/dtrace/Xserver-DTrace.xml +++ b/xorg-server/doc/dtrace/Xserver-DTrace.xml @@ -14,7 +14,7 @@ <orgdiv>Solaris Engineering</orgdiv> </affiliation> </author> - <releaseinfo>X.Org Xserver version &xserver.version;</releaseinfo> + <releaseinfo>X Server Version &xserver.version;</releaseinfo> <copyright><year>2005</year><year>2006</year><year>2007</year><year>2010</year> <holder>Oracle and/or its affiliates. All rights reserved.</holder> </copyright> diff --git a/xorg-server/exa/exa_render.c b/xorg-server/exa/exa_render.c index 026f5d16d..3974afe87 100644 --- a/xorg-server/exa/exa_render.c +++ b/xorg-server/exa/exa_render.c @@ -1,1256 +1,1256 @@ -/*
- * Copyright © 2001 Keith Packard
- *
- * Partly based on code that is Copyright © The XFree86 Project Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. Keith Packard makes no
- * representations about the suitability of this software for any purpose. It
- * is provided "as is" without express or implied warranty.
- *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <stdlib.h>
-
-#include "exa_priv.h"
-
-#include "mipict.h"
-
-#if DEBUG_TRACE_FALL
-static void exaCompositeFallbackPictDesc(PicturePtr pict, char *string, int n)
-{
- char format[20];
- char size[20];
- char loc;
- int temp;
-
- if (!pict) {
- snprintf(string, n, "None");
- return;
- }
-
- switch (pict->format)
- {
- case PICT_a8r8g8b8:
- snprintf(format, 20, "ARGB8888");
- break;
- case PICT_x8r8g8b8:
- snprintf(format, 20, "XRGB8888");
- break;
- case PICT_b8g8r8a8:
- snprintf(format, 20, "BGRA8888");
- break;
- case PICT_b8g8r8x8:
- snprintf(format, 20, "BGRX8888");
- break;
- case PICT_r5g6b5:
- snprintf(format, 20, "RGB565 ");
- break;
- case PICT_x1r5g5b5:
- snprintf(format, 20, "RGB555 ");
- break;
- case PICT_a8:
- snprintf(format, 20, "A8 ");
- break;
- case PICT_a1:
- snprintf(format, 20, "A1 ");
- break;
- default:
- snprintf(format, 20, "0x%x", (int)pict->format);
- break;
- }
-
- if (pict->pDrawable) {
- loc = exaGetOffscreenPixmap(pict->pDrawable, &temp, &temp) ? 's' : 'm';
-
- snprintf(size, 20, "%dx%d%s", pict->pDrawable->width,
- pict->pDrawable->height, pict->repeat ?
- " R" : "");
- } else {
- loc = '-';
-
- snprintf(size, 20, "%s", pict->repeat ? " R" : "");
- }
-
- snprintf(string, n, "%p:%c fmt %s (%s)", pict->pDrawable, loc, format, size);
-}
-
-static void
-exaPrintCompositeFallback(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pMask,
- PicturePtr pDst)
-{
- char sop[20];
- char srcdesc[40], maskdesc[40], dstdesc[40];
-
- switch(op)
- {
- case PictOpSrc:
- sprintf(sop, "Src");
- break;
- case PictOpOver:
- sprintf(sop, "Over");
- break;
- default:
- sprintf(sop, "0x%x", (int)op);
- break;
- }
-
- exaCompositeFallbackPictDesc(pSrc, srcdesc, 40);
- exaCompositeFallbackPictDesc(pMask, maskdesc, 40);
- exaCompositeFallbackPictDesc(pDst, dstdesc, 40);
-
- ErrorF("Composite fallback: op %s, \n"
- " src %s, \n"
- " mask %s, \n"
- " dst %s, \n",
- sop, srcdesc, maskdesc, dstdesc);
-}
-#endif /* DEBUG_TRACE_FALL */
-
-Bool
-exaOpReadsDestination (CARD8 op)
-{
- /* FALSE (does not read destination) is the list of ops in the protocol
- * document with "0" in the "Fb" column and no "Ab" in the "Fa" column.
- * That's just Clear and Src. ReduceCompositeOp() will already have
- * converted con/disjoint clear/src to Clear or Src.
- */
- switch (op) {
- case PictOpClear:
- case PictOpSrc:
- return FALSE;
- default:
- return TRUE;
- }
-}
-
-
-static Bool
-exaGetPixelFromRGBA(CARD32 *pixel,
- CARD16 red,
- CARD16 green,
- CARD16 blue,
- CARD16 alpha,
- PictFormatPtr pFormat)
-{
- int rbits, bbits, gbits, abits;
- int rshift, bshift, gshift, ashift;
-
- *pixel = 0;
-
- if (!PICT_FORMAT_COLOR(pFormat->format) &&
- PICT_FORMAT_TYPE(pFormat->format) != PICT_TYPE_A)
- return FALSE;
-
- rbits = PICT_FORMAT_R(pFormat->format);
- gbits = PICT_FORMAT_G(pFormat->format);
- bbits = PICT_FORMAT_B(pFormat->format);
- abits = PICT_FORMAT_A(pFormat->format);
-
- rshift = pFormat->direct.red;
- gshift = pFormat->direct.green;
- bshift = pFormat->direct.blue;
- ashift = pFormat->direct.alpha;
-
- *pixel |= ( blue >> (16 - bbits)) << bshift;
- *pixel |= ( red >> (16 - rbits)) << rshift;
- *pixel |= (green >> (16 - gbits)) << gshift;
- *pixel |= (alpha >> (16 - abits)) << ashift;
-
- return TRUE;
-}
-
-static Bool
-exaGetRGBAFromPixel(CARD32 pixel,
- CARD16 *red,
- CARD16 *green,
- CARD16 *blue,
- CARD16 *alpha,
- PictFormatPtr pFormat,
- PictFormatShort format)
-{
- int rbits, bbits, gbits, abits;
- int rshift, bshift, gshift, ashift;
-
- if (!PICT_FORMAT_COLOR(format) && PICT_FORMAT_TYPE(format) != PICT_TYPE_A)
- return FALSE;
-
- rbits = PICT_FORMAT_R(format);
- gbits = PICT_FORMAT_G(format);
- bbits = PICT_FORMAT_B(format);
- abits = PICT_FORMAT_A(format);
-
- if (pFormat) {
- rshift = pFormat->direct.red;
- gshift = pFormat->direct.green;
- bshift = pFormat->direct.blue;
- ashift = pFormat->direct.alpha;
- } else if (format == PICT_a8r8g8b8) {
- rshift = 16;
- gshift = 8;
- bshift = 0;
- ashift = 24;
- } else
- FatalError("EXA bug: exaGetRGBAFromPixel() doesn't match "
- "createSourcePicture()\n");
-
- if (rbits) {
- *red = ((pixel >> rshift ) & ((1 << rbits) - 1)) << (16 - rbits);
- while (rbits < 16) {
- *red |= *red >> rbits;
- rbits <<= 1;
- }
-
- *green = ((pixel >> gshift ) & ((1 << gbits) - 1)) << (16 - gbits);
- while (gbits < 16) {
- *green |= *green >> gbits;
- gbits <<= 1;
- }
-
- *blue = ((pixel >> bshift ) & ((1 << bbits) - 1)) << (16 - bbits);
- while (bbits < 16) {
- *blue |= *blue >> bbits;
- bbits <<= 1;
- }
- } else {
- *red = 0x0000;
- *green = 0x0000;
- *blue = 0x0000;
- }
-
- if (abits) {
- *alpha = ((pixel >> ashift ) & ((1 << abits) - 1)) << (16 - abits);
- while (abits < 16) {
- *alpha |= *alpha >> abits;
- abits <<= 1;
- }
- } else
- *alpha = 0xffff;
-
- return TRUE;
-}
-
-static int
-exaTryDriverSolidFill(PicturePtr pSrc,
- PicturePtr pDst,
- INT16 xSrc,
- INT16 ySrc,
- INT16 xDst,
- INT16 yDst,
- CARD16 width,
- CARD16 height)
-{
- ExaScreenPriv (pDst->pDrawable->pScreen);
- RegionRec region;
- BoxPtr pbox;
- int nbox;
- int dst_off_x, dst_off_y;
- PixmapPtr pSrcPix, pDstPix;
- ExaPixmapPrivPtr pDstExaPix;
- CARD32 pixel;
- CARD16 red, green, blue, alpha;
-
- pDstPix = exaGetDrawablePixmap (pDst->pDrawable);
- pDstExaPix = ExaGetPixmapPriv(pDstPix);
-
- /* Check whether the accelerator can use the destination pixmap.
- */
- if (pDstExaPix->accel_blocked)
- {
- return -1;
- }
-
- xDst += pDst->pDrawable->x;
- yDst += pDst->pDrawable->y;
- if (pSrc->pDrawable) {
- xSrc += pSrc->pDrawable->x;
- ySrc += pSrc->pDrawable->y;
- }
-
- if (!miComputeCompositeRegion (®ion, pSrc, NULL, pDst,
- xSrc, ySrc, 0, 0, xDst, yDst,
- width, height))
- return 1;
-
- exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &dst_off_x, &dst_off_y);
-
- RegionTranslate(®ion, dst_off_x, dst_off_y);
-
- if (pSrc->pDrawable) {
- pSrcPix = exaGetDrawablePixmap (pSrc->pDrawable);
- pixel = exaGetPixmapFirstPixel (pSrcPix);
- } else
- pixel = pSrc->pSourcePict->solidFill.color;
-
- if (!exaGetRGBAFromPixel(pixel, &red, &green, &blue, &alpha,
- pSrc->pFormat, pSrc->format) ||
- !exaGetPixelFromRGBA(&pixel, red, green, blue, alpha,
- pDst->pFormat))
- {
- RegionUninit(®ion);
- return -1;
- }
-
- if (pExaScr->do_migration) {
- ExaMigrationRec pixmaps[1];
-
- pixmaps[0].as_dst = TRUE;
- pixmaps[0].as_src = FALSE;
- pixmaps[0].pPix = pDstPix;
- pixmaps[0].pReg = ®ion;
- exaDoMigration(pixmaps, 1, TRUE);
- }
-
- if (!exaPixmapHasGpuCopy(pDstPix)) {
- RegionUninit(®ion);
- return 0;
- }
-
- if (!(*pExaScr->info->PrepareSolid) (pDstPix, GXcopy, 0xffffffff, pixel))
- {
- RegionUninit(®ion);
- return -1;
- }
-
- nbox = RegionNumRects(®ion);
- pbox = RegionRects(®ion);
-
- while (nbox--)
- {
- (*pExaScr->info->Solid) (pDstPix, pbox->x1, pbox->y1, pbox->x2, pbox->y2);
- pbox++;
- }
-
- (*pExaScr->info->DoneSolid) (pDstPix);
- exaMarkSync(pDst->pDrawable->pScreen);
-
- RegionUninit(®ion);
- return 1;
-}
-
-static int
-exaTryDriverCompositeRects(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pMask,
- PicturePtr pDst,
- int nrect,
- ExaCompositeRectPtr rects)
-{
- ExaScreenPriv (pDst->pDrawable->pScreen);
- int src_off_x = 0, src_off_y = 0, mask_off_x = 0, mask_off_y = 0;
- int dst_off_x, dst_off_y;
- PixmapPtr pSrcPix = NULL, pMaskPix = NULL, pDstPix;
- ExaPixmapPrivPtr pSrcExaPix = NULL, pMaskExaPix = NULL, pDstExaPix;
-
- if (!pExaScr->info->PrepareComposite)
- return -1;
-
- if (pSrc->pDrawable) {
- pSrcPix = exaGetDrawablePixmap(pSrc->pDrawable);
- pSrcExaPix = ExaGetPixmapPriv(pSrcPix);
- }
-
- if (pMask && pMask->pDrawable) {
- pMaskPix = exaGetDrawablePixmap(pMask->pDrawable);
- pMaskExaPix = ExaGetPixmapPriv(pMaskPix);
- }
-
- pDstPix = exaGetDrawablePixmap(pDst->pDrawable);
- pDstExaPix = ExaGetPixmapPriv(pDstPix);
-
- /* Check whether the accelerator can use these pixmaps.
- * FIXME: If it cannot, use temporary pixmaps so that the drawing
- * happens within limits.
- */
- if (pDstExaPix->accel_blocked ||
- (pSrcExaPix && pSrcExaPix->accel_blocked) ||
- (pMaskExaPix && pMaskExaPix->accel_blocked))
- {
- return -1;
- }
-
- if (pExaScr->info->CheckComposite &&
- !(*pExaScr->info->CheckComposite) (op, pSrc, pMask, pDst))
- {
- return -1;
- }
-
- if (pExaScr->do_migration) {
- ExaMigrationRec pixmaps[3];
- int i = 0;
-
- pixmaps[i].as_dst = TRUE;
- pixmaps[i].as_src = exaOpReadsDestination(op);
- pixmaps[i].pPix = pDstPix;
- pixmaps[i].pReg = NULL;
- i++;
-
- if (pSrcPix) {
- pixmaps[i].as_dst = FALSE;
- pixmaps[i].as_src = TRUE;
- pixmaps[i].pPix = pSrcPix;
- pixmaps[i].pReg = NULL;
- i++;
- }
-
- if (pMaskPix) {
- pixmaps[i].as_dst = FALSE;
- pixmaps[i].as_src = TRUE;
- pixmaps[i].pPix = pMaskPix;
- pixmaps[i].pReg = NULL;
- i++;
- }
-
- exaDoMigration(pixmaps, i, TRUE);
- }
-
- pDstPix = exaGetOffscreenPixmap (pDst->pDrawable, &dst_off_x, &dst_off_y);
- if (!pDstPix)
- return 0;
-
- if (pSrcPix) {
- pSrcPix = exaGetOffscreenPixmap (pSrc->pDrawable, &src_off_x, &src_off_y);
- if (!pSrcPix)
- return 0;
- }
-
- if (pMaskPix) {
- pMaskPix = exaGetOffscreenPixmap (pMask->pDrawable, &mask_off_x, &mask_off_y);
- if (!pMaskPix)
- return 0;
- }
-
- if (!(*pExaScr->info->PrepareComposite) (op, pSrc, pMask, pDst, pSrcPix,
- pMaskPix, pDstPix))
- return -1;
-
- while (nrect--)
- {
- INT16 xDst = rects->xDst + pDst->pDrawable->x;
- INT16 yDst = rects->yDst + pDst->pDrawable->y;
- INT16 xMask = rects->xMask;
- INT16 yMask = rects->yMask;
- INT16 xSrc = rects->xSrc;
- INT16 ySrc = rects->ySrc;
- RegionRec region;
- BoxPtr pbox;
- int nbox;
-
- if (pMaskPix) {
- xMask += pMask->pDrawable->x;
- yMask += pMask->pDrawable->y;
- }
-
- if (pSrcPix) {
- xSrc += pSrc->pDrawable->x;
- ySrc += pSrc->pDrawable->y;
- }
-
- if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst,
- xSrc, ySrc, xMask, yMask, xDst, yDst,
- rects->width, rects->height))
- goto next_rect;
-
- RegionTranslate(®ion, dst_off_x, dst_off_y);
-
- nbox = RegionNumRects(®ion);
- pbox = RegionRects(®ion);
-
- xMask = xMask + mask_off_x - xDst - dst_off_x;
- yMask = yMask + mask_off_y - yDst - dst_off_y;
- xSrc = xSrc + src_off_x - xDst - dst_off_x;
- ySrc = ySrc + src_off_y - yDst - dst_off_y;
-
- while (nbox--)
- {
- (*pExaScr->info->Composite) (pDstPix,
- pbox->x1 + xSrc,
- pbox->y1 + ySrc,
- pbox->x1 + xMask,
- pbox->y1 + yMask,
- pbox->x1,
- pbox->y1,
- pbox->x2 - pbox->x1,
- pbox->y2 - pbox->y1);
- pbox++;
- }
-
- next_rect:
- RegionUninit(®ion);
-
- rects++;
- }
-
- (*pExaScr->info->DoneComposite) (pDstPix);
- exaMarkSync(pDst->pDrawable->pScreen);
-
- return 1;
-}
-
-/**
- * Copy a number of rectangles from source to destination in a single
- * operation. This is specialized for glyph rendering: we don't have the
- * special-case fallbacks found in exaComposite() - if the driver can support
- * it, we use the driver functionality, otherwise we fall back straight to
- * software.
- */
-void
-exaCompositeRects(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pMask,
- PicturePtr pDst,
- int nrect,
- ExaCompositeRectPtr rects)
-{
- ExaScreenPriv (pDst->pDrawable->pScreen);
- int n;
- ExaCompositeRectPtr r;
- int ret;
-
- /* If we get a mask, that means we're rendering to the exaGlyphs
- * destination directly, so the damage layer takes care of this.
- */
- if (!pMask) {
- RegionRec region;
- int x1 = MAXSHORT;
- int y1 = MAXSHORT;
- int x2 = MINSHORT;
- int y2 = MINSHORT;
- BoxRec box;
-
- /* We have to manage the damage ourselves, since CompositeRects isn't
- * something in the screen that can be managed by the damage extension,
- * and EXA depends on damage to track what needs to be migrated between
- * the gpu and the cpu.
- */
-
- /* Compute the overall extents of the composited region - we're making
- * the assumption here that we are compositing a bunch of glyphs that
- * cluster closely together and damaging each glyph individually would
- * be a loss compared to damaging the bounding box.
- */
- n = nrect;
- r = rects;
- while (n--) {
- int rect_x2 = r->xDst + r->width;
- int rect_y2 = r->yDst + r->height;
-
- if (r->xDst < x1) x1 = r->xDst;
- if (r->yDst < y1) y1 = r->yDst;
- if (rect_x2 > x2) x2 = rect_x2;
- if (rect_y2 > y2) y2 = rect_y2;
-
- r++;
- }
-
- if (x2 <= x1 || y2 <= y1)
- return;
-
- box.x1 = x1;
- box.x2 = x2 < MAXSHORT ? x2 : MAXSHORT;
- box.y1 = y1;
- box.y2 = y2 < MAXSHORT ? y2 : MAXSHORT;
-
- /* The pixmap migration code relies on pendingDamage indicating
- * the bounds of the current rendering, so we need to force
- * the actual damage into that region before we do anything, and
- * (see use of DamagePendingRegion in exaCopyDirty)
- */
-
- RegionInit(®ion, &box, 1);
-
- DamageRegionAppend(pDst->pDrawable, ®ion);
-
- RegionUninit(®ion);
- }
-
- /************************************************************/
-
- ValidatePicture (pSrc);
- if (pMask)
- ValidatePicture (pMask);
- ValidatePicture (pDst);
-
- ret = exaTryDriverCompositeRects(op, pSrc, pMask, pDst, nrect, rects);
-
- if (ret != 1) {
- if (ret == -1 && op == PictOpOver && pMask && pMask->componentAlpha &&
- (!pExaScr->info->CheckComposite ||
- ((*pExaScr->info->CheckComposite)(PictOpOutReverse, pSrc, pMask,
- pDst) &&
- (*pExaScr->info->CheckComposite)(PictOpAdd, pSrc, pMask, pDst)))) {
- ret = exaTryDriverCompositeRects(PictOpOutReverse, pSrc, pMask,
- pDst, nrect, rects);
- if (ret == 1) {
- op = PictOpAdd;
- ret = exaTryDriverCompositeRects(op, pSrc, pMask, pDst, nrect,
- rects);
- }
- }
-
- if (ret != 1) {
- n = nrect;
- r = rects;
- while (n--) {
- ExaCheckComposite (op, pSrc, pMask, pDst,
- r->xSrc, r->ySrc,
- r->xMask, r->yMask,
- r->xDst, r->yDst,
- r->width, r->height);
- r++;
- }
- }
- }
-
- /************************************************************/
-
- if (!pMask) {
- /* Now we have to flush the damage out from pendingDamage => damage
- * Calling DamageRegionProcessPending has that effect.
- */
-
- DamageRegionProcessPending(pDst->pDrawable);
- }
-}
-
-static int
-exaTryDriverComposite(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pMask,
- PicturePtr pDst,
- INT16 xSrc,
- INT16 ySrc,
- INT16 xMask,
- INT16 yMask,
- INT16 xDst,
- INT16 yDst,
- CARD16 width,
- CARD16 height)
-{
- ExaScreenPriv (pDst->pDrawable->pScreen);
- RegionRec region;
- BoxPtr pbox;
- int nbox;
- int src_off_x, src_off_y, mask_off_x, mask_off_y, dst_off_x, dst_off_y;
- PixmapPtr pSrcPix = NULL, pMaskPix = NULL, pDstPix;
- ExaPixmapPrivPtr pSrcExaPix = NULL, pMaskExaPix = NULL, pDstExaPix;
-
- if (pSrc->pDrawable) {
- pSrcPix = exaGetDrawablePixmap(pSrc->pDrawable);
- pSrcExaPix = ExaGetPixmapPriv(pSrcPix);
- }
-
- pDstPix = exaGetDrawablePixmap(pDst->pDrawable);
- pDstExaPix = ExaGetPixmapPriv(pDstPix);
-
- if (pMask && pMask->pDrawable) {
- pMaskPix = exaGetDrawablePixmap(pMask->pDrawable);
- pMaskExaPix = ExaGetPixmapPriv(pMaskPix);
- }
-
- /* Check whether the accelerator can use these pixmaps.
- * FIXME: If it cannot, use temporary pixmaps so that the drawing
- * happens within limits.
- */
- if (pDstExaPix->accel_blocked ||
- (pSrcExaPix && pSrcExaPix->accel_blocked) ||
- (pMaskExaPix && (pMaskExaPix->accel_blocked)))
- {
- return -1;
- }
-
- xDst += pDst->pDrawable->x;
- yDst += pDst->pDrawable->y;
-
- if (pMaskPix) {
- xMask += pMask->pDrawable->x;
- yMask += pMask->pDrawable->y;
- }
-
- if (pSrcPix) {
- xSrc += pSrc->pDrawable->x;
- ySrc += pSrc->pDrawable->y;
- }
-
- if (pExaScr->info->CheckComposite &&
- !(*pExaScr->info->CheckComposite) (op, pSrc, pMask, pDst))
- {
- return -1;
- }
-
- if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst,
- xSrc, ySrc, xMask, yMask, xDst, yDst,
- width, height))
- return 1;
-
- exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &dst_off_x, &dst_off_y);
-
- RegionTranslate(®ion, dst_off_x, dst_off_y);
-
- if (pExaScr->do_migration) {
- ExaMigrationRec pixmaps[3];
- int i = 0;
-
- pixmaps[i].as_dst = TRUE;
- pixmaps[i].as_src = exaOpReadsDestination(op);
- pixmaps[i].pPix = pDstPix;
- pixmaps[i].pReg = pixmaps[0].as_src ? NULL : ®ion;
- i++;
-
- if (pSrcPix) {
- pixmaps[i].as_dst = FALSE;
- pixmaps[i].as_src = TRUE;
- pixmaps[i].pPix = pSrcPix;
- pixmaps[i].pReg = NULL;
- i++;
- }
-
- if (pMaskPix) {
- pixmaps[i].as_dst = FALSE;
- pixmaps[i].as_src = TRUE;
- pixmaps[i].pPix = pMaskPix;
- pixmaps[i].pReg = NULL;
- i++;
- }
-
- exaDoMigration(pixmaps, i, TRUE);
- }
-
- if (pSrcPix) {
- pSrcPix = exaGetOffscreenPixmap (pSrc->pDrawable, &src_off_x, &src_off_y);
- if (!pSrcPix) {
- RegionUninit(®ion);
- return 0;
- }
- }
-
- if (pMaskPix) {
- pMaskPix = exaGetOffscreenPixmap (pMask->pDrawable, &mask_off_x,
- &mask_off_y);
- if (!pMaskPix) {
- RegionUninit(®ion);
- return 0;
- }
- }
-
- if (!exaPixmapHasGpuCopy(pDstPix)) {
- RegionUninit(®ion);
- return 0;
- }
-
- if (!(*pExaScr->info->PrepareComposite) (op, pSrc, pMask, pDst, pSrcPix,
- pMaskPix, pDstPix))
- {
- RegionUninit(®ion);
- return -1;
- }
-
- nbox = RegionNumRects(®ion);
- pbox = RegionRects(®ion);
-
- xMask = xMask + mask_off_x - xDst - dst_off_x;
- yMask = yMask + mask_off_y - yDst - dst_off_y;
-
- xSrc = xSrc + src_off_x - xDst - dst_off_x;
- ySrc = ySrc + src_off_y - yDst - dst_off_y;
-
- while (nbox--)
- {
- (*pExaScr->info->Composite) (pDstPix,
- pbox->x1 + xSrc,
- pbox->y1 + ySrc,
- pbox->x1 + xMask,
- pbox->y1 + yMask,
- pbox->x1,
- pbox->y1,
- pbox->x2 - pbox->x1,
- pbox->y2 - pbox->y1);
- pbox++;
- }
- (*pExaScr->info->DoneComposite) (pDstPix);
- exaMarkSync(pDst->pDrawable->pScreen);
-
- RegionUninit(®ion);
- return 1;
-}
-
-/**
- * exaTryMagicTwoPassCompositeHelper implements PictOpOver using two passes of
- * simpler operations PictOpOutReverse and PictOpAdd. Mainly used for component
- * alpha and limited 1-tmu cards.
- *
- * From http://anholt.livejournal.com/32058.html:
- *
- * The trouble is that component-alpha rendering requires two different sources
- * for blending: one for the source value to the blender, which is the
- * per-channel multiplication of source and mask, and one for the source alpha
- * for multiplying with the destination channels, which is the multiplication
- * of the source channels by the mask alpha. So the equation for Over is:
- *
- * dst.A = src.A * mask.A + (1 - (src.A * mask.A)) * dst.A
- * dst.R = src.R * mask.R + (1 - (src.A * mask.R)) * dst.R
- * dst.G = src.G * mask.G + (1 - (src.A * mask.G)) * dst.G
- * dst.B = src.B * mask.B + (1 - (src.A * mask.B)) * dst.B
- *
- * But we can do some simpler operations, right? How about PictOpOutReverse,
- * which has a source factor of 0 and dest factor of (1 - source alpha). We
- * can get the source alpha value (srca.X = src.A * mask.X) out of the texture
- * blenders pretty easily. So we can do a component-alpha OutReverse, which
- * gets us:
- *
- * dst.A = 0 + (1 - (src.A * mask.A)) * dst.A
- * dst.R = 0 + (1 - (src.A * mask.R)) * dst.R
- * dst.G = 0 + (1 - (src.A * mask.G)) * dst.G
- * dst.B = 0 + (1 - (src.A * mask.B)) * dst.B
- *
- * OK. And if an op doesn't use the source alpha value for the destination
- * factor, then we can do the channel multiplication in the texture blenders
- * to get the source value, and ignore the source alpha that we wouldn't use.
- * We've supported this in the Radeon driver for a long time. An example would
- * be PictOpAdd, which does:
- *
- * dst.A = src.A * mask.A + dst.A
- * dst.R = src.R * mask.R + dst.R
- * dst.G = src.G * mask.G + dst.G
- * dst.B = src.B * mask.B + dst.B
- *
- * Hey, this looks good! If we do a PictOpOutReverse and then a PictOpAdd right
- * after it, we get:
- *
- * dst.A = src.A * mask.A + ((1 - (src.A * mask.A)) * dst.A)
- * dst.R = src.R * mask.R + ((1 - (src.A * mask.R)) * dst.R)
- * dst.G = src.G * mask.G + ((1 - (src.A * mask.G)) * dst.G)
- * dst.B = src.B * mask.B + ((1 - (src.A * mask.B)) * dst.B)
- */
-
-static int
-exaTryMagicTwoPassCompositeHelper(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pMask,
- PicturePtr pDst,
- INT16 xSrc,
- INT16 ySrc,
- INT16 xMask,
- INT16 yMask,
- INT16 xDst,
- INT16 yDst,
- CARD16 width,
- CARD16 height)
-{
- ExaScreenPriv (pDst->pDrawable->pScreen);
-
- assert(op == PictOpOver);
-
- if (pExaScr->info->CheckComposite &&
- (!(*pExaScr->info->CheckComposite)(PictOpOutReverse, pSrc, pMask,
- pDst) ||
- !(*pExaScr->info->CheckComposite)(PictOpAdd, pSrc, pMask, pDst)))
- {
- return -1;
- }
-
- /* Now, we think we should be able to accelerate this operation. First,
- * composite the destination to be the destination times the source alpha
- * factors.
- */
- exaComposite(PictOpOutReverse, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask,
- xDst, yDst, width, height);
-
- /* Then, add in the source value times the destination alpha factors (1.0).
- */
- exaComposite(PictOpAdd, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask,
- xDst, yDst, width, height);
-
- return 1;
-}
-
-void
-exaComposite(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pMask,
- PicturePtr pDst,
- INT16 xSrc,
- INT16 ySrc,
- INT16 xMask,
- INT16 yMask,
- INT16 xDst,
- INT16 yDst,
- CARD16 width,
- CARD16 height)
-{
- ExaScreenPriv (pDst->pDrawable->pScreen);
- int ret = -1;
- Bool saveSrcRepeat = pSrc->repeat;
- Bool saveMaskRepeat = pMask ? pMask->repeat : 0;
- RegionRec region;
-
- if (pExaScr->swappedOut)
- goto fallback;
-
- /* Remove repeat in source if useless */
- if (pSrc->pDrawable && pSrc->repeat && !pSrc->transform && xSrc >= 0 &&
- (xSrc + width) <= pSrc->pDrawable->width && ySrc >= 0 &&
- (ySrc + height) <= pSrc->pDrawable->height)
- pSrc->repeat = 0;
-
- if (!pMask && !pSrc->alphaMap && !pDst->alphaMap &&
- (op == PictOpSrc || (op == PictOpOver && !PICT_FORMAT_A(pSrc->format))))
- {
- if (pSrc->pDrawable ?
- (pSrc->pDrawable->width == 1 && pSrc->pDrawable->height == 1 &&
- pSrc->repeat) :
- (pSrc->pSourcePict->type == SourcePictTypeSolidFill))
- {
- ret = exaTryDriverSolidFill(pSrc, pDst, xSrc, ySrc, xDst, yDst,
- width, height);
- if (ret == 1)
- goto done;
- } else if (pSrc->pDrawable && !pSrc->transform &&
- ((op == PictOpSrc &&
- (pSrc->format == pDst->format ||
- (PICT_FORMAT_COLOR(pDst->format) &&
- PICT_FORMAT_COLOR(pSrc->format) &&
- pDst->format == PICT_FORMAT(PICT_FORMAT_BPP(pSrc->format),
- PICT_FORMAT_TYPE(pSrc->format),
- 0,
- PICT_FORMAT_R(pSrc->format),
- PICT_FORMAT_G(pSrc->format),
- PICT_FORMAT_B(pSrc->format))))) ||
- (op == PictOpOver && pSrc->format == pDst->format &&
- !PICT_FORMAT_A(pSrc->format))))
- {
- if (!pSrc->repeat && xSrc >= 0 && ySrc >= 0 &&
- (xSrc + width <= pSrc->pDrawable->width) &&
- (ySrc + height <= pSrc->pDrawable->height))
- {
- Bool ret;
- xDst += pDst->pDrawable->x;
- yDst += pDst->pDrawable->y;
- xSrc += pSrc->pDrawable->x;
- ySrc += pSrc->pDrawable->y;
-
- if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst,
- xSrc, ySrc, xMask, yMask, xDst,
- yDst, width, height))
- goto done;
-
- ret = exaHWCopyNtoN(pSrc->pDrawable, pDst->pDrawable, NULL,
- RegionRects(®ion), RegionNumRects(®ion),
- xSrc - xDst, ySrc - yDst, FALSE, FALSE);
- RegionUninit(®ion);
-
- /* Reset values to their original values. */
- xDst -= pDst->pDrawable->x;
- yDst -= pDst->pDrawable->y;
- xSrc -= pSrc->pDrawable->x;
- ySrc -= pSrc->pDrawable->y;
-
- if (!ret)
- goto fallback;
-
- goto done;
- }
-
- if (pSrc->repeat && pSrc->repeatType == RepeatNormal &&
- pSrc->pDrawable->type == DRAWABLE_PIXMAP)
- {
- DDXPointRec patOrg;
-
- /* Let's see if the driver can do the repeat in one go */
- if (pExaScr->info->PrepareComposite && !pSrc->alphaMap &&
- !pDst->alphaMap)
- {
- ret = exaTryDriverComposite(op, pSrc, pMask, pDst, xSrc,
- ySrc, xMask, yMask, xDst, yDst,
- width, height);
- if (ret == 1)
- goto done;
- }
-
- /* Now see if we can use exaFillRegionTiled() */
- xDst += pDst->pDrawable->x;
- yDst += pDst->pDrawable->y;
- xSrc += pSrc->pDrawable->x;
- ySrc += pSrc->pDrawable->y;
-
- if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst, xSrc,
- ySrc, xMask, yMask, xDst, yDst,
- width, height))
- goto done;
-
- /* pattern origin is the point in the destination drawable
- * corresponding to (0,0) in the source */
- patOrg.x = xDst - xSrc;
- patOrg.y = yDst - ySrc;
-
- ret = exaFillRegionTiled(pDst->pDrawable, ®ion,
- (PixmapPtr)pSrc->pDrawable,
- &patOrg, FB_ALLONES, GXcopy, CT_NONE);
-
- RegionUninit(®ion);
-
- if (ret)
- goto done;
-
- /* Let's be correct and restore the variables to their original state. */
- xDst -= pDst->pDrawable->x;
- yDst -= pDst->pDrawable->y;
- xSrc -= pSrc->pDrawable->x;
- ySrc -= pSrc->pDrawable->y;
- }
- }
- }
-
- /* Remove repeat in mask if useless */
- if (pMask && pMask->pDrawable && pMask->repeat && !pMask->transform &&
- xMask >= 0 && (xMask + width) <= pMask->pDrawable->width &&
- yMask >= 0 && (yMask + height) <= pMask->pDrawable->height)
- pMask->repeat = 0;
-
- if (pExaScr->info->PrepareComposite &&
- !pSrc->alphaMap && (!pMask || !pMask->alphaMap) && !pDst->alphaMap)
- {
- Bool isSrcSolid;
-
- ret = exaTryDriverComposite(op, pSrc, pMask, pDst, xSrc, ySrc, xMask,
- yMask, xDst, yDst, width, height);
- if (ret == 1)
- goto done;
-
- /* For generic masks and solid src pictures, mach64 can do Over in two
- * passes, similar to the component-alpha case.
- */
- isSrcSolid = pSrc->pDrawable ?
- (pSrc->pDrawable->width == 1 && pSrc->pDrawable->height == 1 &&
- pSrc->repeat) :
- (pSrc->pSourcePict->type == SourcePictTypeSolidFill);
-
- /* If we couldn't do the Composite in a single pass, and it was a
- * component-alpha Over, see if we can do it in two passes with
- * an OutReverse and then an Add.
- */
- if (ret == -1 && op == PictOpOver && pMask &&
- (pMask->componentAlpha || isSrcSolid)) {
- ret = exaTryMagicTwoPassCompositeHelper(op, pSrc, pMask, pDst,
- xSrc, ySrc,
- xMask, yMask, xDst, yDst,
- width, height);
- if (ret == 1)
- goto done;
- }
- }
-
-fallback:
-#if DEBUG_TRACE_FALL
- exaPrintCompositeFallback (op, pSrc, pMask, pDst);
-#endif
-
- ExaCheckComposite (op, pSrc, pMask, pDst, xSrc, ySrc,
- xMask, yMask, xDst, yDst, width, height);
-
-done:
- pSrc->repeat = saveSrcRepeat;
- if (pMask)
- pMask->repeat = saveMaskRepeat;
-}
-
-/**
- * Same as miCreateAlphaPicture, except it uses ExaCheckPolyFillRect instead
- * of PolyFillRect to initialize the pixmap after creating it, to prevent
- * the pixmap from being migrated.
- *
- * See the comments about exaTrapezoids and exaTriangles.
- */
-static PicturePtr
-exaCreateAlphaPicture (ScreenPtr pScreen,
- PicturePtr pDst,
- PictFormatPtr pPictFormat,
- CARD16 width,
- CARD16 height)
-{
- PixmapPtr pPixmap;
- PicturePtr pPicture;
- GCPtr pGC;
- int error;
- xRectangle rect;
-
- if (width > 32767 || height > 32767)
- return 0;
-
- if (!pPictFormat)
- {
- if (pDst->polyEdge == PolyEdgeSharp)
- pPictFormat = PictureMatchFormat (pScreen, 1, PICT_a1);
- else
- pPictFormat = PictureMatchFormat (pScreen, 8, PICT_a8);
- if (!pPictFormat)
- return 0;
- }
-
- pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height,
- pPictFormat->depth, 0);
- if (!pPixmap)
- return 0;
- pGC = GetScratchGC (pPixmap->drawable.depth, pScreen);
- if (!pGC)
- {
- (*pScreen->DestroyPixmap) (pPixmap);
- return 0;
- }
- ValidateGC (&pPixmap->drawable, pGC);
- rect.x = 0;
- rect.y = 0;
- rect.width = width;
- rect.height = height;
- ExaCheckPolyFillRect (&pPixmap->drawable, pGC, 1, &rect);
- exaPixmapDirty (pPixmap, 0, 0, width, height);
- FreeScratchGC (pGC);
- pPicture = CreatePicture (0, &pPixmap->drawable, pPictFormat,
- 0, 0, serverClient, &error);
- (*pScreen->DestroyPixmap) (pPixmap);
- return pPicture;
-}
-
-/**
- * exaTrapezoids is essentially a copy of miTrapezoids that uses
- * exaCreateAlphaPicture instead of miCreateAlphaPicture.
- *
- * The problem with miCreateAlphaPicture is that it calls PolyFillRect
- * to initialize the contents after creating the pixmap, which
- * causes the pixmap to be moved in for acceleration. The subsequent
- * call to RasterizeTrapezoid won't be accelerated however, which
- * forces the pixmap to be moved out again.
- *
- * exaCreateAlphaPicture avoids this roundtrip by using ExaCheckPolyFillRect
- * to initialize the contents.
- */
-void
-exaTrapezoids (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
- PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
- int ntrap, xTrapezoid *traps)
-{
- ScreenPtr pScreen = pDst->pDrawable->pScreen;
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- BoxRec bounds;
-
- if (maskFormat) {
- PicturePtr pPicture;
- INT16 xDst, yDst;
- INT16 xRel, yRel;
-
- miTrapezoidBounds (ntrap, traps, &bounds);
-
- if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
- return;
-
- xDst = traps[0].left.p1.x >> 16;
- yDst = traps[0].left.p1.y >> 16;
-
- pPicture = exaCreateAlphaPicture (pScreen, pDst, maskFormat,
- bounds.x2 - bounds.x1,
- bounds.y2 - bounds.y1);
- if (!pPicture)
- return;
-
- exaPrepareAccess(pPicture->pDrawable, EXA_PREPARE_DEST);
- for (; ntrap; ntrap--, traps++)
- (*ps->RasterizeTrapezoid) (pPicture, traps,
- -bounds.x1, -bounds.y1);
- exaFinishAccess(pPicture->pDrawable, EXA_PREPARE_DEST);
-
- xRel = bounds.x1 + xSrc - xDst;
- yRel = bounds.y1 + ySrc - yDst;
- CompositePicture (op, pSrc, pPicture, pDst,
- xRel, yRel, 0, 0, bounds.x1, bounds.y1,
- bounds.x2 - bounds.x1,
- bounds.y2 - bounds.y1);
- FreePicture (pPicture, 0);
- } else {
- if (pDst->polyEdge == PolyEdgeSharp)
- maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1);
- else
- maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8);
- for (; ntrap; ntrap--, traps++)
- exaTrapezoids (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, traps);
- }
-}
-
-/**
- * exaTriangles is essentially a copy of miTriangles that uses
- * exaCreateAlphaPicture instead of miCreateAlphaPicture.
- *
- * The problem with miCreateAlphaPicture is that it calls PolyFillRect
- * to initialize the contents after creating the pixmap, which
- * causes the pixmap to be moved in for acceleration. The subsequent
- * call to AddTriangles won't be accelerated however, which forces the pixmap
- * to be moved out again.
- *
- * exaCreateAlphaPicture avoids this roundtrip by using ExaCheckPolyFillRect
- * to initialize the contents.
- */
-void
-exaTriangles (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
- PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
- int ntri, xTriangle *tris)
-{
- ScreenPtr pScreen = pDst->pDrawable->pScreen;
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- BoxRec bounds;
-
- if (maskFormat) {
- PicturePtr pPicture;
- INT16 xDst, yDst;
- INT16 xRel, yRel;
-
- miTriangleBounds (ntri, tris, &bounds);
-
- if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
- return;
-
- xDst = tris[0].p1.x >> 16;
- yDst = tris[0].p1.y >> 16;
-
- pPicture = exaCreateAlphaPicture (pScreen, pDst, maskFormat,
- bounds.x2 - bounds.x1,
- bounds.y2 - bounds.y1);
- if (!pPicture)
- return;
-
- exaPrepareAccess(pPicture->pDrawable, EXA_PREPARE_DEST);
- (*ps->AddTriangles) (pPicture, -bounds.x1, -bounds.y1, ntri, tris);
- exaFinishAccess(pPicture->pDrawable, EXA_PREPARE_DEST);
-
- xRel = bounds.x1 + xSrc - xDst;
- yRel = bounds.y1 + ySrc - yDst;
- CompositePicture (op, pSrc, pPicture, pDst,
- xRel, yRel, 0, 0, bounds.x1, bounds.y1,
- bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
- FreePicture (pPicture, 0);
- } else {
- if (pDst->polyEdge == PolyEdgeSharp)
- maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1);
- else
- maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8);
-
- for (; ntri; ntri--, tris++)
- exaTriangles (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, tris);
- }
-}
+/* + * Copyright © 2001 Keith Packard + * + * Partly based on code that is Copyright © The XFree86 Project Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <stdlib.h> + +#include "exa_priv.h" + +#include "mipict.h" + +#if DEBUG_TRACE_FALL +static void exaCompositeFallbackPictDesc(PicturePtr pict, char *string, int n) +{ + char format[20]; + char size[20]; + char loc; + int temp; + + if (!pict) { + snprintf(string, n, "None"); + return; + } + + switch (pict->format) + { + case PICT_a8r8g8b8: + snprintf(format, 20, "ARGB8888"); + break; + case PICT_x8r8g8b8: + snprintf(format, 20, "XRGB8888"); + break; + case PICT_b8g8r8a8: + snprintf(format, 20, "BGRA8888"); + break; + case PICT_b8g8r8x8: + snprintf(format, 20, "BGRX8888"); + break; + case PICT_r5g6b5: + snprintf(format, 20, "RGB565 "); + break; + case PICT_x1r5g5b5: + snprintf(format, 20, "RGB555 "); + break; + case PICT_a8: + snprintf(format, 20, "A8 "); + break; + case PICT_a1: + snprintf(format, 20, "A1 "); + break; + default: + snprintf(format, 20, "0x%x", (int)pict->format); + break; + } + + if (pict->pDrawable) { + loc = exaGetOffscreenPixmap(pict->pDrawable, &temp, &temp) ? 's' : 'm'; + + snprintf(size, 20, "%dx%d%s", pict->pDrawable->width, + pict->pDrawable->height, pict->repeat ? + " R" : ""); + } else { + loc = '-'; + + snprintf(size, 20, "%s", pict->repeat ? " R" : ""); + } + + snprintf(string, n, "%p:%c fmt %s (%s)", pict->pDrawable, loc, format, size); +} + +static void +exaPrintCompositeFallback(CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst) +{ + char sop[20]; + char srcdesc[40], maskdesc[40], dstdesc[40]; + + switch(op) + { + case PictOpSrc: + snprintf(sop, sizeof(sop), "Src"); + break; + case PictOpOver: + snprintf(sop, sizeof(sop), "Over"); + break; + default: + snprintf(sop, sizeof(sop), "0x%x", (int)op); + break; + } + + exaCompositeFallbackPictDesc(pSrc, srcdesc, 40); + exaCompositeFallbackPictDesc(pMask, maskdesc, 40); + exaCompositeFallbackPictDesc(pDst, dstdesc, 40); + + ErrorF("Composite fallback: op %s, \n" + " src %s, \n" + " mask %s, \n" + " dst %s, \n", + sop, srcdesc, maskdesc, dstdesc); +} +#endif /* DEBUG_TRACE_FALL */ + +Bool +exaOpReadsDestination (CARD8 op) +{ + /* FALSE (does not read destination) is the list of ops in the protocol + * document with "0" in the "Fb" column and no "Ab" in the "Fa" column. + * That's just Clear and Src. ReduceCompositeOp() will already have + * converted con/disjoint clear/src to Clear or Src. + */ + switch (op) { + case PictOpClear: + case PictOpSrc: + return FALSE; + default: + return TRUE; + } +} + + +static Bool +exaGetPixelFromRGBA(CARD32 *pixel, + CARD16 red, + CARD16 green, + CARD16 blue, + CARD16 alpha, + PictFormatPtr pFormat) +{ + int rbits, bbits, gbits, abits; + int rshift, bshift, gshift, ashift; + + *pixel = 0; + + if (!PICT_FORMAT_COLOR(pFormat->format) && + PICT_FORMAT_TYPE(pFormat->format) != PICT_TYPE_A) + return FALSE; + + rbits = PICT_FORMAT_R(pFormat->format); + gbits = PICT_FORMAT_G(pFormat->format); + bbits = PICT_FORMAT_B(pFormat->format); + abits = PICT_FORMAT_A(pFormat->format); + + rshift = pFormat->direct.red; + gshift = pFormat->direct.green; + bshift = pFormat->direct.blue; + ashift = pFormat->direct.alpha; + + *pixel |= ( blue >> (16 - bbits)) << bshift; + *pixel |= ( red >> (16 - rbits)) << rshift; + *pixel |= (green >> (16 - gbits)) << gshift; + *pixel |= (alpha >> (16 - abits)) << ashift; + + return TRUE; +} + +static Bool +exaGetRGBAFromPixel(CARD32 pixel, + CARD16 *red, + CARD16 *green, + CARD16 *blue, + CARD16 *alpha, + PictFormatPtr pFormat, + PictFormatShort format) +{ + int rbits, bbits, gbits, abits; + int rshift, bshift, gshift, ashift; + + if (!PICT_FORMAT_COLOR(format) && PICT_FORMAT_TYPE(format) != PICT_TYPE_A) + return FALSE; + + rbits = PICT_FORMAT_R(format); + gbits = PICT_FORMAT_G(format); + bbits = PICT_FORMAT_B(format); + abits = PICT_FORMAT_A(format); + + if (pFormat) { + rshift = pFormat->direct.red; + gshift = pFormat->direct.green; + bshift = pFormat->direct.blue; + ashift = pFormat->direct.alpha; + } else if (format == PICT_a8r8g8b8) { + rshift = 16; + gshift = 8; + bshift = 0; + ashift = 24; + } else + FatalError("EXA bug: exaGetRGBAFromPixel() doesn't match " + "createSourcePicture()\n"); + + if (rbits) { + *red = ((pixel >> rshift ) & ((1 << rbits) - 1)) << (16 - rbits); + while (rbits < 16) { + *red |= *red >> rbits; + rbits <<= 1; + } + + *green = ((pixel >> gshift ) & ((1 << gbits) - 1)) << (16 - gbits); + while (gbits < 16) { + *green |= *green >> gbits; + gbits <<= 1; + } + + *blue = ((pixel >> bshift ) & ((1 << bbits) - 1)) << (16 - bbits); + while (bbits < 16) { + *blue |= *blue >> bbits; + bbits <<= 1; + } + } else { + *red = 0x0000; + *green = 0x0000; + *blue = 0x0000; + } + + if (abits) { + *alpha = ((pixel >> ashift ) & ((1 << abits) - 1)) << (16 - abits); + while (abits < 16) { + *alpha |= *alpha >> abits; + abits <<= 1; + } + } else + *alpha = 0xffff; + + return TRUE; +} + +static int +exaTryDriverSolidFill(PicturePtr pSrc, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + ExaScreenPriv (pDst->pDrawable->pScreen); + RegionRec region; + BoxPtr pbox; + int nbox; + int dst_off_x, dst_off_y; + PixmapPtr pSrcPix, pDstPix; + ExaPixmapPrivPtr pDstExaPix; + CARD32 pixel; + CARD16 red, green, blue, alpha; + + pDstPix = exaGetDrawablePixmap (pDst->pDrawable); + pDstExaPix = ExaGetPixmapPriv(pDstPix); + + /* Check whether the accelerator can use the destination pixmap. + */ + if (pDstExaPix->accel_blocked) + { + return -1; + } + + xDst += pDst->pDrawable->x; + yDst += pDst->pDrawable->y; + if (pSrc->pDrawable) { + xSrc += pSrc->pDrawable->x; + ySrc += pSrc->pDrawable->y; + } + + if (!miComputeCompositeRegion (®ion, pSrc, NULL, pDst, + xSrc, ySrc, 0, 0, xDst, yDst, + width, height)) + return 1; + + exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &dst_off_x, &dst_off_y); + + RegionTranslate(®ion, dst_off_x, dst_off_y); + + if (pSrc->pDrawable) { + pSrcPix = exaGetDrawablePixmap (pSrc->pDrawable); + pixel = exaGetPixmapFirstPixel (pSrcPix); + } else + pixel = pSrc->pSourcePict->solidFill.color; + + if (!exaGetRGBAFromPixel(pixel, &red, &green, &blue, &alpha, + pSrc->pFormat, pSrc->format) || + !exaGetPixelFromRGBA(&pixel, red, green, blue, alpha, + pDst->pFormat)) + { + RegionUninit(®ion); + return -1; + } + + if (pExaScr->do_migration) { + ExaMigrationRec pixmaps[1]; + + pixmaps[0].as_dst = TRUE; + pixmaps[0].as_src = FALSE; + pixmaps[0].pPix = pDstPix; + pixmaps[0].pReg = ®ion; + exaDoMigration(pixmaps, 1, TRUE); + } + + if (!exaPixmapHasGpuCopy(pDstPix)) { + RegionUninit(®ion); + return 0; + } + + if (!(*pExaScr->info->PrepareSolid) (pDstPix, GXcopy, 0xffffffff, pixel)) + { + RegionUninit(®ion); + return -1; + } + + nbox = RegionNumRects(®ion); + pbox = RegionRects(®ion); + + while (nbox--) + { + (*pExaScr->info->Solid) (pDstPix, pbox->x1, pbox->y1, pbox->x2, pbox->y2); + pbox++; + } + + (*pExaScr->info->DoneSolid) (pDstPix); + exaMarkSync(pDst->pDrawable->pScreen); + + RegionUninit(®ion); + return 1; +} + +static int +exaTryDriverCompositeRects(CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + int nrect, + ExaCompositeRectPtr rects) +{ + ExaScreenPriv (pDst->pDrawable->pScreen); + int src_off_x = 0, src_off_y = 0, mask_off_x = 0, mask_off_y = 0; + int dst_off_x, dst_off_y; + PixmapPtr pSrcPix = NULL, pMaskPix = NULL, pDstPix; + ExaPixmapPrivPtr pSrcExaPix = NULL, pMaskExaPix = NULL, pDstExaPix; + + if (!pExaScr->info->PrepareComposite) + return -1; + + if (pSrc->pDrawable) { + pSrcPix = exaGetDrawablePixmap(pSrc->pDrawable); + pSrcExaPix = ExaGetPixmapPriv(pSrcPix); + } + + if (pMask && pMask->pDrawable) { + pMaskPix = exaGetDrawablePixmap(pMask->pDrawable); + pMaskExaPix = ExaGetPixmapPriv(pMaskPix); + } + + pDstPix = exaGetDrawablePixmap(pDst->pDrawable); + pDstExaPix = ExaGetPixmapPriv(pDstPix); + + /* Check whether the accelerator can use these pixmaps. + * FIXME: If it cannot, use temporary pixmaps so that the drawing + * happens within limits. + */ + if (pDstExaPix->accel_blocked || + (pSrcExaPix && pSrcExaPix->accel_blocked) || + (pMaskExaPix && pMaskExaPix->accel_blocked)) + { + return -1; + } + + if (pExaScr->info->CheckComposite && + !(*pExaScr->info->CheckComposite) (op, pSrc, pMask, pDst)) + { + return -1; + } + + if (pExaScr->do_migration) { + ExaMigrationRec pixmaps[3]; + int i = 0; + + pixmaps[i].as_dst = TRUE; + pixmaps[i].as_src = exaOpReadsDestination(op); + pixmaps[i].pPix = pDstPix; + pixmaps[i].pReg = NULL; + i++; + + if (pSrcPix) { + pixmaps[i].as_dst = FALSE; + pixmaps[i].as_src = TRUE; + pixmaps[i].pPix = pSrcPix; + pixmaps[i].pReg = NULL; + i++; + } + + if (pMaskPix) { + pixmaps[i].as_dst = FALSE; + pixmaps[i].as_src = TRUE; + pixmaps[i].pPix = pMaskPix; + pixmaps[i].pReg = NULL; + i++; + } + + exaDoMigration(pixmaps, i, TRUE); + } + + pDstPix = exaGetOffscreenPixmap (pDst->pDrawable, &dst_off_x, &dst_off_y); + if (!pDstPix) + return 0; + + if (pSrcPix) { + pSrcPix = exaGetOffscreenPixmap (pSrc->pDrawable, &src_off_x, &src_off_y); + if (!pSrcPix) + return 0; + } + + if (pMaskPix) { + pMaskPix = exaGetOffscreenPixmap (pMask->pDrawable, &mask_off_x, &mask_off_y); + if (!pMaskPix) + return 0; + } + + if (!(*pExaScr->info->PrepareComposite) (op, pSrc, pMask, pDst, pSrcPix, + pMaskPix, pDstPix)) + return -1; + + while (nrect--) + { + INT16 xDst = rects->xDst + pDst->pDrawable->x; + INT16 yDst = rects->yDst + pDst->pDrawable->y; + INT16 xMask = rects->xMask; + INT16 yMask = rects->yMask; + INT16 xSrc = rects->xSrc; + INT16 ySrc = rects->ySrc; + RegionRec region; + BoxPtr pbox; + int nbox; + + if (pMaskPix) { + xMask += pMask->pDrawable->x; + yMask += pMask->pDrawable->y; + } + + if (pSrcPix) { + xSrc += pSrc->pDrawable->x; + ySrc += pSrc->pDrawable->y; + } + + if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst, + xSrc, ySrc, xMask, yMask, xDst, yDst, + rects->width, rects->height)) + goto next_rect; + + RegionTranslate(®ion, dst_off_x, dst_off_y); + + nbox = RegionNumRects(®ion); + pbox = RegionRects(®ion); + + xMask = xMask + mask_off_x - xDst - dst_off_x; + yMask = yMask + mask_off_y - yDst - dst_off_y; + xSrc = xSrc + src_off_x - xDst - dst_off_x; + ySrc = ySrc + src_off_y - yDst - dst_off_y; + + while (nbox--) + { + (*pExaScr->info->Composite) (pDstPix, + pbox->x1 + xSrc, + pbox->y1 + ySrc, + pbox->x1 + xMask, + pbox->y1 + yMask, + pbox->x1, + pbox->y1, + pbox->x2 - pbox->x1, + pbox->y2 - pbox->y1); + pbox++; + } + + next_rect: + RegionUninit(®ion); + + rects++; + } + + (*pExaScr->info->DoneComposite) (pDstPix); + exaMarkSync(pDst->pDrawable->pScreen); + + return 1; +} + +/** + * Copy a number of rectangles from source to destination in a single + * operation. This is specialized for glyph rendering: we don't have the + * special-case fallbacks found in exaComposite() - if the driver can support + * it, we use the driver functionality, otherwise we fall back straight to + * software. + */ +void +exaCompositeRects(CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + int nrect, + ExaCompositeRectPtr rects) +{ + ExaScreenPriv (pDst->pDrawable->pScreen); + int n; + ExaCompositeRectPtr r; + int ret; + + /* If we get a mask, that means we're rendering to the exaGlyphs + * destination directly, so the damage layer takes care of this. + */ + if (!pMask) { + RegionRec region; + int x1 = MAXSHORT; + int y1 = MAXSHORT; + int x2 = MINSHORT; + int y2 = MINSHORT; + BoxRec box; + + /* We have to manage the damage ourselves, since CompositeRects isn't + * something in the screen that can be managed by the damage extension, + * and EXA depends on damage to track what needs to be migrated between + * the gpu and the cpu. + */ + + /* Compute the overall extents of the composited region - we're making + * the assumption here that we are compositing a bunch of glyphs that + * cluster closely together and damaging each glyph individually would + * be a loss compared to damaging the bounding box. + */ + n = nrect; + r = rects; + while (n--) { + int rect_x2 = r->xDst + r->width; + int rect_y2 = r->yDst + r->height; + + if (r->xDst < x1) x1 = r->xDst; + if (r->yDst < y1) y1 = r->yDst; + if (rect_x2 > x2) x2 = rect_x2; + if (rect_y2 > y2) y2 = rect_y2; + + r++; + } + + if (x2 <= x1 || y2 <= y1) + return; + + box.x1 = x1; + box.x2 = x2 < MAXSHORT ? x2 : MAXSHORT; + box.y1 = y1; + box.y2 = y2 < MAXSHORT ? y2 : MAXSHORT; + + /* The pixmap migration code relies on pendingDamage indicating + * the bounds of the current rendering, so we need to force + * the actual damage into that region before we do anything, and + * (see use of DamagePendingRegion in exaCopyDirty) + */ + + RegionInit(®ion, &box, 1); + + DamageRegionAppend(pDst->pDrawable, ®ion); + + RegionUninit(®ion); + } + + /************************************************************/ + + ValidatePicture (pSrc); + if (pMask) + ValidatePicture (pMask); + ValidatePicture (pDst); + + ret = exaTryDriverCompositeRects(op, pSrc, pMask, pDst, nrect, rects); + + if (ret != 1) { + if (ret == -1 && op == PictOpOver && pMask && pMask->componentAlpha && + (!pExaScr->info->CheckComposite || + ((*pExaScr->info->CheckComposite)(PictOpOutReverse, pSrc, pMask, + pDst) && + (*pExaScr->info->CheckComposite)(PictOpAdd, pSrc, pMask, pDst)))) { + ret = exaTryDriverCompositeRects(PictOpOutReverse, pSrc, pMask, + pDst, nrect, rects); + if (ret == 1) { + op = PictOpAdd; + ret = exaTryDriverCompositeRects(op, pSrc, pMask, pDst, nrect, + rects); + } + } + + if (ret != 1) { + n = nrect; + r = rects; + while (n--) { + ExaCheckComposite (op, pSrc, pMask, pDst, + r->xSrc, r->ySrc, + r->xMask, r->yMask, + r->xDst, r->yDst, + r->width, r->height); + r++; + } + } + } + + /************************************************************/ + + if (!pMask) { + /* Now we have to flush the damage out from pendingDamage => damage + * Calling DamageRegionProcessPending has that effect. + */ + + DamageRegionProcessPending(pDst->pDrawable); + } +} + +static int +exaTryDriverComposite(CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + ExaScreenPriv (pDst->pDrawable->pScreen); + RegionRec region; + BoxPtr pbox; + int nbox; + int src_off_x, src_off_y, mask_off_x, mask_off_y, dst_off_x, dst_off_y; + PixmapPtr pSrcPix = NULL, pMaskPix = NULL, pDstPix; + ExaPixmapPrivPtr pSrcExaPix = NULL, pMaskExaPix = NULL, pDstExaPix; + + if (pSrc->pDrawable) { + pSrcPix = exaGetDrawablePixmap(pSrc->pDrawable); + pSrcExaPix = ExaGetPixmapPriv(pSrcPix); + } + + pDstPix = exaGetDrawablePixmap(pDst->pDrawable); + pDstExaPix = ExaGetPixmapPriv(pDstPix); + + if (pMask && pMask->pDrawable) { + pMaskPix = exaGetDrawablePixmap(pMask->pDrawable); + pMaskExaPix = ExaGetPixmapPriv(pMaskPix); + } + + /* Check whether the accelerator can use these pixmaps. + * FIXME: If it cannot, use temporary pixmaps so that the drawing + * happens within limits. + */ + if (pDstExaPix->accel_blocked || + (pSrcExaPix && pSrcExaPix->accel_blocked) || + (pMaskExaPix && (pMaskExaPix->accel_blocked))) + { + return -1; + } + + xDst += pDst->pDrawable->x; + yDst += pDst->pDrawable->y; + + if (pMaskPix) { + xMask += pMask->pDrawable->x; + yMask += pMask->pDrawable->y; + } + + if (pSrcPix) { + xSrc += pSrc->pDrawable->x; + ySrc += pSrc->pDrawable->y; + } + + if (pExaScr->info->CheckComposite && + !(*pExaScr->info->CheckComposite) (op, pSrc, pMask, pDst)) + { + return -1; + } + + if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst, + xSrc, ySrc, xMask, yMask, xDst, yDst, + width, height)) + return 1; + + exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &dst_off_x, &dst_off_y); + + RegionTranslate(®ion, dst_off_x, dst_off_y); + + if (pExaScr->do_migration) { + ExaMigrationRec pixmaps[3]; + int i = 0; + + pixmaps[i].as_dst = TRUE; + pixmaps[i].as_src = exaOpReadsDestination(op); + pixmaps[i].pPix = pDstPix; + pixmaps[i].pReg = pixmaps[0].as_src ? NULL : ®ion; + i++; + + if (pSrcPix) { + pixmaps[i].as_dst = FALSE; + pixmaps[i].as_src = TRUE; + pixmaps[i].pPix = pSrcPix; + pixmaps[i].pReg = NULL; + i++; + } + + if (pMaskPix) { + pixmaps[i].as_dst = FALSE; + pixmaps[i].as_src = TRUE; + pixmaps[i].pPix = pMaskPix; + pixmaps[i].pReg = NULL; + i++; + } + + exaDoMigration(pixmaps, i, TRUE); + } + + if (pSrcPix) { + pSrcPix = exaGetOffscreenPixmap (pSrc->pDrawable, &src_off_x, &src_off_y); + if (!pSrcPix) { + RegionUninit(®ion); + return 0; + } + } + + if (pMaskPix) { + pMaskPix = exaGetOffscreenPixmap (pMask->pDrawable, &mask_off_x, + &mask_off_y); + if (!pMaskPix) { + RegionUninit(®ion); + return 0; + } + } + + if (!exaPixmapHasGpuCopy(pDstPix)) { + RegionUninit(®ion); + return 0; + } + + if (!(*pExaScr->info->PrepareComposite) (op, pSrc, pMask, pDst, pSrcPix, + pMaskPix, pDstPix)) + { + RegionUninit(®ion); + return -1; + } + + nbox = RegionNumRects(®ion); + pbox = RegionRects(®ion); + + xMask = xMask + mask_off_x - xDst - dst_off_x; + yMask = yMask + mask_off_y - yDst - dst_off_y; + + xSrc = xSrc + src_off_x - xDst - dst_off_x; + ySrc = ySrc + src_off_y - yDst - dst_off_y; + + while (nbox--) + { + (*pExaScr->info->Composite) (pDstPix, + pbox->x1 + xSrc, + pbox->y1 + ySrc, + pbox->x1 + xMask, + pbox->y1 + yMask, + pbox->x1, + pbox->y1, + pbox->x2 - pbox->x1, + pbox->y2 - pbox->y1); + pbox++; + } + (*pExaScr->info->DoneComposite) (pDstPix); + exaMarkSync(pDst->pDrawable->pScreen); + + RegionUninit(®ion); + return 1; +} + +/** + * exaTryMagicTwoPassCompositeHelper implements PictOpOver using two passes of + * simpler operations PictOpOutReverse and PictOpAdd. Mainly used for component + * alpha and limited 1-tmu cards. + * + * From http://anholt.livejournal.com/32058.html: + * + * The trouble is that component-alpha rendering requires two different sources + * for blending: one for the source value to the blender, which is the + * per-channel multiplication of source and mask, and one for the source alpha + * for multiplying with the destination channels, which is the multiplication + * of the source channels by the mask alpha. So the equation for Over is: + * + * dst.A = src.A * mask.A + (1 - (src.A * mask.A)) * dst.A + * dst.R = src.R * mask.R + (1 - (src.A * mask.R)) * dst.R + * dst.G = src.G * mask.G + (1 - (src.A * mask.G)) * dst.G + * dst.B = src.B * mask.B + (1 - (src.A * mask.B)) * dst.B + * + * But we can do some simpler operations, right? How about PictOpOutReverse, + * which has a source factor of 0 and dest factor of (1 - source alpha). We + * can get the source alpha value (srca.X = src.A * mask.X) out of the texture + * blenders pretty easily. So we can do a component-alpha OutReverse, which + * gets us: + * + * dst.A = 0 + (1 - (src.A * mask.A)) * dst.A + * dst.R = 0 + (1 - (src.A * mask.R)) * dst.R + * dst.G = 0 + (1 - (src.A * mask.G)) * dst.G + * dst.B = 0 + (1 - (src.A * mask.B)) * dst.B + * + * OK. And if an op doesn't use the source alpha value for the destination + * factor, then we can do the channel multiplication in the texture blenders + * to get the source value, and ignore the source alpha that we wouldn't use. + * We've supported this in the Radeon driver for a long time. An example would + * be PictOpAdd, which does: + * + * dst.A = src.A * mask.A + dst.A + * dst.R = src.R * mask.R + dst.R + * dst.G = src.G * mask.G + dst.G + * dst.B = src.B * mask.B + dst.B + * + * Hey, this looks good! If we do a PictOpOutReverse and then a PictOpAdd right + * after it, we get: + * + * dst.A = src.A * mask.A + ((1 - (src.A * mask.A)) * dst.A) + * dst.R = src.R * mask.R + ((1 - (src.A * mask.R)) * dst.R) + * dst.G = src.G * mask.G + ((1 - (src.A * mask.G)) * dst.G) + * dst.B = src.B * mask.B + ((1 - (src.A * mask.B)) * dst.B) + */ + +static int +exaTryMagicTwoPassCompositeHelper(CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + ExaScreenPriv (pDst->pDrawable->pScreen); + + assert(op == PictOpOver); + + if (pExaScr->info->CheckComposite && + (!(*pExaScr->info->CheckComposite)(PictOpOutReverse, pSrc, pMask, + pDst) || + !(*pExaScr->info->CheckComposite)(PictOpAdd, pSrc, pMask, pDst))) + { + return -1; + } + + /* Now, we think we should be able to accelerate this operation. First, + * composite the destination to be the destination times the source alpha + * factors. + */ + exaComposite(PictOpOutReverse, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask, + xDst, yDst, width, height); + + /* Then, add in the source value times the destination alpha factors (1.0). + */ + exaComposite(PictOpAdd, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask, + xDst, yDst, width, height); + + return 1; +} + +void +exaComposite(CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + ExaScreenPriv (pDst->pDrawable->pScreen); + int ret = -1; + Bool saveSrcRepeat = pSrc->repeat; + Bool saveMaskRepeat = pMask ? pMask->repeat : 0; + RegionRec region; + + if (pExaScr->swappedOut) + goto fallback; + + /* Remove repeat in source if useless */ + if (pSrc->pDrawable && pSrc->repeat && !pSrc->transform && xSrc >= 0 && + (xSrc + width) <= pSrc->pDrawable->width && ySrc >= 0 && + (ySrc + height) <= pSrc->pDrawable->height) + pSrc->repeat = 0; + + if (!pMask && !pSrc->alphaMap && !pDst->alphaMap && + (op == PictOpSrc || (op == PictOpOver && !PICT_FORMAT_A(pSrc->format)))) + { + if (pSrc->pDrawable ? + (pSrc->pDrawable->width == 1 && pSrc->pDrawable->height == 1 && + pSrc->repeat) : + (pSrc->pSourcePict->type == SourcePictTypeSolidFill)) + { + ret = exaTryDriverSolidFill(pSrc, pDst, xSrc, ySrc, xDst, yDst, + width, height); + if (ret == 1) + goto done; + } else if (pSrc->pDrawable && !pSrc->transform && + ((op == PictOpSrc && + (pSrc->format == pDst->format || + (PICT_FORMAT_COLOR(pDst->format) && + PICT_FORMAT_COLOR(pSrc->format) && + pDst->format == PICT_FORMAT(PICT_FORMAT_BPP(pSrc->format), + PICT_FORMAT_TYPE(pSrc->format), + 0, + PICT_FORMAT_R(pSrc->format), + PICT_FORMAT_G(pSrc->format), + PICT_FORMAT_B(pSrc->format))))) || + (op == PictOpOver && pSrc->format == pDst->format && + !PICT_FORMAT_A(pSrc->format)))) + { + if (!pSrc->repeat && xSrc >= 0 && ySrc >= 0 && + (xSrc + width <= pSrc->pDrawable->width) && + (ySrc + height <= pSrc->pDrawable->height)) + { + Bool ret; + xDst += pDst->pDrawable->x; + yDst += pDst->pDrawable->y; + xSrc += pSrc->pDrawable->x; + ySrc += pSrc->pDrawable->y; + + if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst, + xSrc, ySrc, xMask, yMask, xDst, + yDst, width, height)) + goto done; + + ret = exaHWCopyNtoN(pSrc->pDrawable, pDst->pDrawable, NULL, + RegionRects(®ion), RegionNumRects(®ion), + xSrc - xDst, ySrc - yDst, FALSE, FALSE); + RegionUninit(®ion); + + /* Reset values to their original values. */ + xDst -= pDst->pDrawable->x; + yDst -= pDst->pDrawable->y; + xSrc -= pSrc->pDrawable->x; + ySrc -= pSrc->pDrawable->y; + + if (!ret) + goto fallback; + + goto done; + } + + if (pSrc->repeat && pSrc->repeatType == RepeatNormal && + pSrc->pDrawable->type == DRAWABLE_PIXMAP) + { + DDXPointRec patOrg; + + /* Let's see if the driver can do the repeat in one go */ + if (pExaScr->info->PrepareComposite && !pSrc->alphaMap && + !pDst->alphaMap) + { + ret = exaTryDriverComposite(op, pSrc, pMask, pDst, xSrc, + ySrc, xMask, yMask, xDst, yDst, + width, height); + if (ret == 1) + goto done; + } + + /* Now see if we can use exaFillRegionTiled() */ + xDst += pDst->pDrawable->x; + yDst += pDst->pDrawable->y; + xSrc += pSrc->pDrawable->x; + ySrc += pSrc->pDrawable->y; + + if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst, xSrc, + ySrc, xMask, yMask, xDst, yDst, + width, height)) + goto done; + + /* pattern origin is the point in the destination drawable + * corresponding to (0,0) in the source */ + patOrg.x = xDst - xSrc; + patOrg.y = yDst - ySrc; + + ret = exaFillRegionTiled(pDst->pDrawable, ®ion, + (PixmapPtr)pSrc->pDrawable, + &patOrg, FB_ALLONES, GXcopy, CT_NONE); + + RegionUninit(®ion); + + if (ret) + goto done; + + /* Let's be correct and restore the variables to their original state. */ + xDst -= pDst->pDrawable->x; + yDst -= pDst->pDrawable->y; + xSrc -= pSrc->pDrawable->x; + ySrc -= pSrc->pDrawable->y; + } + } + } + + /* Remove repeat in mask if useless */ + if (pMask && pMask->pDrawable && pMask->repeat && !pMask->transform && + xMask >= 0 && (xMask + width) <= pMask->pDrawable->width && + yMask >= 0 && (yMask + height) <= pMask->pDrawable->height) + pMask->repeat = 0; + + if (pExaScr->info->PrepareComposite && + !pSrc->alphaMap && (!pMask || !pMask->alphaMap) && !pDst->alphaMap) + { + Bool isSrcSolid; + + ret = exaTryDriverComposite(op, pSrc, pMask, pDst, xSrc, ySrc, xMask, + yMask, xDst, yDst, width, height); + if (ret == 1) + goto done; + + /* For generic masks and solid src pictures, mach64 can do Over in two + * passes, similar to the component-alpha case. + */ + isSrcSolid = pSrc->pDrawable ? + (pSrc->pDrawable->width == 1 && pSrc->pDrawable->height == 1 && + pSrc->repeat) : + (pSrc->pSourcePict->type == SourcePictTypeSolidFill); + + /* If we couldn't do the Composite in a single pass, and it was a + * component-alpha Over, see if we can do it in two passes with + * an OutReverse and then an Add. + */ + if (ret == -1 && op == PictOpOver && pMask && + (pMask->componentAlpha || isSrcSolid)) { + ret = exaTryMagicTwoPassCompositeHelper(op, pSrc, pMask, pDst, + xSrc, ySrc, + xMask, yMask, xDst, yDst, + width, height); + if (ret == 1) + goto done; + } + } + +fallback: +#if DEBUG_TRACE_FALL + exaPrintCompositeFallback (op, pSrc, pMask, pDst); +#endif + + ExaCheckComposite (op, pSrc, pMask, pDst, xSrc, ySrc, + xMask, yMask, xDst, yDst, width, height); + +done: + pSrc->repeat = saveSrcRepeat; + if (pMask) + pMask->repeat = saveMaskRepeat; +} + +/** + * Same as miCreateAlphaPicture, except it uses ExaCheckPolyFillRect instead + * of PolyFillRect to initialize the pixmap after creating it, to prevent + * the pixmap from being migrated. + * + * See the comments about exaTrapezoids and exaTriangles. + */ +static PicturePtr +exaCreateAlphaPicture (ScreenPtr pScreen, + PicturePtr pDst, + PictFormatPtr pPictFormat, + CARD16 width, + CARD16 height) +{ + PixmapPtr pPixmap; + PicturePtr pPicture; + GCPtr pGC; + int error; + xRectangle rect; + + if (width > 32767 || height > 32767) + return 0; + + if (!pPictFormat) + { + if (pDst->polyEdge == PolyEdgeSharp) + pPictFormat = PictureMatchFormat (pScreen, 1, PICT_a1); + else + pPictFormat = PictureMatchFormat (pScreen, 8, PICT_a8); + if (!pPictFormat) + return 0; + } + + pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, + pPictFormat->depth, 0); + if (!pPixmap) + return 0; + pGC = GetScratchGC (pPixmap->drawable.depth, pScreen); + if (!pGC) + { + (*pScreen->DestroyPixmap) (pPixmap); + return 0; + } + ValidateGC (&pPixmap->drawable, pGC); + rect.x = 0; + rect.y = 0; + rect.width = width; + rect.height = height; + ExaCheckPolyFillRect (&pPixmap->drawable, pGC, 1, &rect); + exaPixmapDirty (pPixmap, 0, 0, width, height); + FreeScratchGC (pGC); + pPicture = CreatePicture (0, &pPixmap->drawable, pPictFormat, + 0, 0, serverClient, &error); + (*pScreen->DestroyPixmap) (pPixmap); + return pPicture; +} + +/** + * exaTrapezoids is essentially a copy of miTrapezoids that uses + * exaCreateAlphaPicture instead of miCreateAlphaPicture. + * + * The problem with miCreateAlphaPicture is that it calls PolyFillRect + * to initialize the contents after creating the pixmap, which + * causes the pixmap to be moved in for acceleration. The subsequent + * call to RasterizeTrapezoid won't be accelerated however, which + * forces the pixmap to be moved out again. + * + * exaCreateAlphaPicture avoids this roundtrip by using ExaCheckPolyFillRect + * to initialize the contents. + */ +void +exaTrapezoids (CARD8 op, PicturePtr pSrc, PicturePtr pDst, + PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, + int ntrap, xTrapezoid *traps) +{ + ScreenPtr pScreen = pDst->pDrawable->pScreen; + PictureScreenPtr ps = GetPictureScreen(pScreen); + BoxRec bounds; + + if (maskFormat) { + PicturePtr pPicture; + INT16 xDst, yDst; + INT16 xRel, yRel; + + miTrapezoidBounds (ntrap, traps, &bounds); + + if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) + return; + + xDst = traps[0].left.p1.x >> 16; + yDst = traps[0].left.p1.y >> 16; + + pPicture = exaCreateAlphaPicture (pScreen, pDst, maskFormat, + bounds.x2 - bounds.x1, + bounds.y2 - bounds.y1); + if (!pPicture) + return; + + exaPrepareAccess(pPicture->pDrawable, EXA_PREPARE_DEST); + for (; ntrap; ntrap--, traps++) + (*ps->RasterizeTrapezoid) (pPicture, traps, + -bounds.x1, -bounds.y1); + exaFinishAccess(pPicture->pDrawable, EXA_PREPARE_DEST); + + xRel = bounds.x1 + xSrc - xDst; + yRel = bounds.y1 + ySrc - yDst; + CompositePicture (op, pSrc, pPicture, pDst, + xRel, yRel, 0, 0, bounds.x1, bounds.y1, + bounds.x2 - bounds.x1, + bounds.y2 - bounds.y1); + FreePicture (pPicture, 0); + } else { + if (pDst->polyEdge == PolyEdgeSharp) + maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1); + else + maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8); + for (; ntrap; ntrap--, traps++) + exaTrapezoids (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, traps); + } +} + +/** + * exaTriangles is essentially a copy of miTriangles that uses + * exaCreateAlphaPicture instead of miCreateAlphaPicture. + * + * The problem with miCreateAlphaPicture is that it calls PolyFillRect + * to initialize the contents after creating the pixmap, which + * causes the pixmap to be moved in for acceleration. The subsequent + * call to AddTriangles won't be accelerated however, which forces the pixmap + * to be moved out again. + * + * exaCreateAlphaPicture avoids this roundtrip by using ExaCheckPolyFillRect + * to initialize the contents. + */ +void +exaTriangles (CARD8 op, PicturePtr pSrc, PicturePtr pDst, + PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, + int ntri, xTriangle *tris) +{ + ScreenPtr pScreen = pDst->pDrawable->pScreen; + PictureScreenPtr ps = GetPictureScreen(pScreen); + BoxRec bounds; + + if (maskFormat) { + PicturePtr pPicture; + INT16 xDst, yDst; + INT16 xRel, yRel; + + miTriangleBounds (ntri, tris, &bounds); + + if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2) + return; + + xDst = tris[0].p1.x >> 16; + yDst = tris[0].p1.y >> 16; + + pPicture = exaCreateAlphaPicture (pScreen, pDst, maskFormat, + bounds.x2 - bounds.x1, + bounds.y2 - bounds.y1); + if (!pPicture) + return; + + exaPrepareAccess(pPicture->pDrawable, EXA_PREPARE_DEST); + (*ps->AddTriangles) (pPicture, -bounds.x1, -bounds.y1, ntri, tris); + exaFinishAccess(pPicture->pDrawable, EXA_PREPARE_DEST); + + xRel = bounds.x1 + xSrc - xDst; + yRel = bounds.y1 + ySrc - yDst; + CompositePicture (op, pSrc, pPicture, pDst, + xRel, yRel, 0, 0, bounds.x1, bounds.y1, + bounds.x2 - bounds.x1, bounds.y2 - bounds.y1); + FreePicture (pPicture, 0); + } else { + if (pDst->polyEdge == PolyEdgeSharp) + maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1); + else + maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8); + + for (; ntri; ntri--, tris++) + exaTriangles (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, tris); + } +} diff --git a/xorg-server/glx/glxdri.c b/xorg-server/glx/glxdri.c index 244eac6c2..326f53915 100644 --- a/xorg-server/glx/glxdri.c +++ b/xorg-server/glx/glxdri.c @@ -78,6 +78,7 @@ struct __GLXDRIscreen { const __DRIlegacyExtension *legacy; const __DRIcopySubBufferExtension *copySubBuffer; const __DRIswapControlExtension *swapControl; + const __DRIconfig **driConfigs; #ifdef __DRI_TEX_OFFSET const __DRItexOffsetExtension *texOffset; @@ -585,6 +586,8 @@ static __GLXtextureFromPixmap __glXDRItextureFromPixmap = { static void __glXDRIscreenDestroy(__GLXscreen *baseScreen) { + int i; + __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen; screen->core->destroyScreen(screen->driScreen); @@ -593,6 +596,12 @@ __glXDRIscreenDestroy(__GLXscreen *baseScreen) __glXScreenDestroy(baseScreen); + if (screen->driConfigs) { + for (i = 0; screen->driConfigs[i] != NULL; i++) + free((__DRIconfig **)screen->driConfigs[i]); + free(screen->driConfigs); + } + free(screen); } @@ -967,7 +976,6 @@ __glXDRIscreenProbe(ScreenPtr pScreen) Bool isCapable; size_t buffer_size; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - const __DRIconfig **driConfigs; if (!xf86LoaderCheckSymbol("DRIQueryDirectRenderingCapable") || !DRIQueryDirectRenderingCapable(pScreen, &isCapable) || @@ -1095,7 +1103,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen) pSAREA, fd, loader_extensions, - &driConfigs, + &screen->driConfigs, screen); if (screen->driScreen == NULL) { @@ -1105,7 +1113,8 @@ __glXDRIscreenProbe(ScreenPtr pScreen) } screen->base.fbconfigs = glxConvertConfigs(screen->core, - driConfigs, GLX_WINDOW_BIT); + screen->driConfigs, + GLX_WINDOW_BIT); initializeExtensions(screen); diff --git a/xorg-server/glx/glxdri2.c b/xorg-server/glx/glxdri2.c index e8722585b..8187a3edd 100644 --- a/xorg-server/glx/glxdri2.c +++ b/xorg-server/glx/glxdri2.c @@ -73,6 +73,7 @@ struct __GLXDRIscreen { const __DRIcopySubBufferExtension *copySubBuffer; const __DRIswapControlExtension *swapControl; const __DRItexBufferExtension *texBuffer; + const __DRIconfig **driConfigs; unsigned char glx_enable_bits[__GLX_EXT_BYTES]; }; @@ -363,6 +364,8 @@ static __GLXtextureFromPixmap __glXDRItextureFromPixmap = { static void __glXDRIscreenDestroy(__GLXscreen *baseScreen) { + int i; + __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen; (*screen->core->destroyScreen)(screen->driScreen); @@ -371,6 +374,12 @@ __glXDRIscreenDestroy(__GLXscreen *baseScreen) __glXScreenDestroy(baseScreen); + if (screen->driConfigs) { + for (i = 0; screen->driConfigs[i] != NULL; i++) + free((__DRIconfig **)screen->driConfigs[i]); + free(screen->driConfigs); + } + free(screen); } @@ -688,7 +697,6 @@ __glXDRIscreenProbe(ScreenPtr pScreen) __GLXDRIscreen *screen; size_t buffer_size; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - const __DRIconfig **driConfigs; screen = calloc(1, sizeof *screen); if (screen == NULL) @@ -720,7 +728,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen) (*screen->dri2->createNewScreen)(pScreen->myNum, screen->fd, loader_extensions, - &driConfigs, + &screen->driConfigs, screen); if (screen->driScreen == NULL) { @@ -731,7 +739,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen) initializeExtensions(screen); - screen->base.fbconfigs = glxConvertConfigs(screen->core, driConfigs, + screen->base.fbconfigs = glxConvertConfigs(screen->core, screen->driConfigs, GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT); diff --git a/xorg-server/glx/glxdriswrast.c b/xorg-server/glx/glxdriswrast.c index 9b65f3662..d064a0536 100644 --- a/xorg-server/glx/glxdriswrast.c +++ b/xorg-server/glx/glxdriswrast.c @@ -1,494 +1,502 @@ -/*
- * Copyright © 2008 George Sapountzis <gsap7@yahoo.gr>
- * Copyright © 2008 Red Hat, Inc
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose is hereby granted without
- * fee, provided that the above copyright notice appear in all copies
- * and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of the
- * copyright holders not be used in advertising or publicity
- * pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied
- * warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <dlfcn.h>
-
-#include <GL/gl.h>
-#include <GL/internal/dri_interface.h>
-#include <GL/glxtokens.h>
-
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "gcstruct.h"
-#include "os.h"
-
-#include "glxserver.h"
-#include "glxutil.h"
-#include "glxdricommon.h"
-
-#include "glapitable.h"
-#include "glapi.h"
-#include "glthread.h"
-#include "dispatch.h"
-#include "extension_string.h"
-
-/* RTLD_LOCAL is not defined on Cygwin */
-#ifdef __CYGWIN__
-#ifndef RTLD_LOCAL
-#define RTLD_LOCAL 0
-#endif
-#endif
-
-typedef struct __GLXDRIscreen __GLXDRIscreen;
-typedef struct __GLXDRIcontext __GLXDRIcontext;
-typedef struct __GLXDRIdrawable __GLXDRIdrawable;
-
-struct __GLXDRIscreen {
- __GLXscreen base;
- __DRIscreen *driScreen;
- void *driver;
-
- const __DRIcoreExtension *core;
- const __DRIswrastExtension *swrast;
- const __DRIcopySubBufferExtension *copySubBuffer;
- const __DRItexBufferExtension *texBuffer;
-};
-
-struct __GLXDRIcontext {
- __GLXcontext base;
- __DRIcontext *driContext;
-};
-
-struct __GLXDRIdrawable {
- __GLXdrawable base;
- __DRIdrawable *driDrawable;
- __GLXDRIscreen *screen;
-
- GCPtr gc; /* scratch GC for span drawing */
- GCPtr swapgc; /* GC for swapping the color buffers */
-};
-
-static void
-__glXDRIdrawableDestroy(__GLXdrawable *drawable)
-{
- __GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
- const __DRIcoreExtension *core = private->screen->core;
-
- (*core->destroyDrawable)(private->driDrawable);
-
- FreeGC(private->gc, (GContext)0);
- FreeGC(private->swapgc, (GContext)0);
-
- __glXDrawableRelease(drawable);
-
- free(private);
-}
-
-static GLboolean
-__glXDRIdrawableSwapBuffers(ClientPtr client, __GLXdrawable *drawable)
-{
- __GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
- const __DRIcoreExtension *core = private->screen->core;
-
- (*core->swapBuffers)(private->driDrawable);
-
- return TRUE;
-}
-
-static void
-__glXDRIdrawableCopySubBuffer(__GLXdrawable *basePrivate,
- int x, int y, int w, int h)
-{
- __GLXDRIdrawable *private = (__GLXDRIdrawable *) basePrivate;
- const __DRIcopySubBufferExtension *copySubBuffer =
- private->screen->copySubBuffer;
-
- if (copySubBuffer)
- (*copySubBuffer->copySubBuffer)(private->driDrawable, x, y, w, h);
-}
-
-static void
-__glXDRIcontextDestroy(__GLXcontext *baseContext)
-{
- __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
- __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
-
- (*screen->core->destroyContext)(context->driContext);
- __glXContextDestroy(&context->base);
- free(context);
-}
-
-static int
-__glXDRIcontextMakeCurrent(__GLXcontext *baseContext)
-{
- __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
- __GLXDRIdrawable *draw = (__GLXDRIdrawable *) baseContext->drawPriv;
- __GLXDRIdrawable *read = (__GLXDRIdrawable *) baseContext->readPriv;
- __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
-
- return (*screen->core->bindContext)(context->driContext,
- draw->driDrawable,
- read->driDrawable);
-}
-
-static int
-__glXDRIcontextLoseCurrent(__GLXcontext *baseContext)
-{
- __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
- __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
-
- return (*screen->core->unbindContext)(context->driContext);
-}
-
-static int
-__glXDRIcontextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc,
- unsigned long mask)
-{
- __GLXDRIcontext *dst = (__GLXDRIcontext *) baseDst;
- __GLXDRIcontext *src = (__GLXDRIcontext *) baseSrc;
- __GLXDRIscreen *screen = (__GLXDRIscreen *) dst->base.pGlxScreen;
-
- return (*screen->core->copyContext)(dst->driContext,
- src->driContext, mask);
-}
-
-#ifdef __DRI_TEX_BUFFER
-
-static int
-__glXDRIbindTexImage(__GLXcontext *baseContext,
- int buffer,
- __GLXdrawable *glxPixmap)
-{
- __GLXDRIdrawable *drawable = (__GLXDRIdrawable *) glxPixmap;
- const __DRItexBufferExtension *texBuffer = drawable->screen->texBuffer;
- __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
-
- if (texBuffer == NULL)
- return Success;
-
-#if __DRI_TEX_BUFFER_VERSION >= 2
- if (texBuffer->base.version >= 2 && texBuffer->setTexBuffer2 != NULL) {
- (*texBuffer->setTexBuffer2)(context->driContext,
- glxPixmap->target,
- glxPixmap->format,
- drawable->driDrawable);
- } else
-#endif
- texBuffer->setTexBuffer(context->driContext,
- glxPixmap->target,
- drawable->driDrawable);
-
- return Success;
-}
-
-static int
-__glXDRIreleaseTexImage(__GLXcontext *baseContext,
- int buffer,
- __GLXdrawable *pixmap)
-{
- /* FIXME: Just unbind the texture? */
- return Success;
-}
-
-#else
-
-static int
-__glXDRIbindTexImage(__GLXcontext *baseContext,
- int buffer,
- __GLXdrawable *glxPixmap)
-{
- return Success;
-}
-
-static int
-__glXDRIreleaseTexImage(__GLXcontext *baseContext,
- int buffer,
- __GLXdrawable *pixmap)
-{
- return Success;
-}
-
-#endif
-
-static __GLXtextureFromPixmap __glXDRItextureFromPixmap = {
- __glXDRIbindTexImage,
- __glXDRIreleaseTexImage
-};
-
-static void
-__glXDRIscreenDestroy(__GLXscreen *baseScreen)
-{
- __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
-
- (*screen->core->destroyScreen)(screen->driScreen);
-
- dlclose(screen->driver);
-
- __glXScreenDestroy(baseScreen);
-
- free(screen);
-}
-
-static __GLXcontext *
-__glXDRIscreenCreateContext(__GLXscreen *baseScreen,
- __GLXconfig *glxConfig,
- __GLXcontext *baseShareContext)
-{
- __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
- __GLXDRIcontext *context, *shareContext;
- __GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
- const __DRIcoreExtension *core = screen->core;
- __DRIcontext *driShare;
-
- shareContext = (__GLXDRIcontext *) baseShareContext;
- if (shareContext)
- driShare = shareContext->driContext;
- else
- driShare = NULL;
-
- context = calloc(1, sizeof *context);
- if (context == NULL)
- return NULL;
-
- context->base.destroy = __glXDRIcontextDestroy;
- context->base.makeCurrent = __glXDRIcontextMakeCurrent;
- context->base.loseCurrent = __glXDRIcontextLoseCurrent;
- context->base.copy = __glXDRIcontextCopy;
- context->base.textureFromPixmap = &__glXDRItextureFromPixmap;
-
- context->driContext =
- (*core->createNewContext)(screen->driScreen,
- config->driConfig, driShare, context);
-
- return &context->base;
-}
-
-static __GLXdrawable *
-__glXDRIscreenCreateDrawable(ClientPtr client,
- __GLXscreen *screen,
- DrawablePtr pDraw,
- XID drawId,
- int type,
- XID glxDrawId,
- __GLXconfig *glxConfig)
-{
- XID gcvals[2];
- int status;
- __GLXDRIscreen *driScreen = (__GLXDRIscreen *) screen;
- __GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
- __GLXDRIdrawable *private;
-
- private = calloc(1, sizeof *private);
- if (private == NULL)
- return NULL;
-
- private->screen = driScreen;
- if (!__glXDrawableInit(&private->base, screen,
- pDraw, type, glxDrawId, glxConfig)) {
- free(private);
- return NULL;
- }
-
- private->base.destroy = __glXDRIdrawableDestroy;
- private->base.swapBuffers = __glXDRIdrawableSwapBuffers;
- private->base.copySubBuffer = __glXDRIdrawableCopySubBuffer;
-
- gcvals[0] = GXcopy;
- private->gc = CreateGC(pDraw, GCFunction, gcvals, &status, (XID)0, serverClient);
- gcvals[1] = FALSE;
- private->swapgc = CreateGC(pDraw, GCFunction | GCGraphicsExposures, gcvals, &status, (XID)0, serverClient);
-
- private->driDrawable =
- (*driScreen->swrast->createNewDrawable)(driScreen->driScreen,
- config->driConfig,
- private);
-
- return &private->base;
-}
-
-static void
-swrastGetDrawableInfo(__DRIdrawable *draw,
- int *x, int *y, int *w, int *h,
- void *loaderPrivate)
-{
- __GLXDRIdrawable *drawable = loaderPrivate;
- DrawablePtr pDraw = drawable->base.pDraw;
-
- *x = pDraw->x;
- *y = pDraw->x;
- *w = pDraw->width;
- *h = pDraw->height;
-}
-
-static void
-swrastPutImage(__DRIdrawable *draw, int op,
- int x, int y, int w, int h, char *data,
- void *loaderPrivate)
-{
- __GLXDRIdrawable *drawable = loaderPrivate;
- DrawablePtr pDraw = drawable->base.pDraw;
- GCPtr gc;
-
- switch (op) {
- case __DRI_SWRAST_IMAGE_OP_DRAW:
- gc = drawable->gc;
- break;
- case __DRI_SWRAST_IMAGE_OP_SWAP:
- gc = drawable->swapgc;
- break;
- default:
- return;
- }
-
- ValidateGC(pDraw, gc);
-
- gc->ops->PutImage(pDraw, gc, pDraw->depth,
- x, y, w, h, 0, ZPixmap, data);
-}
-
-static void
-swrastGetImage(__DRIdrawable *draw,
- int x, int y, int w, int h, char *data,
- void *loaderPrivate)
-{
- __GLXDRIdrawable *drawable = loaderPrivate;
- DrawablePtr pDraw = drawable->base.pDraw;
- ScreenPtr pScreen = pDraw->pScreen;
-
- pScreen->GetImage(pDraw, x, y, w, h, ZPixmap, ~0L, data);
-}
-
-static const __DRIswrastLoaderExtension swrastLoaderExtension = {
- { __DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION },
- swrastGetDrawableInfo,
- swrastPutImage,
- swrastGetImage
-};
-
-static const __DRIextension *loader_extensions[] = {
- &systemTimeExtension.base,
- &swrastLoaderExtension.base,
- NULL
-};
-
-static void
-initializeExtensions(__GLXDRIscreen *screen)
-{
- const __DRIextension **extensions;
- int i;
-
- extensions = screen->core->getExtensions(screen->driScreen);
-
- for (i = 0; extensions[i]; i++) {
-#ifdef __DRI_COPY_SUB_BUFFER
- if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) {
- screen->copySubBuffer =
- (const __DRIcopySubBufferExtension *) extensions[i];
- /* GLX_MESA_copy_sub_buffer is always enabled. */
- }
-#endif
-
-#ifdef __DRI_TEX_BUFFER
- if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) {
- screen->texBuffer =
- (const __DRItexBufferExtension *) extensions[i];
- /* GLX_EXT_texture_from_pixmap is always enabled. */
- }
-#endif
- /* Ignore unknown extensions */
- }
-}
-
-static __GLXscreen *
-__glXDRIscreenProbe(ScreenPtr pScreen)
-{
- const char *driverName = "swrast";
- __GLXDRIscreen *screen;
- const __DRIconfig **driConfigs;
-
- screen = calloc(1, sizeof *screen);
- if (screen == NULL)
- return NULL;
-
- screen->base.destroy = __glXDRIscreenDestroy;
- screen->base.createContext = __glXDRIscreenCreateContext;
- screen->base.createDrawable = __glXDRIscreenCreateDrawable;
- screen->base.swapInterval = NULL;
- screen->base.pScreen = pScreen;
-
- screen->driver = glxProbeDriver(driverName,
- (void **)&screen->core,
- __DRI_CORE, __DRI_CORE_VERSION,
- (void **)&screen->swrast,
- __DRI_SWRAST, __DRI_SWRAST_VERSION);
- if (screen->driver == NULL) {
- goto handle_error;
- }
-
- screen->driScreen =
- (*screen->swrast->createNewScreen)(pScreen->myNum,
- loader_extensions,
- &driConfigs,
- screen);
-
- if (screen->driScreen == NULL) {
- LogMessage(X_ERROR,
- "AIGLX error: Calling driver entry point failed\n");
- goto handle_error;
- }
-
- initializeExtensions(screen);
-
- screen->base.fbconfigs = glxConvertConfigs(screen->core, driConfigs,
- GLX_WINDOW_BIT |
- GLX_PIXMAP_BIT |
- GLX_PBUFFER_BIT);
-
- __glXScreenInit(&screen->base, pScreen);
-
- screen->base.GLXmajor = 1;
- screen->base.GLXminor = 4;
-
- LogMessage(X_INFO,
- "AIGLX: Loaded and initialized %s\n", driverName);
-
- return &screen->base;
-
- handle_error:
- if (screen->driver)
- dlclose(screen->driver);
-
- free(screen);
-
- LogMessage(X_ERROR, "GLX: could not load software renderer\n");
-
- return NULL;
-}
-
-_X_EXPORT __GLXprovider __glXDRISWRastProvider = {
- __glXDRIscreenProbe,
- "DRISWRAST",
- NULL
-};
+/* + * Copyright © 2008 George Sapountzis <gsap7@yahoo.gr> + * Copyright © 2008 Red Hat, Inc + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of the + * copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <sys/time.h> +#include <dlfcn.h> + +#include <GL/gl.h> +#include <GL/internal/dri_interface.h> +#include <GL/glxtokens.h> + +#include "scrnintstr.h" +#include "pixmapstr.h" +#include "gcstruct.h" +#include "os.h" + +#include "glxserver.h" +#include "glxutil.h" +#include "glxdricommon.h" + +#include "glapitable.h" +#include "glapi.h" +#include "glthread.h" +#include "dispatch.h" +#include "extension_string.h" + +/* RTLD_LOCAL is not defined on Cygwin */ +#ifdef __CYGWIN__ +#ifndef RTLD_LOCAL +#define RTLD_LOCAL 0 +#endif +#endif + +typedef struct __GLXDRIscreen __GLXDRIscreen; +typedef struct __GLXDRIcontext __GLXDRIcontext; +typedef struct __GLXDRIdrawable __GLXDRIdrawable; + +struct __GLXDRIscreen { + __GLXscreen base; + __DRIscreen *driScreen; + void *driver; + + const __DRIcoreExtension *core; + const __DRIswrastExtension *swrast; + const __DRIcopySubBufferExtension *copySubBuffer; + const __DRItexBufferExtension *texBuffer; + const __DRIconfig **driConfigs; +}; + +struct __GLXDRIcontext { + __GLXcontext base; + __DRIcontext *driContext; +}; + +struct __GLXDRIdrawable { + __GLXdrawable base; + __DRIdrawable *driDrawable; + __GLXDRIscreen *screen; + + GCPtr gc; /* scratch GC for span drawing */ + GCPtr swapgc; /* GC for swapping the color buffers */ +}; + +static void +__glXDRIdrawableDestroy(__GLXdrawable *drawable) +{ + __GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable; + const __DRIcoreExtension *core = private->screen->core; + + (*core->destroyDrawable)(private->driDrawable); + + FreeGC(private->gc, (GContext)0); + FreeGC(private->swapgc, (GContext)0); + + __glXDrawableRelease(drawable); + + free(private); +} + +static GLboolean +__glXDRIdrawableSwapBuffers(ClientPtr client, __GLXdrawable *drawable) +{ + __GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable; + const __DRIcoreExtension *core = private->screen->core; + + (*core->swapBuffers)(private->driDrawable); + + return TRUE; +} + +static void +__glXDRIdrawableCopySubBuffer(__GLXdrawable *basePrivate, + int x, int y, int w, int h) +{ + __GLXDRIdrawable *private = (__GLXDRIdrawable *) basePrivate; + const __DRIcopySubBufferExtension *copySubBuffer = + private->screen->copySubBuffer; + + if (copySubBuffer) + (*copySubBuffer->copySubBuffer)(private->driDrawable, x, y, w, h); +} + +static void +__glXDRIcontextDestroy(__GLXcontext *baseContext) +{ + __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext; + __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen; + + (*screen->core->destroyContext)(context->driContext); + __glXContextDestroy(&context->base); + free(context); +} + +static int +__glXDRIcontextMakeCurrent(__GLXcontext *baseContext) +{ + __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext; + __GLXDRIdrawable *draw = (__GLXDRIdrawable *) baseContext->drawPriv; + __GLXDRIdrawable *read = (__GLXDRIdrawable *) baseContext->readPriv; + __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen; + + return (*screen->core->bindContext)(context->driContext, + draw->driDrawable, + read->driDrawable); +} + +static int +__glXDRIcontextLoseCurrent(__GLXcontext *baseContext) +{ + __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext; + __GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen; + + return (*screen->core->unbindContext)(context->driContext); +} + +static int +__glXDRIcontextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, + unsigned long mask) +{ + __GLXDRIcontext *dst = (__GLXDRIcontext *) baseDst; + __GLXDRIcontext *src = (__GLXDRIcontext *) baseSrc; + __GLXDRIscreen *screen = (__GLXDRIscreen *) dst->base.pGlxScreen; + + return (*screen->core->copyContext)(dst->driContext, + src->driContext, mask); +} + +#ifdef __DRI_TEX_BUFFER + +static int +__glXDRIbindTexImage(__GLXcontext *baseContext, + int buffer, + __GLXdrawable *glxPixmap) +{ + __GLXDRIdrawable *drawable = (__GLXDRIdrawable *) glxPixmap; + const __DRItexBufferExtension *texBuffer = drawable->screen->texBuffer; + __GLXDRIcontext *context = (__GLXDRIcontext *) baseContext; + + if (texBuffer == NULL) + return Success; + +#if __DRI_TEX_BUFFER_VERSION >= 2 + if (texBuffer->base.version >= 2 && texBuffer->setTexBuffer2 != NULL) { + (*texBuffer->setTexBuffer2)(context->driContext, + glxPixmap->target, + glxPixmap->format, + drawable->driDrawable); + } else +#endif + texBuffer->setTexBuffer(context->driContext, + glxPixmap->target, + drawable->driDrawable); + + return Success; +} + +static int +__glXDRIreleaseTexImage(__GLXcontext *baseContext, + int buffer, + __GLXdrawable *pixmap) +{ + /* FIXME: Just unbind the texture? */ + return Success; +} + +#else + +static int +__glXDRIbindTexImage(__GLXcontext *baseContext, + int buffer, + __GLXdrawable *glxPixmap) +{ + return Success; +} + +static int +__glXDRIreleaseTexImage(__GLXcontext *baseContext, + int buffer, + __GLXdrawable *pixmap) +{ + return Success; +} + +#endif + +static __GLXtextureFromPixmap __glXDRItextureFromPixmap = { + __glXDRIbindTexImage, + __glXDRIreleaseTexImage +}; + +static void +__glXDRIscreenDestroy(__GLXscreen *baseScreen) +{ + int i; + + __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen; + + (*screen->core->destroyScreen)(screen->driScreen); + + dlclose(screen->driver); + + __glXScreenDestroy(baseScreen); + + if (screen->driConfigs) { + for (i = 0; screen->driConfigs[i] != NULL; i++) + free((__DRIconfig **)screen->driConfigs[i]); + free(screen->driConfigs); + } + + free(screen); +} + +static __GLXcontext * +__glXDRIscreenCreateContext(__GLXscreen *baseScreen, + __GLXconfig *glxConfig, + __GLXcontext *baseShareContext) +{ + __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen; + __GLXDRIcontext *context, *shareContext; + __GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig; + const __DRIcoreExtension *core = screen->core; + __DRIcontext *driShare; + + shareContext = (__GLXDRIcontext *) baseShareContext; + if (shareContext) + driShare = shareContext->driContext; + else + driShare = NULL; + + context = calloc(1, sizeof *context); + if (context == NULL) + return NULL; + + context->base.destroy = __glXDRIcontextDestroy; + context->base.makeCurrent = __glXDRIcontextMakeCurrent; + context->base.loseCurrent = __glXDRIcontextLoseCurrent; + context->base.copy = __glXDRIcontextCopy; + context->base.textureFromPixmap = &__glXDRItextureFromPixmap; + + context->driContext = + (*core->createNewContext)(screen->driScreen, + config->driConfig, driShare, context); + + return &context->base; +} + +static __GLXdrawable * +__glXDRIscreenCreateDrawable(ClientPtr client, + __GLXscreen *screen, + DrawablePtr pDraw, + XID drawId, + int type, + XID glxDrawId, + __GLXconfig *glxConfig) +{ + XID gcvals[2]; + int status; + __GLXDRIscreen *driScreen = (__GLXDRIscreen *) screen; + __GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig; + __GLXDRIdrawable *private; + + private = calloc(1, sizeof *private); + if (private == NULL) + return NULL; + + private->screen = driScreen; + if (!__glXDrawableInit(&private->base, screen, + pDraw, type, glxDrawId, glxConfig)) { + free(private); + return NULL; + } + + private->base.destroy = __glXDRIdrawableDestroy; + private->base.swapBuffers = __glXDRIdrawableSwapBuffers; + private->base.copySubBuffer = __glXDRIdrawableCopySubBuffer; + + gcvals[0] = GXcopy; + private->gc = CreateGC(pDraw, GCFunction, gcvals, &status, (XID)0, serverClient); + gcvals[1] = FALSE; + private->swapgc = CreateGC(pDraw, GCFunction | GCGraphicsExposures, gcvals, &status, (XID)0, serverClient); + + private->driDrawable = + (*driScreen->swrast->createNewDrawable)(driScreen->driScreen, + config->driConfig, + private); + + return &private->base; +} + +static void +swrastGetDrawableInfo(__DRIdrawable *draw, + int *x, int *y, int *w, int *h, + void *loaderPrivate) +{ + __GLXDRIdrawable *drawable = loaderPrivate; + DrawablePtr pDraw = drawable->base.pDraw; + + *x = pDraw->x; + *y = pDraw->x; + *w = pDraw->width; + *h = pDraw->height; +} + +static void +swrastPutImage(__DRIdrawable *draw, int op, + int x, int y, int w, int h, char *data, + void *loaderPrivate) +{ + __GLXDRIdrawable *drawable = loaderPrivate; + DrawablePtr pDraw = drawable->base.pDraw; + GCPtr gc; + + switch (op) { + case __DRI_SWRAST_IMAGE_OP_DRAW: + gc = drawable->gc; + break; + case __DRI_SWRAST_IMAGE_OP_SWAP: + gc = drawable->swapgc; + break; + default: + return; + } + + ValidateGC(pDraw, gc); + + gc->ops->PutImage(pDraw, gc, pDraw->depth, + x, y, w, h, 0, ZPixmap, data); +} + +static void +swrastGetImage(__DRIdrawable *draw, + int x, int y, int w, int h, char *data, + void *loaderPrivate) +{ + __GLXDRIdrawable *drawable = loaderPrivate; + DrawablePtr pDraw = drawable->base.pDraw; + ScreenPtr pScreen = pDraw->pScreen; + + pScreen->GetImage(pDraw, x, y, w, h, ZPixmap, ~0L, data); +} + +static const __DRIswrastLoaderExtension swrastLoaderExtension = { + { __DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION }, + swrastGetDrawableInfo, + swrastPutImage, + swrastGetImage +}; + +static const __DRIextension *loader_extensions[] = { + &systemTimeExtension.base, + &swrastLoaderExtension.base, + NULL +}; + +static void +initializeExtensions(__GLXDRIscreen *screen) +{ + const __DRIextension **extensions; + int i; + + extensions = screen->core->getExtensions(screen->driScreen); + + for (i = 0; extensions[i]; i++) { +#ifdef __DRI_COPY_SUB_BUFFER + if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) { + screen->copySubBuffer = + (const __DRIcopySubBufferExtension *) extensions[i]; + /* GLX_MESA_copy_sub_buffer is always enabled. */ + } +#endif + +#ifdef __DRI_TEX_BUFFER + if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) { + screen->texBuffer = + (const __DRItexBufferExtension *) extensions[i]; + /* GLX_EXT_texture_from_pixmap is always enabled. */ + } +#endif + /* Ignore unknown extensions */ + } +} + +static __GLXscreen * +__glXDRIscreenProbe(ScreenPtr pScreen) +{ + const char *driverName = "swrast"; + __GLXDRIscreen *screen; + + screen = calloc(1, sizeof *screen); + if (screen == NULL) + return NULL; + + screen->base.destroy = __glXDRIscreenDestroy; + screen->base.createContext = __glXDRIscreenCreateContext; + screen->base.createDrawable = __glXDRIscreenCreateDrawable; + screen->base.swapInterval = NULL; + screen->base.pScreen = pScreen; + + screen->driver = glxProbeDriver(driverName, + (void **)&screen->core, + __DRI_CORE, __DRI_CORE_VERSION, + (void **)&screen->swrast, + __DRI_SWRAST, __DRI_SWRAST_VERSION); + if (screen->driver == NULL) { + goto handle_error; + } + + screen->driScreen = + (*screen->swrast->createNewScreen)(pScreen->myNum, + loader_extensions, + &screen->driConfigs, + screen); + + if (screen->driScreen == NULL) { + LogMessage(X_ERROR, + "AIGLX error: Calling driver entry point failed\n"); + goto handle_error; + } + + initializeExtensions(screen); + + screen->base.fbconfigs = glxConvertConfigs(screen->core, screen->driConfigs, + GLX_WINDOW_BIT | + GLX_PIXMAP_BIT | + GLX_PBUFFER_BIT); + + __glXScreenInit(&screen->base, pScreen); + + screen->base.GLXmajor = 1; + screen->base.GLXminor = 4; + + LogMessage(X_INFO, + "AIGLX: Loaded and initialized %s\n", driverName); + + return &screen->base; + + handle_error: + if (screen->driver) + dlclose(screen->driver); + + free(screen); + + LogMessage(X_ERROR, "GLX: could not load software renderer\n"); + + return NULL; +} + +_X_EXPORT __GLXprovider __glXDRISWRastProvider = { + __glXDRIscreenProbe, + "DRISWRAST", + NULL +}; diff --git a/xorg-server/glx/glxscreens.c b/xorg-server/glx/glxscreens.c index c4ad42648..928cf0c92 100644 --- a/xorg-server/glx/glxscreens.c +++ b/xorg-server/glx/glxscreens.c @@ -419,7 +419,17 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen) void __glXScreenDestroy(__GLXscreen *screen) { + __GLXconfig *head, *next; + + head = screen->fbconfigs; + while (head) { + next = head->next; + free(head); + head = next; + } + free(screen->GLXvendor); free(screen->GLXextensions); free(screen->GLextensions); + free(screen->visuals); } diff --git a/xorg-server/glx/single2.c b/xorg-server/glx/single2.c index 4abd4c084..9f8254b01 100644 --- a/xorg-server/glx/single2.c +++ b/xorg-server/glx/single2.c @@ -1,386 +1,384 @@ -/*
- * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
- * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice including the dates of first publication and
- * either this permission notice or a reference to
- * http://oss.sgi.com/projects/FreeB/
- * shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Except as contained in this notice, the name of Silicon Graphics, Inc.
- * shall not be used in advertising or otherwise to promote the sale, use or
- * other dealings in this Software without prior written authorization from
- * Silicon Graphics, Inc.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "glxserver.h"
-#include "glxutil.h"
-#include "glxext.h"
-#include "indirect_dispatch.h"
-#include "unpack.h"
-#include "glapitable.h"
-#include "glapi.h"
-#include "glthread.h"
-#include "dispatch.h"
-
-int __glXDisp_FeedbackBuffer(__GLXclientState *cl, GLbyte *pc)
-{
- GLsizei size;
- GLenum type;
- __GLXcontext *cx;
- int error;
-
- cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
- if (!cx) {
- return error;
- }
-
- pc += __GLX_SINGLE_HDR_SIZE;
- size = *(GLsizei *)(pc+0);
- type = *(GLenum *)(pc+4);
- if (cx->feedbackBufSize < size) {
- cx->feedbackBuf = (GLfloat *) realloc(cx->feedbackBuf,
- (size_t)size
- * __GLX_SIZE_FLOAT32);
- if (!cx->feedbackBuf) {
- cl->client->errorValue = size;
- return BadAlloc;
- }
- cx->feedbackBufSize = size;
- }
- CALL_FeedbackBuffer( GET_DISPATCH(), (size, type, cx->feedbackBuf) );
- cx->hasUnflushedCommands = GL_TRUE;
- return Success;
-}
-
-int __glXDisp_SelectBuffer(__GLXclientState *cl, GLbyte *pc)
-{
- __GLXcontext *cx;
- GLsizei size;
- int error;
-
- cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
- if (!cx) {
- return error;
- }
-
- pc += __GLX_SINGLE_HDR_SIZE;
- size = *(GLsizei *)(pc+0);
- if (cx->selectBufSize < size) {
- cx->selectBuf = (GLuint *) realloc(cx->selectBuf,
- (size_t) size
- * __GLX_SIZE_CARD32);
- if (!cx->selectBuf) {
- cl->client->errorValue = size;
- return BadAlloc;
- }
- cx->selectBufSize = size;
- }
- CALL_SelectBuffer( GET_DISPATCH(), (size, cx->selectBuf) );
- cx->hasUnflushedCommands = GL_TRUE;
- return Success;
-}
-
-int __glXDisp_RenderMode(__GLXclientState *cl, GLbyte *pc)
-{
- ClientPtr client;
- xGLXRenderModeReply reply;
- __GLXcontext *cx;
- GLint nitems=0, retBytes=0, retval, newModeCheck;
- GLubyte *retBuffer = NULL;
- GLenum newMode;
- int error;
-
- cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
- if (!cx) {
- return error;
- }
-
- pc += __GLX_SINGLE_HDR_SIZE;
- newMode = *(GLenum*) pc;
- retval = CALL_RenderMode( GET_DISPATCH(), (newMode) );
-
- /* Check that render mode worked */
- CALL_GetIntegerv( GET_DISPATCH(), (GL_RENDER_MODE, &newModeCheck) );
- if (newModeCheck != newMode) {
- /* Render mode change failed. Bail */
- newMode = newModeCheck;
- goto noChangeAllowed;
- }
-
- /*
- ** Render mode might have still failed if we get here. But in this
- ** case we can't really tell, nor does it matter. If it did fail, it
- ** will return 0, and thus we won't send any data across the wire.
- */
-
- switch (cx->renderMode) {
- case GL_RENDER:
- cx->renderMode = newMode;
- break;
- case GL_FEEDBACK:
- if (retval < 0) {
- /* Overflow happened. Copy the entire buffer */
- nitems = cx->feedbackBufSize;
- } else {
- nitems = retval;
- }
- retBytes = nitems * __GLX_SIZE_FLOAT32;
- retBuffer = (GLubyte*) cx->feedbackBuf;
- cx->renderMode = newMode;
- break;
- case GL_SELECT:
- if (retval < 0) {
- /* Overflow happened. Copy the entire buffer */
- nitems = cx->selectBufSize;
- } else {
- GLuint *bp = cx->selectBuf;
- GLint i;
-
- /*
- ** Figure out how many bytes of data need to be sent. Parse
- ** the selection buffer to determine this fact as the
- ** return value is the number of hits, not the number of
- ** items in the buffer.
- */
- nitems = 0;
- i = retval;
- while (--i >= 0) {
- GLuint n;
-
- /* Parse select data for this hit */
- n = *bp;
- bp += 3 + n;
- }
- nitems = bp - cx->selectBuf;
- }
- retBytes = nitems * __GLX_SIZE_CARD32;
- retBuffer = (GLubyte*) cx->selectBuf;
- cx->renderMode = newMode;
- break;
- }
-
- /*
- ** First reply is the number of elements returned in the feedback or
- ** selection array, as per the API for glRenderMode itself.
- */
- noChangeAllowed:;
- client = cl->client;
- reply.length = nitems;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.retval = retval;
- reply.size = nitems;
- reply.newMode = newMode;
- WriteToClient(client, sz_xGLXRenderModeReply, (char *)&reply);
- if (retBytes) {
- WriteToClient(client, retBytes, (char *)retBuffer);
- }
- return Success;
-}
-
-int __glXDisp_Flush(__GLXclientState *cl, GLbyte *pc)
-{
- __GLXcontext *cx;
- int error;
-
- cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
- if (!cx) {
- return error;
- }
-
- CALL_Flush( GET_DISPATCH(), () );
- cx->hasUnflushedCommands = GL_FALSE;
- return Success;
-}
-
-int __glXDisp_Finish(__GLXclientState *cl, GLbyte *pc)
-{
- __GLXcontext *cx;
- ClientPtr client;
- int error;
-
- cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
- if (!cx) {
- return error;
- }
-
- /* Do a local glFinish */
- CALL_Finish( GET_DISPATCH(), () );
- cx->hasUnflushedCommands = GL_FALSE;
-
- /* Send empty reply packet to indicate finish is finished */
- client = cl->client;
- __GLX_BEGIN_REPLY(0);
- __GLX_SEND_HEADER();
- return Success;
-}
-
-#define SEPARATOR " "
-
-char *__glXcombine_strings(const char *cext_string, const char *sext_string)
-{
- size_t clen, slen;
- char *combo_string, *token, *s1;
- const char *s2, *end;
-
- /* safeguard to prevent potentially fatal errors in the string functions */
- if (!cext_string)
- cext_string = "";
- if (!sext_string)
- sext_string = "";
-
- /*
- ** String can't be longer than min(cstring, sstring)
- ** pull tokens out of shortest string
- ** include space in combo_string for final separator and null terminator
- */
- clen = strlen(cext_string);
- slen = strlen(sext_string);
- if (clen > slen) {
- combo_string = (char *) malloc(slen + 2);
- s1 = (char *) malloc(slen + 2);
- if (s1) strcpy(s1, sext_string);
- s2 = cext_string;
- } else {
- combo_string = (char *) malloc(clen + 2);
- s1 = (char *) malloc(clen + 2);
- if (s1) strcpy(s1, cext_string);
- s2 = sext_string;
- }
- if (!combo_string || !s1) {
- free(combo_string);
- free(s1);
- return NULL;
- }
- combo_string[0] = '\0';
-
- /* Get first extension token */
- token = strtok( s1, SEPARATOR);
- while ( token != NULL ) {
-
- /*
- ** if token in second string then save it
- ** beware of extension names which are prefixes of other extension names
- */
- const char *p = s2;
- end = p + strlen(p);
- while (p < end) {
- size_t n = strcspn(p, SEPARATOR);
- if ((strlen(token) == n) && (strncmp(token, p, n) == 0)) {
- combo_string = strcat(combo_string, token);
- combo_string = strcat(combo_string, SEPARATOR);
- }
- p += (n + 1);
- }
-
- /* Get next extension token */
- token = strtok( NULL, SEPARATOR);
- }
- free(s1);
- return combo_string;
-}
-
-int DoGetString(__GLXclientState *cl, GLbyte *pc, GLboolean need_swap)
-{
- ClientPtr client;
- __GLXcontext *cx;
- GLenum name;
- const char *string;
- __GLX_DECLARE_SWAP_VARIABLES;
- int error;
- char *buf = NULL, *buf1 = NULL;
- GLint length = 0;
-
- /* If the client has the opposite byte order, swap the contextTag and
- * the name.
- */
- if ( need_swap ) {
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + __GLX_SINGLE_HDR_SIZE);
- }
-
- cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
- if (!cx) {
- return error;
- }
-
- pc += __GLX_SINGLE_HDR_SIZE;
- name = *(GLenum *)(pc + 0);
- string = (const char *) CALL_GetString( GET_DISPATCH(), (name) );
- client = cl->client;
-
- if (string == NULL)
- string = "";
-
- /*
- ** Restrict extensions to those that are supported by both the
- ** implementation and the connection. That is, return the
- ** intersection of client, server, and core extension strings.
- */
- if (name == GL_EXTENSIONS) {
- buf1 = __glXcombine_strings(string,
- cl->GLClientextensions);
- buf = __glXcombine_strings(buf1,
- cx->pGlxScreen->GLextensions);
- free(buf1);
- string = buf;
- }
- else if ( name == GL_VERSION ) {
- if ( atof( string ) > atof( GLServerVersion ) ) {
- buf = malloc( strlen( string ) + strlen( GLServerVersion ) + 4 );
- if ( buf == NULL ) {
- string = GLServerVersion;
- }
- else {
- sprintf( buf, "%s (%s)", GLServerVersion, string );
- string = buf;
- }
- }
- }
- if (string) {
- length = strlen((const char *) string) + 1;
- }
-
- __GLX_BEGIN_REPLY(length);
- __GLX_PUT_SIZE(length);
-
- if ( need_swap ) {
- __GLX_SWAP_REPLY_SIZE();
- __GLX_SWAP_REPLY_HEADER();
- }
-
- __GLX_SEND_HEADER();
- WriteToClient(client, length, (char *) string);
- free(buf);
-
- return Success;
-}
-
-int __glXDisp_GetString(__GLXclientState *cl, GLbyte *pc)
-{
- return DoGetString(cl, pc, GL_FALSE);
-}
+/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "glxserver.h" +#include "glxutil.h" +#include "glxext.h" +#include "indirect_dispatch.h" +#include "unpack.h" +#include "glapitable.h" +#include "glapi.h" +#include "glthread.h" +#include "dispatch.h" + +int __glXDisp_FeedbackBuffer(__GLXclientState *cl, GLbyte *pc) +{ + GLsizei size; + GLenum type; + __GLXcontext *cx; + int error; + + cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error); + if (!cx) { + return error; + } + + pc += __GLX_SINGLE_HDR_SIZE; + size = *(GLsizei *)(pc+0); + type = *(GLenum *)(pc+4); + if (cx->feedbackBufSize < size) { + cx->feedbackBuf = (GLfloat *) realloc(cx->feedbackBuf, + (size_t)size + * __GLX_SIZE_FLOAT32); + if (!cx->feedbackBuf) { + cl->client->errorValue = size; + return BadAlloc; + } + cx->feedbackBufSize = size; + } + CALL_FeedbackBuffer( GET_DISPATCH(), (size, type, cx->feedbackBuf) ); + cx->hasUnflushedCommands = GL_TRUE; + return Success; +} + +int __glXDisp_SelectBuffer(__GLXclientState *cl, GLbyte *pc) +{ + __GLXcontext *cx; + GLsizei size; + int error; + + cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error); + if (!cx) { + return error; + } + + pc += __GLX_SINGLE_HDR_SIZE; + size = *(GLsizei *)(pc+0); + if (cx->selectBufSize < size) { + cx->selectBuf = (GLuint *) realloc(cx->selectBuf, + (size_t) size + * __GLX_SIZE_CARD32); + if (!cx->selectBuf) { + cl->client->errorValue = size; + return BadAlloc; + } + cx->selectBufSize = size; + } + CALL_SelectBuffer( GET_DISPATCH(), (size, cx->selectBuf) ); + cx->hasUnflushedCommands = GL_TRUE; + return Success; +} + +int __glXDisp_RenderMode(__GLXclientState *cl, GLbyte *pc) +{ + ClientPtr client; + xGLXRenderModeReply reply; + __GLXcontext *cx; + GLint nitems=0, retBytes=0, retval, newModeCheck; + GLubyte *retBuffer = NULL; + GLenum newMode; + int error; + + cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error); + if (!cx) { + return error; + } + + pc += __GLX_SINGLE_HDR_SIZE; + newMode = *(GLenum*) pc; + retval = CALL_RenderMode( GET_DISPATCH(), (newMode) ); + + /* Check that render mode worked */ + CALL_GetIntegerv( GET_DISPATCH(), (GL_RENDER_MODE, &newModeCheck) ); + if (newModeCheck != newMode) { + /* Render mode change failed. Bail */ + newMode = newModeCheck; + goto noChangeAllowed; + } + + /* + ** Render mode might have still failed if we get here. But in this + ** case we can't really tell, nor does it matter. If it did fail, it + ** will return 0, and thus we won't send any data across the wire. + */ + + switch (cx->renderMode) { + case GL_RENDER: + cx->renderMode = newMode; + break; + case GL_FEEDBACK: + if (retval < 0) { + /* Overflow happened. Copy the entire buffer */ + nitems = cx->feedbackBufSize; + } else { + nitems = retval; + } + retBytes = nitems * __GLX_SIZE_FLOAT32; + retBuffer = (GLubyte*) cx->feedbackBuf; + cx->renderMode = newMode; + break; + case GL_SELECT: + if (retval < 0) { + /* Overflow happened. Copy the entire buffer */ + nitems = cx->selectBufSize; + } else { + GLuint *bp = cx->selectBuf; + GLint i; + + /* + ** Figure out how many bytes of data need to be sent. Parse + ** the selection buffer to determine this fact as the + ** return value is the number of hits, not the number of + ** items in the buffer. + */ + nitems = 0; + i = retval; + while (--i >= 0) { + GLuint n; + + /* Parse select data for this hit */ + n = *bp; + bp += 3 + n; + } + nitems = bp - cx->selectBuf; + } + retBytes = nitems * __GLX_SIZE_CARD32; + retBuffer = (GLubyte*) cx->selectBuf; + cx->renderMode = newMode; + break; + } + + /* + ** First reply is the number of elements returned in the feedback or + ** selection array, as per the API for glRenderMode itself. + */ + noChangeAllowed:; + client = cl->client; + reply.length = nitems; + reply.type = X_Reply; + reply.sequenceNumber = client->sequence; + reply.retval = retval; + reply.size = nitems; + reply.newMode = newMode; + WriteToClient(client, sz_xGLXRenderModeReply, (char *)&reply); + if (retBytes) { + WriteToClient(client, retBytes, (char *)retBuffer); + } + return Success; +} + +int __glXDisp_Flush(__GLXclientState *cl, GLbyte *pc) +{ + __GLXcontext *cx; + int error; + + cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error); + if (!cx) { + return error; + } + + CALL_Flush( GET_DISPATCH(), () ); + cx->hasUnflushedCommands = GL_FALSE; + return Success; +} + +int __glXDisp_Finish(__GLXclientState *cl, GLbyte *pc) +{ + __GLXcontext *cx; + ClientPtr client; + int error; + + cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error); + if (!cx) { + return error; + } + + /* Do a local glFinish */ + CALL_Finish( GET_DISPATCH(), () ); + cx->hasUnflushedCommands = GL_FALSE; + + /* Send empty reply packet to indicate finish is finished */ + client = cl->client; + __GLX_BEGIN_REPLY(0); + __GLX_SEND_HEADER(); + return Success; +} + +#define SEPARATOR " " + +char *__glXcombine_strings(const char *cext_string, const char *sext_string) +{ + size_t clen, slen; + char *combo_string, *token, *s1; + const char *s2, *end; + + /* safeguard to prevent potentially fatal errors in the string functions */ + if (!cext_string) + cext_string = ""; + if (!sext_string) + sext_string = ""; + + /* + ** String can't be longer than min(cstring, sstring) + ** pull tokens out of shortest string + ** include space in combo_string for final separator and null terminator + */ + clen = strlen(cext_string); + slen = strlen(sext_string); + if (clen > slen) { + combo_string = (char *) malloc(slen + 2); + s1 = (char *) malloc(slen + 2); + if (s1) strcpy(s1, sext_string); + s2 = cext_string; + } else { + combo_string = (char *) malloc(clen + 2); + s1 = (char *) malloc(clen + 2); + if (s1) strcpy(s1, cext_string); + s2 = sext_string; + } + if (!combo_string || !s1) { + free(combo_string); + free(s1); + return NULL; + } + combo_string[0] = '\0'; + + /* Get first extension token */ + token = strtok( s1, SEPARATOR); + while ( token != NULL ) { + + /* + ** if token in second string then save it + ** beware of extension names which are prefixes of other extension names + */ + const char *p = s2; + end = p + strlen(p); + while (p < end) { + size_t n = strcspn(p, SEPARATOR); + if ((strlen(token) == n) && (strncmp(token, p, n) == 0)) { + combo_string = strcat(combo_string, token); + combo_string = strcat(combo_string, SEPARATOR); + } + p += (n + 1); + } + + /* Get next extension token */ + token = strtok( NULL, SEPARATOR); + } + free(s1); + return combo_string; +} + +int DoGetString(__GLXclientState *cl, GLbyte *pc, GLboolean need_swap) +{ + ClientPtr client; + __GLXcontext *cx; + GLenum name; + const char *string; + __GLX_DECLARE_SWAP_VARIABLES; + int error; + char *buf = NULL, *buf1 = NULL; + GLint length = 0; + + /* If the client has the opposite byte order, swap the contextTag and + * the name. + */ + if ( need_swap ) { + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + __GLX_SINGLE_HDR_SIZE); + } + + cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error); + if (!cx) { + return error; + } + + pc += __GLX_SINGLE_HDR_SIZE; + name = *(GLenum *)(pc + 0); + string = (const char *) CALL_GetString( GET_DISPATCH(), (name) ); + client = cl->client; + + if (string == NULL) + string = ""; + + /* + ** Restrict extensions to those that are supported by both the + ** implementation and the connection. That is, return the + ** intersection of client, server, and core extension strings. + */ + if (name == GL_EXTENSIONS) { + buf1 = __glXcombine_strings(string, + cl->GLClientextensions); + buf = __glXcombine_strings(buf1, + cx->pGlxScreen->GLextensions); + free(buf1); + string = buf; + } + else if ( name == GL_VERSION ) { + if ( atof( string ) > atof( GLServerVersion ) ) { + if ( asprintf( &buf, "%s (%s)", GLServerVersion, string ) == -1) { + string = GLServerVersion; + } + else { + string = buf; + } + } + } + if (string) { + length = strlen((const char *) string) + 1; + } + + __GLX_BEGIN_REPLY(length); + __GLX_PUT_SIZE(length); + + if ( need_swap ) { + __GLX_SWAP_REPLY_SIZE(); + __GLX_SWAP_REPLY_HEADER(); + } + + __GLX_SEND_HEADER(); + WriteToClient(client, length, (char *) string); + free(buf); + + return Success; +} + +int __glXDisp_GetString(__GLXclientState *cl, GLbyte *pc) +{ + return DoGetString(cl, pc, GL_FALSE); +} diff --git a/xorg-server/hw/dmx/config/Makefile.am b/xorg-server/hw/dmx/config/Makefile.am index de4ce315d..75181436e 100644 --- a/xorg-server/hw/dmx/config/Makefile.am +++ b/xorg-server/hw/dmx/config/Makefile.am @@ -22,6 +22,10 @@ MAINTAINERCLEANFILES = $(BUILT_SOURCES) libdmxconfig_a_SOURCES = $(LIBSRCS) +if NEED_STRLCAT +libdmxconfig_a_SOURCES += $(top_srcdir)/os/strlcpy.c +endif + if GLX GLX_DEFS = @GL_CFLAGS@ endif diff --git a/xorg-server/hw/dmx/config/dmxcompat.c b/xorg-server/hw/dmx/config/dmxcompat.c index b4190ffcc..1c72084fa 100644 --- a/xorg-server/hw/dmx/config/dmxcompat.c +++ b/xorg-server/hw/dmx/config/dmxcompat.c @@ -42,6 +42,7 @@ #include <dmx-config.h> #endif +#include "os.h" #include "dmxconfig.h" #include "dmxparse.h" #include "dmxcompat.h" @@ -94,8 +95,7 @@ static void dmxVDLDisplayEntry(const char *buf, char *end; pt = strchr(buf, ' '); - strncpy(name, buf, pt-buf); - name[pt-buf] = '\0'; + strlcpy(name, buf, 1+pt-buf); *len = strlen(name); *x = strtol(pt, &end, 10); diff --git a/xorg-server/hw/dmx/config/scanner.l b/xorg-server/hw/dmx/config/scanner.l index cef99d088..e527d6df5 100644 --- a/xorg-server/hw/dmx/config/scanner.l +++ b/xorg-server/hw/dmx/config/scanner.l @@ -39,6 +39,7 @@ #include "dmxparse.h" #include "parser.h" +#include "os.h" #include <string.h> #include <stdlib.h> #include <ctype.h> @@ -152,7 +153,7 @@ static int getdimension(int token, const char *text, int leng) char *tmp = dmxConfigAlloc(leng+1); int x, y; - strncpy(tmp, text, leng); + strlcpy(tmp, text, leng+1); x = strtol(tmp, &endptr, 10); while (*endptr && !isdigit(*endptr)) ++endptr; y = strtol(endptr, NULL, 10); diff --git a/xorg-server/hw/dmx/dmxinit.c b/xorg-server/hw/dmx/dmxinit.c index 165476c5f..57c242598 100644 --- a/xorg-server/hw/dmx/dmxinit.c +++ b/xorg-server/hw/dmx/dmxinit.c @@ -138,7 +138,7 @@ static int dmxErrorHandler(Display *dpy, XErrorEvent *ev) for (ext = dpy->ext_procs; ext && ext->codes.major_opcode != ev->request_code; ext = ext->next); - if (ext) strncpy(buf, ext->name, sizeof(buf)); + if (ext) strlcpy(buf, ext->name, sizeof(buf)); else buf[0] = '\0'; } dmxLog(dmxWarning, " Major opcode: %d (%s)\n", @@ -800,20 +800,17 @@ void InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[]) /* RATS: Assuming the fp string (which comes from the command-line argv vector) is NULL-terminated, the buffer is large enough for the strcpy. */ -static void dmxSetDefaultFontPath(char *fp) +static void dmxSetDefaultFontPath(const char *fp) { - int fplen = strlen(fp) + 1; - if (dmxFontPath) { - int len; + int fplen = strlen(fp) + 1; + int len = strlen(dmxFontPath); - len = strlen(dmxFontPath); dmxFontPath = realloc(dmxFontPath, len+fplen+1); dmxFontPath[len] = ','; strncpy(&dmxFontPath[len+1], fp, fplen); } else { - dmxFontPath = malloc(fplen); - strncpy(dmxFontPath, fp, fplen); + dmxFontPath = strdup(fp); } defaultFontPath = dmxFontPath; diff --git a/xorg-server/hw/dmx/doc/dmx.xml b/xorg-server/hw/dmx/doc/dmx.xml index 845eec97a..793aacea0 100644 --- a/xorg-server/hw/dmx/doc/dmx.xml +++ b/xorg-server/hw/dmx/doc/dmx.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [ + <!ENTITY % defs SYSTEM "/xserver/doc/xml/xserver.ent"> %defs; ]> <article> @@ -14,6 +15,7 @@ <author><firstname>Rickard E.</firstname><surname>Faith</surname></author> </authorgroup> <pubdate>29 June 2004 (created 25 July 2001)</pubdate> + <releaseinfo>X Server Version &xserver.version;</releaseinfo> <abstract><para> This document covers the motivation, background, design, and implementation of the distributed multihead X (DMX) system. It diff --git a/xorg-server/hw/dmx/doc/scaled.xml b/xorg-server/hw/dmx/doc/scaled.xml index 575cafd9d..30c9b9f50 100644 --- a/xorg-server/hw/dmx/doc/scaled.xml +++ b/xorg-server/hw/dmx/doc/scaled.xml @@ -1,725 +1,727 @@ -<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
- "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
-]>
- <article>
-
- <articleinfo>
- <!-- Title information -->
- <title>Scaled Window Support in DMX</title>
- <authorgroup>
- <author><firstname>Kevin E.</firstname><surname>Martin</surname></author>
- <author><firstname>Rickard E.</firstname><surname>Faith</surname></author>
- </authorgroup>
- <pubdate>15 October 2003 (created 19 September 2003)</pubdate>
- <abstract>
- <para>
- This document investigates the possibility of adding scaled window
- support to the DMX X server, thereby allowing a window or some
- selected part of the logical DMX area to be displayed using a
- scaling factor. For example, this might allow the contents of a
- window to be magnified for easier viewing. In particular, scaling
- for the VNC client is explored. <emphasis remap="it">Copyright 2003
- by Red Hat, Inc., Raleigh, North Carolina</emphasis>
- </para>
- </abstract>
- </articleinfo>
-
- <!-- Begin the document -->
- <sect1><title>Introduction</title>
- <sect2><title>DMX</title>
- <para>
- The DMX X server (Xdmx) is a proxy server that is designed
- to allow X servers on multiple machines to be combined into
- a single multi-headed X server. Combined with Xinerama,
- these heads can appear as a single very high-resolution
- screen. Typical applications include the creation of a
- video wall with 16 1280x1024 displays arranged in a
- rectangle, for a total resolution of of 5120x4096.
- </para>
- </sect2>
- <sect2><title>Problem Statement</title>
- <para>
- Applications displayed on a physically large video wall that
- provides high pixel-resolution may be difficult to see,
- especially if the application is designed for use on a
- typical desktop computer with a relatively small display
- located close to the human operator. The goal of this paper
- is to describe and discuss solutions to this problem.
- </para>
- <para>
- The original driving problem for this work is to provide
- scaling for the <command>vncviewer</command> application when
- displayed using DMX (VNC scaling is currently available only
- with the Windows client, and there is no plan to extend that
- capability to other clients). While this specific problem
- will be addressed in this paper, the general solution space
- will also be explored, since this may lead to a good
- solution not only for <command>vncviewer</command> but also for
- other applications.
- </para>
- </sect2>
- <sect2><title>Task</title>
- <para>
- For reference, here is the original description of the task
- this paper addresses:
- <itemizedlist>
- <listitem><para>Scaled window support (for VNC)
- <itemizedlist>
- <listitem><para>
- Investigate possibility of implementing a "scaled
- window" extension:
- <itemizedlist>
- <listitem><para>
- Add XCreateScaledWindow call that could be used
- in place of XCreateWindow
- </para></listitem>
- <listitem><para>
- All primitives drawn to scaled window would be
- scaled by appropriate (integral?) scaling factor
- </para></listitem>
- </itemizedlist>
- </para></listitem>
- <listitem><para>
- Alternate approach: special case VNC support
- </para></listitem>
- </itemizedlist>
- </para></listitem>
- </itemizedlist>
- </para>
- </sect2>
- </sect1>
-
- <sect1><title>Previous Work</title>
- <para>
- This section reviews relevant previous work.
- </para>
- <sect2><title>VNC</title>
- <sect3><title>Scaling under VNC</title>
- <para>
- When using the <command>vncviewer</command> program for Windows, it
- is possible to specify a scaling factor (as numerator and
- denominator). When scaling is in effect, the viewer
- software uses StretchBlt (instead of BitBlt) to display
- the pixels for the user. When this call is made, the
- viewer already has received all of the pixel information
- (at full unscaled resolution).
- </para>
- <para>
- The scaling in VNC is primitive. It does not conserve
- bandwidth, it does not treat textual information
- differently (i.e., by using a suitably scaled font), and
- it does not provide any anti-aliasing other than that
- provided by the underlying (Windows-only) system library.
- </para>
- </sect3>
- </sect2>
- <sect2><title>The X Video Extension</title>
- <para>
- The X Video Extension is a widely-available extension to the
- X11 protocol that provides support for streaming video.
- Integral to this support is the ability to arbitrarily scale
- the output. In version 2.2 of the X Video specification,
- support for scaled still images was provided, using both
- shared memory and traditional transport. The API for this
- support uses calls that are quite similar to XCreateWindow,
- XPutImage, and XShmPutImage. Currently, most of the drivers
- implemented in XFree86 only support data in various YUV
- formats. However, several modern video adaptors support RGB
- as well.
- </para>
- <para>
- Note, though, that the target output for this scaling is an
- overlay plane -- so X Video provides functionality that is
- fundamentally different from that provided by the Windows
- StrechBlt call.
- </para>
- </sect2>
- </sect1>
-
- <sect1><title>Possible Solutions</title>
- <para>
- This section briefly discusses possible solutions, including
- major advantages and disadvantages from both the
- implementation and the end-user programmer standpoint.
- </para>
- <sect2><title>VNC-like Scaling</title>
- <sect3><title>Software Scaling</title>
- <para>
- The <command>vncviewer</command> application could be modified to
- provide software scaling. This is not a general solution,
- but it does solve one of the goals of this work.
- </para>
- <para>
- A prototype of this solution was implemented and a patch
- against <filename>vnc-3.3.7-unixsrc</filename> is available in the
- <filename>dmx/external</filename> directory. Because of limited time
- available for this work, all of the edge cases were not
- considered and the solution works well mainly for integer
- scaling.
- </para>
- <para>
- Currently, <command>vncviewer</command> writes to the X display
- with XPutImage, XCopyArea, and XFillRectangle. All
- instances of these calls have to be aware of scaling
- and must round correctly. In the prototype solution,
- rounding is incorrect and can cause artifacts.
- </para>
- <para>
- A better solution would be to cache all updates to the
- desktop image in <command>vncviewer</command> and only send the
- damaged area to the X display with XPutImage. This would
- allow the damaged area to be computed so that rounding
- errors do not create artifacts. This method is probably
- similar to what is used in the Window client. (The whole
- VNC suite is being re-written in C++ and the forthcoming
- version 4 has not been evaluated.)
- </para>
- </sect3>
- <sect3><title>Scaling with the X Video Extension</title>
- <para>
- The scaling in the Windows <command>vncviewer</command> application
- makes use of a scaled blit that is supplied by the
- underlying system library. Several video cards currently
- provide support for a scaled blit, and some X servers
- (including XFree86) expose this capability to applications
- via the XvPutImage interface of the X Video Extension.
- The capability exposed by XvPutImage results in the scaled
- image being drawn to an overlay plane. Most video cards
- also provide support for a scaled blit into the normal
- output planes, but this is not exposed via XvPutImage.
- </para>
- <para>
- The <command>vncviewer</command> program could be modified to use
- the X Video Extension to provide scaling under X11 that is
- similar to the scaling currently provided under Windows.
- Unfortunately, Xdmx does not currently export the X Video
- Extension, so this would not provide an immediate solution
- usable with DMX.
- </para>
- <para>
- A very early-stage proof-of-concept prototype was
- implemented and a preliminary patch against
- <filename>vnc-3.3.7-unixsrc</filename> is available in the
- <filename>dmx/external</filename> directory. This prototype was
- implemented to better understand the problems that must be
- solved to make this solution viable:
- <itemizedlist>
- <listitem><para>
- As noted under the software scaling section above,
- <command>vncviewer</command> writes to the X display with
- several different calls. These calls write to the
- normal output planes and are compatible with
- XvPutImage, which writes to an overlay plane. To
- eliminate artifacts caused by this problem,
- <command>vncviewer</command> should be modified so that a cached
- copy of the desktop is available, either as a
- client-side image or a server-side off-screen pixmap,
- so that XvPutImage would be the only method for
- writing to the X display.
- </para></listitem>
- <listitem>
- <para>
- Although several modern graphics adaptors support
- hardware scaling using an RGB format (e.g., ATI
- Radeon, nVidia, etc.), XFree86 drivers typically
- only implement YUV formats. YUV generally compress
- the pixel information in some way. For example, two
- commonly implemented formats, YUY2 and UYVY provide
- intensity information for every RGB pixel, but only
- provide chroma and luminance information for pairs
- of horizontal pixels. Since VNC uses
- pixel-resolution for communicating updates on the
- wire, additional artifacts are introduced (because
- there may not be enough information from the wire to
- update a pair of pixels).
- </para>
- <para>
- Further, the well-known problem with YUV encoding
- is even more evident when the image is a desktop
- instead of a movie. For example, consider a
- 1-pixel-wide vertical window border. If the border
- changes in color but not intensity (e.g., because a
- window manager uses color to indicate focus), there
- may or may not be a change in the YUY2 image,
- depending on the algorithm used for RGB to YUV
- conversion and on how the border pixel is ordered in
- the pair of pixels used by the algorithm.
- </para>
- <para>
- Many of these artifacts could be eliminated if
- <command>vncviewer</command> cached a complete RGB image of
- the desktop, and only did the conversion to YUV for
- properly aligned areas of damage. The remaining artifacts
- could be eliminated if an RGB format was used with X
- Video (which may require the extension of existing
- XFree86 drivers to support RGB).
- </para>
- </listitem>
- <listitem><para>
- Most modern video cards support exactly one overlay
- plane that is suitable for use with X Video.
- Therefore, only one application can use X Video at any
- given time. This is a severe limitation in a desktop
- environment.
- </para></listitem>
- </itemizedlist>
- </para>
- <sect4><title>Implementing the X Video Extension for DMX</title>
- <para>
- The user-level API for X Video is fairly simple, but the
- underlying support required for the full specification
- is large. However, since the API provides a method to
- query supported capabilities, a usable subset of X
- Video can be implemented that would support XvPutImage
- and little else. This would require support for the
- following:
- <itemizedlist>
- <listitem><para>
- X Video Extension API calls, including the
- following:
- <itemizedlist>
- <listitem><para>XvQueryExtension</para></listitem>
- <listitem><para>XvQueryAdaptors</para></listitem>
- <listitem><para>XvQueryPortAttributes</para></listitem>
- <listitem><para>XvFreeAdaptorInfo</para></listitem>
- <listitem><para>XvListImageFormats</para></listitem>
- <listitem><para>XvGrabPort</para></listitem>
- <listitem><para>XvCreateImage</para></listitem>
- <listitem><para>XvPutImage</para></listitem>
- <listitem><para>XvShmCreateImage</para></listitem>
- <listitem><para>XvShmPutImage</para></listitem>
- </itemizedlist>
- </para></listitem>
- <listitem><para>
- Support for querying back-end X Video Extension
- capabilities.
- </para></listitem>
- <listitem><para>
- Support for sending the image to the back-ends.
- Because X Video requires sending full images, there
- may be a trade-off between bandwidth limitations and
- additional complexity to divide the image up such
- that is scales properly.
- </para></listitem>
- <listitem><para>
- Possible support for a software fall-back. For
- example, if all of the back-ends do not support the X
- Video Extension, software scaling can be implemented
- such that the image is sent to the back-end with
- XPutImage. This pathway would have poor
- performance.
- </para></listitem>
- </itemizedlist>
- </para>
- </sect4>
- <sect4><title>Supporting RGB formats for the X Video Extension</title>
- <para>
- Assuming an XFree86 driver already supports the X Video
- Extension, and assuming the target hardware supports an
- RGB format, then adding support for that format is
- relatively simple and straightforward.
- </para>
- </sect4>
- </sect3>
- <sect3><title>Scaling with an XPutImageScaled Extension</title>
- <para>
- Instead of (or in addition to) implementing the X Video
- Extension in DMX, one obvious solution would be to
- implement a new extension that provides access to
- hardware-assisted scaled blits, similar to the StretchBlt
- call available under Windows. This call would scale RGB
- images and would not use the overlay plane (unlike the X
- Video Extension).
- </para>
- <para>
- This approach has many of the same advantages and
- disadvantages as the XCopyAreaScaled Extension, discussed
- in the next section. Discussion of XPutImageScaled is
- deferred in favor of XCopyAreaScaled for the following
- reasons:
- <itemizedlist>
- <listitem><para>
- XPutImageScaled can be emulated with XCopyAreaScaled
- by first using XPutImage to copy the image to an
- off-screen pixmap, and then calling XCopyAreaScaled
- between that off-screen pixmap and the target
- drawable.
- </para></listitem>
- <listitem><para>
- Since XCopyAreaScaled would copy between two areas of
- on-screen or off-screen memory, it has additional uses
- and can be viewed as efficiently providing a superset
- of XPutImageScaled functionality.
- </para></listitem>
- </itemizedlist>
- </para>
- </sect3>
- <sect3><title>Scaling with an XCopyAreaScaled Extension</title>
- <para>
- As noted in the previous section, because XCopyAreaScaled
- provides a superset of the functionality provided by
- XPutImageScaled, we will consider this extension instead.
- </para>
- <para>
- First, XCopyAreaScaled would provide for RGB scaling
- between pixmaps (i.e., on-screen or off-screen areas of
- memory that reside on the video card). Unlike the X Video
- Extension, which writes into an overlay plane,
- XCopyAreaScaled would write into the non-overlay areas of
- the screen. Key points to consider are as follows:
- <itemizedlist>
- <listitem><para>
- Because different planes are involved, the two scaling
- operations are usually implemented in hardware
- differently, so an XCopyAreaScaled extension could be
- added in a manner that would neither conflict with nor
- interact with the X Video extension in any way.
- </para></listitem>
- <listitem><para>
- The XCopyAreaScaled extension provides new
- functionality that the X Video Extension does not
- provide. Based on anecdotal feedback, we believe that
- many people outside the DMX and VNC communities would
- be excited about this extension.
- </para></listitem>
- <listitem><para>
- The main drawback to this extension is that it is new
- and needs to be implemented at the driver level in
- XFree86 for each video card to be supported. At the
- present time, it is more likely that the X Video
- Extension will be implemented for a particular piece
- hardware because the X Video extension has multimedia
- uses. However, over time, we would expect the
- XCopyAreaScaled extension to be implemented along with
- the X Video extension, especially if it becomes
- popular.
- </para></listitem>
- <listitem><para>
- Another drawback is that not all modern cards provide
- support for a simple scaled blit operation. However,
- these cards usually do provide a 3D pipeline which
- could be used to provide this functionality in a
- manner that is transparent to the client application
- that is using the XCopyAreaScaled extension. However,
- this implementation pathway would make this extension
- somewhat more difficult to implement on certain cards.
- </para></listitem>
- </itemizedlist>
- </para>
- </sect3>
- <sect3><title>Scaling with OpenGL</title>
- <para>
- Another general solution to the scaling problem is to use
- the texture scaling found in all 3D hardware. This
- ability is already exposed through OpenGL and can be
- exploited by clients without X server modification (i.e.,
- other than the ability to support OpenGL). An application
- using OpenGL would transmit the non-scaled image to the X
- server as a texture, and would then display a single
- non-transformed rect using that texture. This also works
- around the single overlay problem with the X Video
- Extension as well as the need to implement additional
- scaled primitive extensions.
- </para>
- <para>
- The downside is that most OpenGL implementations require
- power of 2 texture sizes and this can be very wasteful of
- memory if, for example, the application needs to scale a
- 1025x1025 image, which would require a 2048x2048 texture
- area (even a 640x480 image would require a 1024x512
- texture). Another downside is that some OpenGL
- implementations have a limited about of texture memory and
- cannot handle textures that are very large. For example,
- they might limit the texture size to 1024x1024.
- </para>
- </sect3>
- </sect2>
- <sect2><title>Application-transparent Scaling for DMX
- </title><sect3><title>Back-end Scaling Without Disconnect/Reconnect</title>
- <para>
- VNC does scaling on the client side (in the
- <command>vncviewer</command> application). Implementing a similar
- solution for DMX would require support in the back-end X
- servers and, therefore, is not a general solution.
- </para>
- <para>
- XFree86 already implements some support for "scaling" that
- could be used with DMX: if, in the XF86Config file,
- multiple Modes are listed in the Display Subsection of the
- Screen Section, then pressing Ctrl-Alt-Plus and
- Ctrl-Alt-Minus can be used to iterate through the listed
- modes. The display dimensions will change to the
- dimensions in the Modes line, but the logical dimensions
- of the X server (i.e., the dimensions that Xdmx knows
- about) will not change.
- </para>
- <para>
- Further, the dimensions of the XFree86 display are under
- software control (via the XFree86-VidModeExtension), so
- the Xdmx server could change the screen dimensions on a
- per-display basis, thereby scaling the information on part
- of that display.
- </para>
- <para>
- However, this scaling appears to have limited use. For
- example, assume a 4 by 4 display wall consisting of 16
- 1280x1024 displays. If all of the back-end servers were
- simultaneously configured to display 640x480, the left
- hand corner of each display would be magnified, but the
- composite result would be unreadable. Magnifying one
- display at a time could be usable, but could have limited
- utility, since the result would still be no larger than a
- single display.
- </para>
- </sect3>
- <sect3><title>Back-end Scaling With Disconnect/Reconnect</title>
- <para>
- Disconnect and reconnect features are not currently
- supported in DMX, but are scheduled to be implemented in
- the future. These features, combined with the
- XFree86-VidModeExtension Extension, would allow an
- application to do the following:
- <itemizedlist>
- <listitem><para>
- Disconnect a specific back-end server (via the DMX
- Extension),
- </para></listitem>
- <listitem><para>
- reconfigure the XFree86 back-end server resolution,
- and
- </para></listitem>
- <listitem><para>
- reconnect the back-end server to DMX -- at a new
- origin with the new screen resolution.
- </para></listitem>
- </itemizedlist>
- </para>
- <para>
- For example, consider a display wall consisting of 16
- 1280x1024 displays with a total resolution of 5120x4096.
- All of the screens could be disconnected, repositioned,
- and reconnected each at a resolution of 640x480. The
- total resolution of the display wall would be 2560x1920,
- allowing a view of a selected area approximately
- one-fourth of the size of the DMX display. This change
- would be completely application independent (except,
- perhaps, for a DMX-aware window manager). When work at
- the increased resolution was completed, the back-end
- servers could be disconnected, reconfigured, and
- reconnected for the original 5120x4096 view.
- </para>
- <para>
- Support for this type of scaling can be implemented in a
- DMX-aware X11 client assuming the DMX server support
- arbitrary disconnect and reconnect semantics. Because
- this application cannot be written before
- disconnect/reconnect is implemented, this solution will
- not be discussed further in this paper.
- </para>
- </sect3>
- <sect3><title>Server-side Scaling</title>
- <para>
- In earlier versions of DMX, a frame buffer was maintained
- on the server side, and XPutImage was used to move the
- information from the server to the client (similar to some
- early VNC implementations). The use of a server-side
- frame buffer would allow the server to do scaling, but is
- not a recommended solution because of overall performance
- issues and server-side memory issues (i.e., the frame
- buffer would be very large for large display walls).
- </para>
- <para>
- Exploration of this path is not recommended.
- </para>
- </sect3>
- </sect2>
- <sect2><title>XCreateScaledWindow API</title>
- <para>
- The implementation of X Video Extension in DMX, and the use
- of XvPutImage by applications requiring scaling requires
- significant changes in DMX Further, XvPutImage is,
- essentially a scaled blit, and it is only useful for
- applications which are already using (or can be modified to
- use) XPutImage. Therefore, a more general API will be
- discussed as another possibility.
- </para>
- <para>
- X applications typically create windows with the
- XCreateWindow call. A new extension could provide an
- XCreateScaledWindow call that could be used in place of the
- XCreateWindow call and be otherwise transparent to the
- application. This would allow applications, even those that
- do not depend on XPutImage, to take advantage of window
- scaling. In this section we describe how the call would
- work, what transparency it provides, and how to solve the
- potential problems that transparency creates.
- </para>
- <sect3><title>XCreateWindow</title>
- <para>
- The XCreateWindow call takes width and height as
- parameters. An XCreateScaledWindow call could take all
- the same parameters, with the addition of a scaling factor.
- </para>
- </sect3>
- <sect3><title>XSetWindowAttributes</title>
- <para>
- An X11 window has several attributes that would have to be
- scaled:
- <itemizedlist>
- <listitem><para>Background and border pixmaps</para></listitem>
- <listitem><para>Border width</para></listitem>
- <listitem><para>Cursor</para></listitem>
- </itemizedlist>
- </para>
- </sect3>
- <sect3><title>XGetWindowAttributes, XGetGeometry</title>
- <para>
- For transparency, calls that query the window attributes
- should return unscaled information. This suggests that
- all unscaled pixmaps and window attributes should be
- cached.
- </para>
- <para>
- Unfortunately, a window manager requires the scaled
- geometry to properly decorate the window. The X server
- can probably determine which client is acting as the
- window manager (e.g., because that client will select
- events that are used exclusively by the window manager).
- However, other Scaled Window Extension aware clients may
- also need to determine the scaled geometry. Therefore, at
- least two additional extension calls should be
- implemented: XGetScaledWindowAttributes and
- XGetScaledGeometry.
- </para>
- </sect3>
- <sect3><title>Popup and Child window positions</title>
- <para>
- Some applications may position popup and child windows
- based on an unscaled notion of the main window geometry.
- In this case, additional modifications to the client would
- be required.
- </para>
- </sect3>
- <sect3><title>Events</title>
- <para>
- Most events (e.g., for mouse motion) return information
- about the coordinates at which the even occurred. These
- coordinates would have to be modified so that unscaled
- values were presented to the client.
- </para>
- </sect3>
- <sect3><title>Implementation</title>
- <para>
- There are many implementation issues, some of which are
- similar to the issues involved in implementing the X Video
- Extension for DMX. The window contents must be scaled,
- either by performing all operations to a frame buffer and
- then writing the image to the display (perhaps using
- hardware scaling support), or by modifying all of the
- various drawing operations to perform scaling. Because of
- the complexity involved, the frame buffer option is
- recommended.
- </para>
- </sect3>
- </sect2>
- </sect1>
-
- <sect1><title>Conclusion and Recommendations
- </title><para>
- We recommend a three phase implementation strategy, based on
- how an application could be written to take advantage of
- scaling:
- <orderedlist>
- <listitem>
- <para>
- The XCopyAreaScaled extension should be implemented, since
- this is the ideal solution for applications like VNC, and
- since making use of this extension will require minimal
- changes to applications that already use XPutImage or
- XCopyArea.
- </para>
- <para>
- The initial implementation work would include the design
- of the X protocol extension, writing this up in the
- usual format for extension documentation, implementation
- of the protocol transport pieces in XFree86,
- implementation of a software fall-back in XFree86 and
- DMX, one example hardware implementation for XFree86,
- and implementation of support for this extension in DMX.
- </para>
- <para>
- We suggest implementing the extension first on the ATI
- Radeon cards. However, since these cards do not provide
- a 2D scaled blit primitive, the implementation would
- have to make use of the 3D texture engine to emulate a
- scaled blit. This is recommended, since other modern
- graphics cards also do not provide a simple 2D scaled
- blit operation and an example of the more difficult
- implementation pathway would be helpful to others.
- </para>
- </listitem>
- <listitem>
- <para>
- Until XCopyAreaScaled is widely supported, applications
- that require scaling will have to fall back to another
- scaling method. We suggest OpenGL as the first fall-back
- method because it is widely available and supported by
- DMX.
- </para>
- <para>
- A project centered around OpenGL-based scaling would
- implement this scaling in VNC as an example. This work
- would include re-writing the <command>vncviewer</command>
- rendering engine to cache a master copy of the desktop
- image for all operations.
- </para>
- </listitem>
- <listitem>
- <para>
- Since OpenGL is not implemented everywhere, and may not
- provide hardware-assisted performance in every
- implementation, an application that requires scaling
- should also fall back to using the X Video Extension.
- </para>
- <para>
- This project would add support for the X Video Extension
- to DMX and would add support to VNC to take advantage of
- this extension without introducing artifacts. This
- would require modifying the <command>vncviewer</command> rendering
- engine to cache a master copy of the desktop image for
- all operations. This project should also add support
- for the RGB format to at least one XFree86 driver (e.g.,
- ATI Radeon).
- </para>
- <para>
- The X Video Extension is one of the few popular
- extensions that DMX does not support. We recommend
- implementing the X Video Extension even if scaling is
- the specific goal of that work.
- </para>
- </listitem>
- </orderedlist>
- </para>
- <para>
- We do <emphasis>not</emphasis> recommend implementation of the
- XCreateScaledWindow extension because of the complexity
- involved. We do <emphasis>not</emphasis> recommend implementation of the
- XPutImageScaled extension because it requires the same amount
- of work as the XCopyAreaScaled extension, but provides less
- functionality. Further, server-side scaling with a large
- frame buffer is <emphasis>not</emphasis> recommended because of the
- performance implications.
- </para>
- <para>
- The back-end scaling, especially with disconnect/reconnect
- support should be explored in the future after
- disconnect/reconnect is implemented, but not at the present
- time.
- </para>
- </sect1>
-
- </article>
- <!-- Local Variables: -->
- <!-- fill-column: 72 -->
- <!-- End: -->
+<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" + "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [ + <!ENTITY % defs SYSTEM "/xserver/doc/xml/xserver.ent"> %defs; +]> + <article> + + <articleinfo> + <!-- Title information --> + <title>Scaled Window Support in DMX</title> + <authorgroup> + <author><firstname>Kevin E.</firstname><surname>Martin</surname></author> + <author><firstname>Rickard E.</firstname><surname>Faith</surname></author> + </authorgroup> + <pubdate>15 October 2003 (created 19 September 2003)</pubdate> + <releaseinfo>X Server Version &xserver.version;</releaseinfo> + <abstract> + <para> + This document investigates the possibility of adding scaled window + support to the DMX X server, thereby allowing a window or some + selected part of the logical DMX area to be displayed using a + scaling factor. For example, this might allow the contents of a + window to be magnified for easier viewing. In particular, scaling + for the VNC client is explored. <emphasis remap="it">Copyright 2003 + by Red Hat, Inc., Raleigh, North Carolina</emphasis> + </para> + </abstract> + </articleinfo> + + <!-- Begin the document --> + <sect1><title>Introduction</title> + <sect2><title>DMX</title> + <para> + The DMX X server (Xdmx) is a proxy server that is designed + to allow X servers on multiple machines to be combined into + a single multi-headed X server. Combined with Xinerama, + these heads can appear as a single very high-resolution + screen. Typical applications include the creation of a + video wall with 16 1280x1024 displays arranged in a + rectangle, for a total resolution of of 5120x4096. + </para> + </sect2> + <sect2><title>Problem Statement</title> + <para> + Applications displayed on a physically large video wall that + provides high pixel-resolution may be difficult to see, + especially if the application is designed for use on a + typical desktop computer with a relatively small display + located close to the human operator. The goal of this paper + is to describe and discuss solutions to this problem. + </para> + <para> + The original driving problem for this work is to provide + scaling for the <command>vncviewer</command> application when + displayed using DMX (VNC scaling is currently available only + with the Windows client, and there is no plan to extend that + capability to other clients). While this specific problem + will be addressed in this paper, the general solution space + will also be explored, since this may lead to a good + solution not only for <command>vncviewer</command> but also for + other applications. + </para> + </sect2> + <sect2><title>Task</title> + <para> + For reference, here is the original description of the task + this paper addresses: + <itemizedlist> + <listitem><para>Scaled window support (for VNC) + <itemizedlist> + <listitem><para> + Investigate possibility of implementing a "scaled + window" extension: + <itemizedlist> + <listitem><para> + Add XCreateScaledWindow call that could be used + in place of XCreateWindow + </para></listitem> + <listitem><para> + All primitives drawn to scaled window would be + scaled by appropriate (integral?) scaling factor + </para></listitem> + </itemizedlist> + </para></listitem> + <listitem><para> + Alternate approach: special case VNC support + </para></listitem> + </itemizedlist> + </para></listitem> + </itemizedlist> + </para> + </sect2> + </sect1> + + <sect1><title>Previous Work</title> + <para> + This section reviews relevant previous work. + </para> + <sect2><title>VNC</title> + <sect3><title>Scaling under VNC</title> + <para> + When using the <command>vncviewer</command> program for Windows, it + is possible to specify a scaling factor (as numerator and + denominator). When scaling is in effect, the viewer + software uses StretchBlt (instead of BitBlt) to display + the pixels for the user. When this call is made, the + viewer already has received all of the pixel information + (at full unscaled resolution). + </para> + <para> + The scaling in VNC is primitive. It does not conserve + bandwidth, it does not treat textual information + differently (i.e., by using a suitably scaled font), and + it does not provide any anti-aliasing other than that + provided by the underlying (Windows-only) system library. + </para> + </sect3> + </sect2> + <sect2><title>The X Video Extension</title> + <para> + The X Video Extension is a widely-available extension to the + X11 protocol that provides support for streaming video. + Integral to this support is the ability to arbitrarily scale + the output. In version 2.2 of the X Video specification, + support for scaled still images was provided, using both + shared memory and traditional transport. The API for this + support uses calls that are quite similar to XCreateWindow, + XPutImage, and XShmPutImage. Currently, most of the drivers + implemented in XFree86 only support data in various YUV + formats. However, several modern video adaptors support RGB + as well. + </para> + <para> + Note, though, that the target output for this scaling is an + overlay plane -- so X Video provides functionality that is + fundamentally different from that provided by the Windows + StrechBlt call. + </para> + </sect2> + </sect1> + + <sect1><title>Possible Solutions</title> + <para> + This section briefly discusses possible solutions, including + major advantages and disadvantages from both the + implementation and the end-user programmer standpoint. + </para> + <sect2><title>VNC-like Scaling</title> + <sect3><title>Software Scaling</title> + <para> + The <command>vncviewer</command> application could be modified to + provide software scaling. This is not a general solution, + but it does solve one of the goals of this work. + </para> + <para> + A prototype of this solution was implemented and a patch + against <filename>vnc-3.3.7-unixsrc</filename> is available in the + <filename>dmx/external</filename> directory. Because of limited time + available for this work, all of the edge cases were not + considered and the solution works well mainly for integer + scaling. + </para> + <para> + Currently, <command>vncviewer</command> writes to the X display + with XPutImage, XCopyArea, and XFillRectangle. All + instances of these calls have to be aware of scaling + and must round correctly. In the prototype solution, + rounding is incorrect and can cause artifacts. + </para> + <para> + A better solution would be to cache all updates to the + desktop image in <command>vncviewer</command> and only send the + damaged area to the X display with XPutImage. This would + allow the damaged area to be computed so that rounding + errors do not create artifacts. This method is probably + similar to what is used in the Window client. (The whole + VNC suite is being re-written in C++ and the forthcoming + version 4 has not been evaluated.) + </para> + </sect3> + <sect3><title>Scaling with the X Video Extension</title> + <para> + The scaling in the Windows <command>vncviewer</command> application + makes use of a scaled blit that is supplied by the + underlying system library. Several video cards currently + provide support for a scaled blit, and some X servers + (including XFree86) expose this capability to applications + via the XvPutImage interface of the X Video Extension. + The capability exposed by XvPutImage results in the scaled + image being drawn to an overlay plane. Most video cards + also provide support for a scaled blit into the normal + output planes, but this is not exposed via XvPutImage. + </para> + <para> + The <command>vncviewer</command> program could be modified to use + the X Video Extension to provide scaling under X11 that is + similar to the scaling currently provided under Windows. + Unfortunately, Xdmx does not currently export the X Video + Extension, so this would not provide an immediate solution + usable with DMX. + </para> + <para> + A very early-stage proof-of-concept prototype was + implemented and a preliminary patch against + <filename>vnc-3.3.7-unixsrc</filename> is available in the + <filename>dmx/external</filename> directory. This prototype was + implemented to better understand the problems that must be + solved to make this solution viable: + <itemizedlist> + <listitem><para> + As noted under the software scaling section above, + <command>vncviewer</command> writes to the X display with + several different calls. These calls write to the + normal output planes and are compatible with + XvPutImage, which writes to an overlay plane. To + eliminate artifacts caused by this problem, + <command>vncviewer</command> should be modified so that a cached + copy of the desktop is available, either as a + client-side image or a server-side off-screen pixmap, + so that XvPutImage would be the only method for + writing to the X display. + </para></listitem> + <listitem> + <para> + Although several modern graphics adaptors support + hardware scaling using an RGB format (e.g., ATI + Radeon, nVidia, etc.), XFree86 drivers typically + only implement YUV formats. YUV generally compress + the pixel information in some way. For example, two + commonly implemented formats, YUY2 and UYVY provide + intensity information for every RGB pixel, but only + provide chroma and luminance information for pairs + of horizontal pixels. Since VNC uses + pixel-resolution for communicating updates on the + wire, additional artifacts are introduced (because + there may not be enough information from the wire to + update a pair of pixels). + </para> + <para> + Further, the well-known problem with YUV encoding + is even more evident when the image is a desktop + instead of a movie. For example, consider a + 1-pixel-wide vertical window border. If the border + changes in color but not intensity (e.g., because a + window manager uses color to indicate focus), there + may or may not be a change in the YUY2 image, + depending on the algorithm used for RGB to YUV + conversion and on how the border pixel is ordered in + the pair of pixels used by the algorithm. + </para> + <para> + Many of these artifacts could be eliminated if + <command>vncviewer</command> cached a complete RGB image of + the desktop, and only did the conversion to YUV for + properly aligned areas of damage. The remaining artifacts + could be eliminated if an RGB format was used with X + Video (which may require the extension of existing + XFree86 drivers to support RGB). + </para> + </listitem> + <listitem><para> + Most modern video cards support exactly one overlay + plane that is suitable for use with X Video. + Therefore, only one application can use X Video at any + given time. This is a severe limitation in a desktop + environment. + </para></listitem> + </itemizedlist> + </para> + <sect4><title>Implementing the X Video Extension for DMX</title> + <para> + The user-level API for X Video is fairly simple, but the + underlying support required for the full specification + is large. However, since the API provides a method to + query supported capabilities, a usable subset of X + Video can be implemented that would support XvPutImage + and little else. This would require support for the + following: + <itemizedlist> + <listitem><para> + X Video Extension API calls, including the + following: + <itemizedlist> + <listitem><para>XvQueryExtension</para></listitem> + <listitem><para>XvQueryAdaptors</para></listitem> + <listitem><para>XvQueryPortAttributes</para></listitem> + <listitem><para>XvFreeAdaptorInfo</para></listitem> + <listitem><para>XvListImageFormats</para></listitem> + <listitem><para>XvGrabPort</para></listitem> + <listitem><para>XvCreateImage</para></listitem> + <listitem><para>XvPutImage</para></listitem> + <listitem><para>XvShmCreateImage</para></listitem> + <listitem><para>XvShmPutImage</para></listitem> + </itemizedlist> + </para></listitem> + <listitem><para> + Support for querying back-end X Video Extension + capabilities. + </para></listitem> + <listitem><para> + Support for sending the image to the back-ends. + Because X Video requires sending full images, there + may be a trade-off between bandwidth limitations and + additional complexity to divide the image up such + that is scales properly. + </para></listitem> + <listitem><para> + Possible support for a software fall-back. For + example, if all of the back-ends do not support the X + Video Extension, software scaling can be implemented + such that the image is sent to the back-end with + XPutImage. This pathway would have poor + performance. + </para></listitem> + </itemizedlist> + </para> + </sect4> + <sect4><title>Supporting RGB formats for the X Video Extension</title> + <para> + Assuming an XFree86 driver already supports the X Video + Extension, and assuming the target hardware supports an + RGB format, then adding support for that format is + relatively simple and straightforward. + </para> + </sect4> + </sect3> + <sect3><title>Scaling with an XPutImageScaled Extension</title> + <para> + Instead of (or in addition to) implementing the X Video + Extension in DMX, one obvious solution would be to + implement a new extension that provides access to + hardware-assisted scaled blits, similar to the StretchBlt + call available under Windows. This call would scale RGB + images and would not use the overlay plane (unlike the X + Video Extension). + </para> + <para> + This approach has many of the same advantages and + disadvantages as the XCopyAreaScaled Extension, discussed + in the next section. Discussion of XPutImageScaled is + deferred in favor of XCopyAreaScaled for the following + reasons: + <itemizedlist> + <listitem><para> + XPutImageScaled can be emulated with XCopyAreaScaled + by first using XPutImage to copy the image to an + off-screen pixmap, and then calling XCopyAreaScaled + between that off-screen pixmap and the target + drawable. + </para></listitem> + <listitem><para> + Since XCopyAreaScaled would copy between two areas of + on-screen or off-screen memory, it has additional uses + and can be viewed as efficiently providing a superset + of XPutImageScaled functionality. + </para></listitem> + </itemizedlist> + </para> + </sect3> + <sect3><title>Scaling with an XCopyAreaScaled Extension</title> + <para> + As noted in the previous section, because XCopyAreaScaled + provides a superset of the functionality provided by + XPutImageScaled, we will consider this extension instead. + </para> + <para> + First, XCopyAreaScaled would provide for RGB scaling + between pixmaps (i.e., on-screen or off-screen areas of + memory that reside on the video card). Unlike the X Video + Extension, which writes into an overlay plane, + XCopyAreaScaled would write into the non-overlay areas of + the screen. Key points to consider are as follows: + <itemizedlist> + <listitem><para> + Because different planes are involved, the two scaling + operations are usually implemented in hardware + differently, so an XCopyAreaScaled extension could be + added in a manner that would neither conflict with nor + interact with the X Video extension in any way. + </para></listitem> + <listitem><para> + The XCopyAreaScaled extension provides new + functionality that the X Video Extension does not + provide. Based on anecdotal feedback, we believe that + many people outside the DMX and VNC communities would + be excited about this extension. + </para></listitem> + <listitem><para> + The main drawback to this extension is that it is new + and needs to be implemented at the driver level in + XFree86 for each video card to be supported. At the + present time, it is more likely that the X Video + Extension will be implemented for a particular piece + hardware because the X Video extension has multimedia + uses. However, over time, we would expect the + XCopyAreaScaled extension to be implemented along with + the X Video extension, especially if it becomes + popular. + </para></listitem> + <listitem><para> + Another drawback is that not all modern cards provide + support for a simple scaled blit operation. However, + these cards usually do provide a 3D pipeline which + could be used to provide this functionality in a + manner that is transparent to the client application + that is using the XCopyAreaScaled extension. However, + this implementation pathway would make this extension + somewhat more difficult to implement on certain cards. + </para></listitem> + </itemizedlist> + </para> + </sect3> + <sect3><title>Scaling with OpenGL</title> + <para> + Another general solution to the scaling problem is to use + the texture scaling found in all 3D hardware. This + ability is already exposed through OpenGL and can be + exploited by clients without X server modification (i.e., + other than the ability to support OpenGL). An application + using OpenGL would transmit the non-scaled image to the X + server as a texture, and would then display a single + non-transformed rect using that texture. This also works + around the single overlay problem with the X Video + Extension as well as the need to implement additional + scaled primitive extensions. + </para> + <para> + The downside is that most OpenGL implementations require + power of 2 texture sizes and this can be very wasteful of + memory if, for example, the application needs to scale a + 1025x1025 image, which would require a 2048x2048 texture + area (even a 640x480 image would require a 1024x512 + texture). Another downside is that some OpenGL + implementations have a limited about of texture memory and + cannot handle textures that are very large. For example, + they might limit the texture size to 1024x1024. + </para> + </sect3> + </sect2> + <sect2><title>Application-transparent Scaling for DMX + </title><sect3><title>Back-end Scaling Without Disconnect/Reconnect</title> + <para> + VNC does scaling on the client side (in the + <command>vncviewer</command> application). Implementing a similar + solution for DMX would require support in the back-end X + servers and, therefore, is not a general solution. + </para> + <para> + XFree86 already implements some support for "scaling" that + could be used with DMX: if, in the XF86Config file, + multiple Modes are listed in the Display Subsection of the + Screen Section, then pressing Ctrl-Alt-Plus and + Ctrl-Alt-Minus can be used to iterate through the listed + modes. The display dimensions will change to the + dimensions in the Modes line, but the logical dimensions + of the X server (i.e., the dimensions that Xdmx knows + about) will not change. + </para> + <para> + Further, the dimensions of the XFree86 display are under + software control (via the XFree86-VidModeExtension), so + the Xdmx server could change the screen dimensions on a + per-display basis, thereby scaling the information on part + of that display. + </para> + <para> + However, this scaling appears to have limited use. For + example, assume a 4 by 4 display wall consisting of 16 + 1280x1024 displays. If all of the back-end servers were + simultaneously configured to display 640x480, the left + hand corner of each display would be magnified, but the + composite result would be unreadable. Magnifying one + display at a time could be usable, but could have limited + utility, since the result would still be no larger than a + single display. + </para> + </sect3> + <sect3><title>Back-end Scaling With Disconnect/Reconnect</title> + <para> + Disconnect and reconnect features are not currently + supported in DMX, but are scheduled to be implemented in + the future. These features, combined with the + XFree86-VidModeExtension Extension, would allow an + application to do the following: + <itemizedlist> + <listitem><para> + Disconnect a specific back-end server (via the DMX + Extension), + </para></listitem> + <listitem><para> + reconfigure the XFree86 back-end server resolution, + and + </para></listitem> + <listitem><para> + reconnect the back-end server to DMX -- at a new + origin with the new screen resolution. + </para></listitem> + </itemizedlist> + </para> + <para> + For example, consider a display wall consisting of 16 + 1280x1024 displays with a total resolution of 5120x4096. + All of the screens could be disconnected, repositioned, + and reconnected each at a resolution of 640x480. The + total resolution of the display wall would be 2560x1920, + allowing a view of a selected area approximately + one-fourth of the size of the DMX display. This change + would be completely application independent (except, + perhaps, for a DMX-aware window manager). When work at + the increased resolution was completed, the back-end + servers could be disconnected, reconfigured, and + reconnected for the original 5120x4096 view. + </para> + <para> + Support for this type of scaling can be implemented in a + DMX-aware X11 client assuming the DMX server support + arbitrary disconnect and reconnect semantics. Because + this application cannot be written before + disconnect/reconnect is implemented, this solution will + not be discussed further in this paper. + </para> + </sect3> + <sect3><title>Server-side Scaling</title> + <para> + In earlier versions of DMX, a frame buffer was maintained + on the server side, and XPutImage was used to move the + information from the server to the client (similar to some + early VNC implementations). The use of a server-side + frame buffer would allow the server to do scaling, but is + not a recommended solution because of overall performance + issues and server-side memory issues (i.e., the frame + buffer would be very large for large display walls). + </para> + <para> + Exploration of this path is not recommended. + </para> + </sect3> + </sect2> + <sect2><title>XCreateScaledWindow API</title> + <para> + The implementation of X Video Extension in DMX, and the use + of XvPutImage by applications requiring scaling requires + significant changes in DMX Further, XvPutImage is, + essentially a scaled blit, and it is only useful for + applications which are already using (or can be modified to + use) XPutImage. Therefore, a more general API will be + discussed as another possibility. + </para> + <para> + X applications typically create windows with the + XCreateWindow call. A new extension could provide an + XCreateScaledWindow call that could be used in place of the + XCreateWindow call and be otherwise transparent to the + application. This would allow applications, even those that + do not depend on XPutImage, to take advantage of window + scaling. In this section we describe how the call would + work, what transparency it provides, and how to solve the + potential problems that transparency creates. + </para> + <sect3><title>XCreateWindow</title> + <para> + The XCreateWindow call takes width and height as + parameters. An XCreateScaledWindow call could take all + the same parameters, with the addition of a scaling factor. + </para> + </sect3> + <sect3><title>XSetWindowAttributes</title> + <para> + An X11 window has several attributes that would have to be + scaled: + <itemizedlist> + <listitem><para>Background and border pixmaps</para></listitem> + <listitem><para>Border width</para></listitem> + <listitem><para>Cursor</para></listitem> + </itemizedlist> + </para> + </sect3> + <sect3><title>XGetWindowAttributes, XGetGeometry</title> + <para> + For transparency, calls that query the window attributes + should return unscaled information. This suggests that + all unscaled pixmaps and window attributes should be + cached. + </para> + <para> + Unfortunately, a window manager requires the scaled + geometry to properly decorate the window. The X server + can probably determine which client is acting as the + window manager (e.g., because that client will select + events that are used exclusively by the window manager). + However, other Scaled Window Extension aware clients may + also need to determine the scaled geometry. Therefore, at + least two additional extension calls should be + implemented: XGetScaledWindowAttributes and + XGetScaledGeometry. + </para> + </sect3> + <sect3><title>Popup and Child window positions</title> + <para> + Some applications may position popup and child windows + based on an unscaled notion of the main window geometry. + In this case, additional modifications to the client would + be required. + </para> + </sect3> + <sect3><title>Events</title> + <para> + Most events (e.g., for mouse motion) return information + about the coordinates at which the even occurred. These + coordinates would have to be modified so that unscaled + values were presented to the client. + </para> + </sect3> + <sect3><title>Implementation</title> + <para> + There are many implementation issues, some of which are + similar to the issues involved in implementing the X Video + Extension for DMX. The window contents must be scaled, + either by performing all operations to a frame buffer and + then writing the image to the display (perhaps using + hardware scaling support), or by modifying all of the + various drawing operations to perform scaling. Because of + the complexity involved, the frame buffer option is + recommended. + </para> + </sect3> + </sect2> + </sect1> + + <sect1><title>Conclusion and Recommendations + </title><para> + We recommend a three phase implementation strategy, based on + how an application could be written to take advantage of + scaling: + <orderedlist> + <listitem> + <para> + The XCopyAreaScaled extension should be implemented, since + this is the ideal solution for applications like VNC, and + since making use of this extension will require minimal + changes to applications that already use XPutImage or + XCopyArea. + </para> + <para> + The initial implementation work would include the design + of the X protocol extension, writing this up in the + usual format for extension documentation, implementation + of the protocol transport pieces in XFree86, + implementation of a software fall-back in XFree86 and + DMX, one example hardware implementation for XFree86, + and implementation of support for this extension in DMX. + </para> + <para> + We suggest implementing the extension first on the ATI + Radeon cards. However, since these cards do not provide + a 2D scaled blit primitive, the implementation would + have to make use of the 3D texture engine to emulate a + scaled blit. This is recommended, since other modern + graphics cards also do not provide a simple 2D scaled + blit operation and an example of the more difficult + implementation pathway would be helpful to others. + </para> + </listitem> + <listitem> + <para> + Until XCopyAreaScaled is widely supported, applications + that require scaling will have to fall back to another + scaling method. We suggest OpenGL as the first fall-back + method because it is widely available and supported by + DMX. + </para> + <para> + A project centered around OpenGL-based scaling would + implement this scaling in VNC as an example. This work + would include re-writing the <command>vncviewer</command> + rendering engine to cache a master copy of the desktop + image for all operations. + </para> + </listitem> + <listitem> + <para> + Since OpenGL is not implemented everywhere, and may not + provide hardware-assisted performance in every + implementation, an application that requires scaling + should also fall back to using the X Video Extension. + </para> + <para> + This project would add support for the X Video Extension + to DMX and would add support to VNC to take advantage of + this extension without introducing artifacts. This + would require modifying the <command>vncviewer</command> rendering + engine to cache a master copy of the desktop image for + all operations. This project should also add support + for the RGB format to at least one XFree86 driver (e.g., + ATI Radeon). + </para> + <para> + The X Video Extension is one of the few popular + extensions that DMX does not support. We recommend + implementing the X Video Extension even if scaling is + the specific goal of that work. + </para> + </listitem> + </orderedlist> + </para> + <para> + We do <emphasis>not</emphasis> recommend implementation of the + XCreateScaledWindow extension because of the complexity + involved. We do <emphasis>not</emphasis> recommend implementation of the + XPutImageScaled extension because it requires the same amount + of work as the XCopyAreaScaled extension, but provides less + functionality. Further, server-side scaling with a large + frame buffer is <emphasis>not</emphasis> recommended because of the + performance implications. + </para> + <para> + The back-end scaling, especially with disconnect/reconnect + support should be explored in the future after + disconnect/reconnect is implemented, but not at the present + time. + </para> + </sect1> + + </article> + <!-- Local Variables: --> + <!-- fill-column: 72 --> + <!-- End: --> diff --git a/xorg-server/hw/dmx/examples/ev.c b/xorg-server/hw/dmx/examples/ev.c index ba45c2b25..ed23b8aa9 100644 --- a/xorg-server/hw/dmx/examples/ev.c +++ b/xorg-server/hw/dmx/examples/ev.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) #define test_bit(bit) (mask[(bit)/8] & (1 << ((bit)%8))) for (i = 0; i < 32; i++) { - sprintf(name, "/dev/input/event%d", i); + snprintf(name, sizeof(name), "/dev/input/event%d", i); if ((fd = open(name, O_RDONLY, 0)) >= 0) { ioctl(fd, EVIOCGVERSION, &version); ioctl(fd, EVIOCGNAME(sizeof(buf)), buf); @@ -92,7 +92,7 @@ int main(int argc, char **argv) } if (argc > 1) { - sprintf(name, "/dev/input/event%d", atoi(argv[1])); + snprintf(name, sizeof(name), "/dev/input/event%d", atoi(argv[1])); if ((fd = open(name, O_RDWR, 0)) >= 0) { printf("%s: open, fd = %d\n", name, fd); for (i = 0; i < LED_MAX; i++) { diff --git a/xorg-server/hw/dmx/glxProxy/compsize.c b/xorg-server/hw/dmx/glxProxy/compsize.c index 3bb562e05..5a5d5d0f1 100644 --- a/xorg-server/hw/dmx/glxProxy/compsize.c +++ b/xorg-server/hw/dmx/glxProxy/compsize.c @@ -1,558 +1,559 @@ -/*
- * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
- * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice including the dates of first publication and
- * either this permission notice or a reference to
- * http://oss.sgi.com/projects/FreeB/
- * shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Except as contained in this notice, the name of Silicon Graphics, Inc.
- * shall not be used in advertising or otherwise to promote the sale, use or
- * other dealings in this Software without prior written authorization from
- * Silicon Graphics, Inc.
- */
-
-#include <GL/gl.h>
-
-GLint __glFogiv_size(GLenum pname)
-{
- switch (pname) {
- case GL_FOG_COLOR: return 4;
- case GL_FOG_DENSITY: return 1;
- case GL_FOG_END: return 1;
- case GL_FOG_MODE: return 1;
- case GL_FOG_INDEX: return 1;
- case GL_FOG_START: return 1;
- default:
- return 0;
- }
-}
-
-GLint __glFogfv_size(GLenum pname)
-{
- return __glFogiv_size(pname);
-}
-
-GLint __glCallLists_size(GLsizei n, GLenum type)
-{
- GLint size;
-
- if (n < 0) return 0;
- switch (type) {
- case GL_BYTE: size = 1; break;
- case GL_UNSIGNED_BYTE: size = 1; break;
- case GL_SHORT: size = 2; break;
- case GL_UNSIGNED_SHORT: size = 2; break;
- case GL_INT: size = 4; break;
- case GL_UNSIGNED_INT: size = 4; break;
- case GL_FLOAT: size = 4; break;
- case GL_2_BYTES: size = 2; break;
- case GL_3_BYTES: size = 3; break;
- case GL_4_BYTES: size = 4; break;
- default:
- return 0;
- }
- return n * size;
-}
-
-GLint __glDrawPixels_size(GLenum format, GLenum type, GLsizei w, GLsizei h)
-{
- GLint elements, esize;
-
- switch (format) {
- case GL_COLOR_INDEX:
- case GL_STENCIL_INDEX:
- case GL_DEPTH_COMPONENT:
- elements = 1;
- break;
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- elements = 1;
- break;
- case GL_LUMINANCE_ALPHA:
- elements = 2;
- break;
- case GL_RGB:
- elements = 3;
- break;
- case GL_RGBA:
- case GL_ABGR_EXT:
- elements = 4;
- break;
- default:
- return 0;
- }
- switch (type) {
- case GL_BITMAP:
- if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) {
- return (h * ((w+7)/8));
- } else {
- return 0;
- }
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- esize = 1;
- break;
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- esize = 1;
- elements = 1;
- break;
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- esize = 2;
- break;
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- esize = 2;
- elements = 1;
- break;
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- esize = 4;
- break;
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- esize = 4;
- elements = 1;
- break;
- default:
- return 0;
- }
- return elements * esize * w * h;
-}
-
-GLint __glBitmap_size(GLsizei w, GLsizei h)
-{
- return __glDrawPixels_size(GL_COLOR_INDEX, GL_BITMAP, w, h);
-}
-
-GLint __glTexGendv_size(GLenum e)
-{
- switch (e) {
- case GL_TEXTURE_GEN_MODE:
- return 1;
- case GL_OBJECT_PLANE:
- case GL_EYE_PLANE:
- return 4;
- default:
- return 0;
- }
-}
-
-GLint __glTexGenfv_size(GLenum e)
-{
- return __glTexGendv_size(e);
-}
-
-GLint __glTexGeniv_size(GLenum e)
-{
- return __glTexGendv_size(e);
-}
-
-GLint __glTexParameterfv_size(GLenum e)
-{
- switch (e) {
- case GL_TEXTURE_WRAP_S:
- case GL_TEXTURE_WRAP_T:
- case GL_TEXTURE_WRAP_R:
- case GL_TEXTURE_MIN_FILTER:
- case GL_TEXTURE_MAG_FILTER:
- return 1;
- case GL_TEXTURE_BORDER_COLOR:
- return 4;
- case GL_TEXTURE_PRIORITY:
- return 1;
- case GL_TEXTURE_MIN_LOD:
- case GL_TEXTURE_MAX_LOD:
- case GL_TEXTURE_BASE_LEVEL:
- case GL_TEXTURE_MAX_LEVEL:
- return 1;
- default:
- return 0;
- }
-}
-
-GLint __glTexParameteriv_size(GLenum e)
-{
- return __glTexParameterfv_size(e);
-}
-
-GLint __glTexEnvfv_size(GLenum e)
-{
- switch (e) {
- case GL_TEXTURE_ENV_MODE:
- return 1;
- case GL_TEXTURE_ENV_COLOR:
- return 4;
- default:
- return 0;
- }
-}
-
-GLint __glTexEnviv_size(GLenum e)
-{
- return __glTexEnvfv_size(e);
-}
-
-GLint __glTexImage1D_size(GLenum format, GLenum type, GLsizei w)
-{
- GLint elements, esize;
-
- if (w < 0) return 0;
- switch (format) {
- case GL_COLOR_INDEX:
- elements = 1;
- break;
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- elements = 1;
- break;
- case GL_LUMINANCE_ALPHA:
- elements = 2;
- break;
- case GL_RGB:
- elements = 3;
- break;
- case GL_RGBA:
- case GL_ABGR_EXT:
- elements = 4;
- break;
- default:
- return 0;
- }
- switch (type) {
- case GL_BITMAP:
- if (format == GL_COLOR_INDEX) {
- return (w+7)/8;
- } else {
- return 0;
- }
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- esize = 1;
- break;
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- esize = 1;
- elements = 1;
- break;
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- esize = 2;
- break;
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- esize = 2;
- elements = 1;
- break;
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- esize = 4;
- break;
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- esize = 4;
- elements = 1;
- break;
- default:
- return 0;
- }
- return elements * esize * w;
-}
-
-GLint __glTexImage2D_size(GLenum format, GLenum type, GLsizei w, GLsizei h)
-{
- GLint elements, esize;
-
- if (w < 0) return 0;
- if (h < 0) return 0;
- switch (format) {
- case GL_COLOR_INDEX:
- elements = 1;
- break;
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- elements = 1;
- break;
- case GL_LUMINANCE_ALPHA:
- elements = 2;
- break;
- case GL_RGB:
- elements = 3;
- break;
- case GL_RGBA:
- case GL_ABGR_EXT:
- elements = 4;
- break;
- default:
- return 0;
- }
- switch (type) {
- case GL_BITMAP:
- if (format == GL_COLOR_INDEX) {
- return (h * ((w+7)/8));
- } else {
- return 0;
- }
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- esize = 1;
- break;
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- esize = 1;
- elements = 1;
- break;
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- esize = 2;
- break;
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- esize = 2;
- elements = 1;
- break;
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- esize = 4;
- break;
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- esize = 4;
- elements = 1;
- break;
- default:
- return 0;
- }
- return elements * esize * w * h;
-}
-
-GLint __glTexImage3D_size(GLenum format, GLenum type, GLsizei w, GLsizei h,
- GLsizei d)
-{
- GLint elements, esize;
-
- if (w < 0) return 0;
- if (h < 0) return 0;
- if (d < 0) return 0;
- switch (format) {
- case GL_COLOR_INDEX:
- elements = 1;
- break;
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- elements = 1;
- break;
- case GL_LUMINANCE_ALPHA:
- elements = 2;
- break;
- case GL_RGB:
- elements = 3;
- break;
- case GL_RGBA:
- case GL_ABGR_EXT:
- elements = 4;
- break;
- default:
- return 0;
- }
- switch (type) {
- case GL_BITMAP:
- if (format == GL_COLOR_INDEX) {
- return (d * (h * ((w+7)/8)));
- } else {
- return 0;
- }
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- esize = 1;
- break;
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- esize = 1;
- elements = 1;
- break;
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- esize = 2;
- break;
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- esize = 2;
- elements = 1;
- break;
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- esize = 4;
- break;
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- esize = 4;
- elements = 1;
- break;
- default:
- return 0;
- }
- return elements * esize * w * h * d;
-}
-
-GLint __glLightfv_size(GLenum pname)
-{
- switch (pname) {
- case GL_SPOT_EXPONENT: return 1;
- case GL_SPOT_CUTOFF: return 1;
- case GL_AMBIENT: return 4;
- case GL_DIFFUSE: return 4;
- case GL_SPECULAR: return 4;
- case GL_POSITION: return 4;
- case GL_SPOT_DIRECTION: return 3;
- case GL_CONSTANT_ATTENUATION: return 1;
- case GL_LINEAR_ATTENUATION: return 1;
- case GL_QUADRATIC_ATTENUATION: return 1;
- default:
- return 0;
- }
-}
-
-GLint __glLightiv_size(GLenum pname)
-{
- return __glLightfv_size(pname);
-}
-
-GLint __glLightModelfv_size(GLenum pname)
-{
- switch (pname) {
- case GL_LIGHT_MODEL_AMBIENT: return 4;
- case GL_LIGHT_MODEL_LOCAL_VIEWER: return 1;
- case GL_LIGHT_MODEL_TWO_SIDE: return 1;
- case GL_LIGHT_MODEL_COLOR_CONTROL: return 1;
- default:
- return 0;
- }
-}
-
-GLint __glLightModeliv_size(GLenum pname)
-{
- return __glLightModelfv_size(pname);
-}
-
-GLint __glMaterialfv_size(GLenum pname)
-{
- switch (pname) {
- case GL_SHININESS: return 1;
- case GL_EMISSION: return 4;
- case GL_AMBIENT: return 4;
- case GL_DIFFUSE: return 4;
- case GL_SPECULAR: return 4;
- case GL_AMBIENT_AND_DIFFUSE: return 4;
- case GL_COLOR_INDEXES: return 3;
- default:
- return 0;
- }
-}
-
-GLint __glMaterialiv_size(GLenum pname)
-{
- return __glMaterialfv_size(pname);
-}
-
-GLint __glColorTableParameterfv_size(GLenum pname)
-{
- switch (pname) {
- case GL_COLOR_TABLE_FORMAT:
- case GL_COLOR_TABLE_WIDTH:
- case GL_COLOR_TABLE_RED_SIZE:
- case GL_COLOR_TABLE_GREEN_SIZE:
- case GL_COLOR_TABLE_BLUE_SIZE:
- case GL_COLOR_TABLE_ALPHA_SIZE:
- case GL_COLOR_TABLE_LUMINANCE_SIZE:
- case GL_COLOR_TABLE_INTENSITY_SIZE:
- return 1;
- case GL_COLOR_TABLE_SCALE:
- case GL_COLOR_TABLE_BIAS:
- return 4;
- default:
- return -1;
- }
-}
-
-GLint __glColorTableParameteriv_size(GLenum pname)
-{
- return __glColorTableParameterfv_size(pname);
-}
-
-GLint __glConvolutionParameterfv_size(GLenum pname)
-{
- switch(pname) {
- case GL_CONVOLUTION_BORDER_MODE:
- return 1;
- case GL_CONVOLUTION_BORDER_COLOR:
- case GL_CONVOLUTION_FILTER_SCALE:
- case GL_CONVOLUTION_FILTER_BIAS:
- return 4;
- default: /* error: bad enum value */
- return -1;
- }
-}
-
-GLint __glConvolutionParameteriv_size(GLenum pname)
-{
- return __glConvolutionParameterfv_size(pname);
-}
+/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include <GL/gl.h> +#include "compsize.h" + +GLint __glFogiv_size(GLenum pname) +{ + switch (pname) { + case GL_FOG_COLOR: return 4; + case GL_FOG_DENSITY: return 1; + case GL_FOG_END: return 1; + case GL_FOG_MODE: return 1; + case GL_FOG_INDEX: return 1; + case GL_FOG_START: return 1; + default: + return 0; + } +} + +GLint __glFogfv_size(GLenum pname) +{ + return __glFogiv_size(pname); +} + +GLint __glCallLists_size(GLsizei n, GLenum type) +{ + GLint size; + + if (n < 0) return 0; + switch (type) { + case GL_BYTE: size = 1; break; + case GL_UNSIGNED_BYTE: size = 1; break; + case GL_SHORT: size = 2; break; + case GL_UNSIGNED_SHORT: size = 2; break; + case GL_INT: size = 4; break; + case GL_UNSIGNED_INT: size = 4; break; + case GL_FLOAT: size = 4; break; + case GL_2_BYTES: size = 2; break; + case GL_3_BYTES: size = 3; break; + case GL_4_BYTES: size = 4; break; + default: + return 0; + } + return n * size; +} + +GLint __glDrawPixels_size(GLenum format, GLenum type, GLsizei w, GLsizei h) +{ + GLint elements, esize; + + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + elements = 3; + break; + case GL_RGBA: + case GL_ABGR_EXT: + elements = 4; + break; + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) { + return (h * ((w+7)/8)); + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return elements * esize * w * h; +} + +GLint __glBitmap_size(GLsizei w, GLsizei h) +{ + return __glDrawPixels_size(GL_COLOR_INDEX, GL_BITMAP, w, h); +} + +GLint __glTexGendv_size(GLenum e) +{ + switch (e) { + case GL_TEXTURE_GEN_MODE: + return 1; + case GL_OBJECT_PLANE: + case GL_EYE_PLANE: + return 4; + default: + return 0; + } +} + +GLint __glTexGenfv_size(GLenum e) +{ + return __glTexGendv_size(e); +} + +GLint __glTexGeniv_size(GLenum e) +{ + return __glTexGendv_size(e); +} + +GLint __glTexParameterfv_size(GLenum e) +{ + switch (e) { + case GL_TEXTURE_WRAP_S: + case GL_TEXTURE_WRAP_T: + case GL_TEXTURE_WRAP_R: + case GL_TEXTURE_MIN_FILTER: + case GL_TEXTURE_MAG_FILTER: + return 1; + case GL_TEXTURE_BORDER_COLOR: + return 4; + case GL_TEXTURE_PRIORITY: + return 1; + case GL_TEXTURE_MIN_LOD: + case GL_TEXTURE_MAX_LOD: + case GL_TEXTURE_BASE_LEVEL: + case GL_TEXTURE_MAX_LEVEL: + return 1; + default: + return 0; + } +} + +GLint __glTexParameteriv_size(GLenum e) +{ + return __glTexParameterfv_size(e); +} + +GLint __glTexEnvfv_size(GLenum e) +{ + switch (e) { + case GL_TEXTURE_ENV_MODE: + return 1; + case GL_TEXTURE_ENV_COLOR: + return 4; + default: + return 0; + } +} + +GLint __glTexEnviv_size(GLenum e) +{ + return __glTexEnvfv_size(e); +} + +GLint __glTexImage1D_size(GLenum format, GLenum type, GLsizei w) +{ + GLint elements, esize; + + if (w < 0) return 0; + switch (format) { + case GL_COLOR_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + elements = 3; + break; + case GL_RGBA: + case GL_ABGR_EXT: + elements = 4; + break; + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX) { + return (w+7)/8; + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return elements * esize * w; +} + +GLint __glTexImage2D_size(GLenum format, GLenum type, GLsizei w, GLsizei h) +{ + GLint elements, esize; + + if (w < 0) return 0; + if (h < 0) return 0; + switch (format) { + case GL_COLOR_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + elements = 3; + break; + case GL_RGBA: + case GL_ABGR_EXT: + elements = 4; + break; + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX) { + return (h * ((w+7)/8)); + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return elements * esize * w * h; +} + +GLint __glTexImage3D_size(GLenum format, GLenum type, GLsizei w, GLsizei h, + GLsizei d) +{ + GLint elements, esize; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_COLOR_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + elements = 3; + break; + case GL_RGBA: + case GL_ABGR_EXT: + elements = 4; + break; + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX) { + return (d * (h * ((w+7)/8))); + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return elements * esize * w * h * d; +} + +GLint __glLightfv_size(GLenum pname) +{ + switch (pname) { + case GL_SPOT_EXPONENT: return 1; + case GL_SPOT_CUTOFF: return 1; + case GL_AMBIENT: return 4; + case GL_DIFFUSE: return 4; + case GL_SPECULAR: return 4; + case GL_POSITION: return 4; + case GL_SPOT_DIRECTION: return 3; + case GL_CONSTANT_ATTENUATION: return 1; + case GL_LINEAR_ATTENUATION: return 1; + case GL_QUADRATIC_ATTENUATION: return 1; + default: + return 0; + } +} + +GLint __glLightiv_size(GLenum pname) +{ + return __glLightfv_size(pname); +} + +GLint __glLightModelfv_size(GLenum pname) +{ + switch (pname) { + case GL_LIGHT_MODEL_AMBIENT: return 4; + case GL_LIGHT_MODEL_LOCAL_VIEWER: return 1; + case GL_LIGHT_MODEL_TWO_SIDE: return 1; + case GL_LIGHT_MODEL_COLOR_CONTROL: return 1; + default: + return 0; + } +} + +GLint __glLightModeliv_size(GLenum pname) +{ + return __glLightModelfv_size(pname); +} + +GLint __glMaterialfv_size(GLenum pname) +{ + switch (pname) { + case GL_SHININESS: return 1; + case GL_EMISSION: return 4; + case GL_AMBIENT: return 4; + case GL_DIFFUSE: return 4; + case GL_SPECULAR: return 4; + case GL_AMBIENT_AND_DIFFUSE: return 4; + case GL_COLOR_INDEXES: return 3; + default: + return 0; + } +} + +GLint __glMaterialiv_size(GLenum pname) +{ + return __glMaterialfv_size(pname); +} + +GLint __glColorTableParameterfv_size(GLenum pname) +{ + switch (pname) { + case GL_COLOR_TABLE_FORMAT: + case GL_COLOR_TABLE_WIDTH: + case GL_COLOR_TABLE_RED_SIZE: + case GL_COLOR_TABLE_GREEN_SIZE: + case GL_COLOR_TABLE_BLUE_SIZE: + case GL_COLOR_TABLE_ALPHA_SIZE: + case GL_COLOR_TABLE_LUMINANCE_SIZE: + case GL_COLOR_TABLE_INTENSITY_SIZE: + return 1; + case GL_COLOR_TABLE_SCALE: + case GL_COLOR_TABLE_BIAS: + return 4; + default: + return -1; + } +} + +GLint __glColorTableParameteriv_size(GLenum pname) +{ + return __glColorTableParameterfv_size(pname); +} + +GLint __glConvolutionParameterfv_size(GLenum pname) +{ + switch(pname) { + case GL_CONVOLUTION_BORDER_MODE: + return 1; + case GL_CONVOLUTION_BORDER_COLOR: + case GL_CONVOLUTION_FILTER_SCALE: + case GL_CONVOLUTION_FILTER_BIAS: + return 4; + default: /* error: bad enum value */ + return -1; + } +} + +GLint __glConvolutionParameteriv_size(GLenum pname) +{ + return __glConvolutionParameterfv_size(pname); +} diff --git a/xorg-server/hw/dmx/glxProxy/compsize.h b/xorg-server/hw/dmx/glxProxy/compsize.h new file mode 100644 index 000000000..856c6f5ad --- /dev/null +++ b/xorg-server/hw/dmx/glxProxy/compsize.h @@ -0,0 +1,51 @@ +/* + * Copyright 2011 Apple Inc. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef __compsize_h__ +#define __compsize_h__ + +extern GLint __glColorTableParameterfv_size(GLenum pname); +extern GLint __glColorTableParameteriv_size(GLenum pname); +extern GLint __glConvolutionParameterfv_size(GLenum pname); +extern GLint __glConvolutionParameteriv_size(GLenum pname); +extern GLint __glFogfv_size(GLenum pname); +extern GLint __glFogiv_size(GLenum pname); +extern GLint __glLightModelfv_size(GLenum pname); +extern GLint __glLightModeliv_size(GLenum pname); +extern GLint __glLightfv_size(GLenum pname); +extern GLint __glLightiv_size(GLenum pname); +extern GLint __glMaterialfv_size(GLenum pname); +extern GLint __glMaterialiv_size(GLenum pname); +extern GLint __glTexEnvfv_size(GLenum e); +extern GLint __glTexEnviv_size(GLenum e); +extern GLint __glTexGendv_size(GLenum e); +extern GLint __glTexGenfv_size(GLenum e); +extern GLint __glTexGeniv_size(GLenum e); +extern GLint __glTexParameterfv_size(GLenum e); +extern GLint __glTexParameteriv_size(GLenum e); + +#endif /* !__compsize_h__ */ diff --git a/xorg-server/hw/dmx/glxProxy/g_renderswap.c b/xorg-server/hw/dmx/glxProxy/g_renderswap.c index 39316a99b..e434a71b6 100644 --- a/xorg-server/hw/dmx/glxProxy/g_renderswap.c +++ b/xorg-server/hw/dmx/glxProxy/g_renderswap.c @@ -1,2433 +1,2434 @@ -/*
- * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
- * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice including the dates of first publication and
- * either this permission notice or a reference to
- * http://oss.sgi.com/projects/FreeB/
- * shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Except as contained in this notice, the name of Silicon Graphics, Inc.
- * shall not be used in advertising or otherwise to promote the sale, use or
- * other dealings in this Software without prior written authorization from
- * Silicon Graphics, Inc.
- */
-
-#include "glxserver.h"
-#include "glxext.h"
-#include "g_disptab.h"
-#include "unpack.h"
-
-void __glXDispSwap_CallList(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_ListBase(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_Begin(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_Color3bv(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_Color3dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 24);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Color3fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
-}
-
-void __glXDispSwap_Color3iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Color3sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Color3ubv(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_Color3uiv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 3);
-}
-
-void __glXDispSwap_Color3usv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
-}
-
-void __glXDispSwap_Color4bv(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_Color4dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 32);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4);
-}
-
-void __glXDispSwap_Color4fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Color4iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Color4sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Color4ubv(GLbyte *pc)
-{
-
-}
-
-void __glXDispSwap_Color4uiv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Color4usv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_EdgeFlagv(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_End(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_Indexdv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 8);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_Indexfv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_Indexiv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_Indexsv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_Normal3bv(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_Normal3dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 24);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Normal3fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Normal3iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Normal3sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_RasterPos2dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 16);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_RasterPos2fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_RasterPos2iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_RasterPos2sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_RasterPos3dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 24);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_RasterPos3fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_RasterPos3iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_RasterPos3sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_RasterPos4dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 32);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_RasterPos4fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_RasterPos4iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_RasterPos4sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Rectdv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 32);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2);
- __GLX_SWAP_DOUBLE_ARRAY(pc + 16, 2);
-
-}
-
-void __glXDispSwap_Rectfv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, 2);
-
-}
-
-void __glXDispSwap_Rectiv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 2);
- __GLX_SWAP_INT_ARRAY(pc + 8, 2);
-
-}
-
-void __glXDispSwap_Rectsv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 2);
- __GLX_SWAP_SHORT_ARRAY(pc + 4, 2);
-
-}
-
-void __glXDispSwap_TexCoord1dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 8);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_TexCoord1fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_TexCoord1iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_TexCoord1sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_TexCoord2dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 16);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_TexCoord2fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_TexCoord2iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_TexCoord2sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_TexCoord3dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 24);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_TexCoord3fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_TexCoord3iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_TexCoord3sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_TexCoord4dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 32);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_TexCoord4fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_TexCoord4iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_TexCoord4sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Vertex2dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 16);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_Vertex2fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_Vertex2iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_Vertex2sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_Vertex3dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 24);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Vertex3fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Vertex3iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Vertex3sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_Vertex4dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 32);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Vertex4fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Vertex4iv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_Vertex4sv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_ClipPlane(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 36);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 32);
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_ColorMaterial(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_CullFace(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_Fogf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
-
-}
-
-void __glXDispSwap_Fogfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- pname = *(GLenum *)(pc + 0);
- compsize = __glFogfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_FLOAT_ARRAY(pc + 4, compsize);
-
-}
-
-void __glXDispSwap_Fogi(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_Fogiv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- pname = *(GLenum *)(pc + 0);
- compsize = __glFogiv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT_ARRAY(pc + 4, compsize);
-
-}
-
-void __glXDispSwap_FrontFace(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_Hint(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_Lightf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_Lightfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glLightfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_Lighti(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_Lightiv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glLightiv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_LightModelf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
-
-}
-
-void __glXDispSwap_LightModelfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- pname = *(GLenum *)(pc + 0);
- compsize = __glLightModelfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_FLOAT_ARRAY(pc + 4, compsize);
-
-}
-
-void __glXDispSwap_LightModeli(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_LightModeliv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- pname = *(GLenum *)(pc + 0);
- compsize = __glLightModeliv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT_ARRAY(pc + 4, compsize);
-
-}
-
-void __glXDispSwap_LineStipple(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_SHORT(pc + 4);
-
-}
-
-void __glXDispSwap_LineWidth(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
-
-}
-
-void __glXDispSwap_Materialf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_Materialfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glMaterialfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_Materiali(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_Materialiv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glMaterialiv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_PointSize(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
-
-}
-
-void __glXDispSwap_PolygonMode(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_Scissor(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
-
-}
-
-void __glXDispSwap_ShadeModel(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_TexParameterf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_TexParameterfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glTexParameterfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_TexParameteri(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_TexParameteriv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glTexParameteriv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_TexEnvf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_TexEnvfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glTexEnvfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_TexEnvi(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_TexEnviv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glTexEnviv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_TexGend(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 16);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_DOUBLE(pc + 0);
-
-}
-
-void __glXDispSwap_TexGendv(GLbyte *pc)
-{
- GLenum pname;
- GLint cmdlen;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glTexGendv_size(pname);
- if (compsize < 0) compsize = 0;
- cmdlen = __GLX_PAD(8+compsize*8);
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, cmdlen);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_DOUBLE_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_TexGenf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_TexGenfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glTexGenfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_TexGeni(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_TexGeniv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glTexGeniv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_InitNames(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_LoadName(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_PassThrough(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
-
-}
-
-void __glXDispSwap_PopName(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_PushName(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_DrawBuffer(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_Clear(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_ClearAccum(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
- __GLX_SWAP_FLOAT(pc + 12);
-
-}
-
-void __glXDispSwap_ClearIndex(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
-
-}
-
-void __glXDispSwap_ClearColor(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
- __GLX_SWAP_FLOAT(pc + 12);
-
-}
-
-void __glXDispSwap_ClearStencil(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_ClearDepth(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 8);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE(pc + 0);
-
-}
-
-void __glXDispSwap_StencilMask(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_ColorMask(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_DepthMask(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_IndexMask(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_Accum(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
-
-}
-
-void __glXDispSwap_Disable(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_Enable(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_PopAttrib(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_PushAttrib(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_MapGrid1d(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 20);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 16);
- __GLX_SWAP_DOUBLE(pc + 0);
- __GLX_SWAP_DOUBLE(pc + 8);
-
-}
-
-void __glXDispSwap_MapGrid1f(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_MapGrid2d(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 40);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 32);
- __GLX_SWAP_DOUBLE(pc + 0);
- __GLX_SWAP_DOUBLE(pc + 8);
- __GLX_SWAP_INT(pc + 36);
- __GLX_SWAP_DOUBLE(pc + 16);
- __GLX_SWAP_DOUBLE(pc + 24);
-
-}
-
-void __glXDispSwap_MapGrid2f(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_FLOAT(pc + 16);
- __GLX_SWAP_FLOAT(pc + 20);
-
-}
-
-void __glXDispSwap_EvalCoord1dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 8);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_EvalCoord1fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_EvalCoord2dv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 16);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_EvalCoord2fv(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_EvalMesh1(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_EvalPoint1(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_EvalMesh2(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
-
-}
-
-void __glXDispSwap_EvalPoint2(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_AlphaFunc(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
-
-}
-
-void __glXDispSwap_BlendFunc(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_LogicOp(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_StencilFunc(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_StencilOp(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_DepthFunc(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_PixelZoom(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
-
-}
-
-void __glXDispSwap_PixelTransferf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
-
-}
-
-void __glXDispSwap_PixelTransferi(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_PixelMapfv(GLbyte *pc)
-{
- GLint mapsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- mapsize = *(GLint *)(pc + 4);
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, mapsize);
-
-}
-
-void __glXDispSwap_PixelMapuiv(GLbyte *pc)
-{
- GLint mapsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- mapsize = *(GLint *)(pc + 4);
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 8, mapsize);
-
-}
-
-void __glXDispSwap_PixelMapusv(GLbyte *pc)
-{
- GLint mapsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- mapsize = *(GLint *)(pc + 4);
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_SHORT_ARRAY(pc + 8, mapsize);
-
-}
-
-void __glXDispSwap_ReadBuffer(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_CopyPixels(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
-
-}
-
-void __glXDispSwap_DepthRange(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 16);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE(pc + 0);
- __GLX_SWAP_DOUBLE(pc + 8);
-
-}
-
-void __glXDispSwap_Frustum(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 48);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE(pc + 0);
- __GLX_SWAP_DOUBLE(pc + 8);
- __GLX_SWAP_DOUBLE(pc + 16);
- __GLX_SWAP_DOUBLE(pc + 24);
- __GLX_SWAP_DOUBLE(pc + 32);
- __GLX_SWAP_DOUBLE(pc + 40);
-
-}
-
-void __glXDispSwap_LoadIdentity(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_LoadMatrixf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 16);
-
-}
-
-void __glXDispSwap_LoadMatrixd(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 128);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 16);
-
-}
-
-void __glXDispSwap_MatrixMode(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_MultMatrixf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_FLOAT_ARRAY(pc + 0, 16);
-
-}
-
-void __glXDispSwap_MultMatrixd(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 128);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 16);
-
-}
-
-void __glXDispSwap_Ortho(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 48);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE(pc + 0);
- __GLX_SWAP_DOUBLE(pc + 8);
- __GLX_SWAP_DOUBLE(pc + 16);
- __GLX_SWAP_DOUBLE(pc + 24);
- __GLX_SWAP_DOUBLE(pc + 32);
- __GLX_SWAP_DOUBLE(pc + 40);
-
-}
-
-void __glXDispSwap_PopMatrix(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_PushMatrix(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_Rotated(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 32);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE(pc + 0);
- __GLX_SWAP_DOUBLE(pc + 8);
- __GLX_SWAP_DOUBLE(pc + 16);
- __GLX_SWAP_DOUBLE(pc + 24);
-
-}
-
-void __glXDispSwap_Rotatef(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
- __GLX_SWAP_FLOAT(pc + 12);
-
-}
-
-void __glXDispSwap_Scaled(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 24);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE(pc + 0);
- __GLX_SWAP_DOUBLE(pc + 8);
- __GLX_SWAP_DOUBLE(pc + 16);
-
-}
-
-void __glXDispSwap_Scalef(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_Translated(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 24);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_DOUBLE(pc + 0);
- __GLX_SWAP_DOUBLE(pc + 8);
- __GLX_SWAP_DOUBLE(pc + 16);
-
-}
-
-void __glXDispSwap_Translatef(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_Viewport(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
-
-}
-
-void __glXDispSwap_PolygonOffset(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
-
-}
-
-void __glXDispSwap_CopyTexImage1D(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
- __GLX_SWAP_INT(pc + 20);
- __GLX_SWAP_INT(pc + 24);
-
-}
-
-void __glXDispSwap_CopyTexImage2D(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
- __GLX_SWAP_INT(pc + 20);
- __GLX_SWAP_INT(pc + 24);
- __GLX_SWAP_INT(pc + 28);
-
-}
-
-void __glXDispSwap_CopyTexSubImage1D(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
- __GLX_SWAP_INT(pc + 20);
-
-}
-
-void __glXDispSwap_CopyTexSubImage2D(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
- __GLX_SWAP_INT(pc + 20);
- __GLX_SWAP_INT(pc + 24);
- __GLX_SWAP_INT(pc + 28);
-
-}
-
-void __glXDispSwap_BindTexture(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_PrioritizeTextures(GLbyte *pc)
-{
- GLsizei n;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- n = *(GLsizei *)(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 4, n);
- __GLX_SWAP_FLOAT_ARRAY(pc + 4+n*4, n);
-
-}
-
-void __glXDispSwap_Indexubv(GLbyte *pc)
-{
-}
-
-void __glXDispSwap_BlendColor(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_FLOAT(pc + 0);
- __GLX_SWAP_FLOAT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
- __GLX_SWAP_FLOAT(pc + 12);
-
-}
-
-void __glXDispSwap_BlendEquation(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_ColorTableParameterfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glColorTableParameterfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_ColorTableParameteriv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glColorTableParameteriv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_CopyColorTable(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
-
-}
-
-void __glXDispSwap_CopyColorSubTable(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
-
-}
-
-void __glXDispSwap_ConvolutionParameterf(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_FLOAT(pc + 8);
-
-}
-
-void __glXDispSwap_ConvolutionParameterfv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glConvolutionParameterfv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_ConvolutionParameteri(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_ConvolutionParameteriv(GLbyte *pc)
-{
- GLenum pname;
- GLint compsize;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 4);
- pname = *(GLenum *)(pc + 4);
- compsize = __glConvolutionParameteriv_size(pname);
- if (compsize < 0) compsize = 0;
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 8, compsize);
-
-}
-
-void __glXDispSwap_CopyConvolutionFilter1D(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
-
-}
-
-void __glXDispSwap_CopyConvolutionFilter2D(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
- __GLX_SWAP_INT(pc + 20);
-
-}
-
-void __glXDispSwap_Histogram(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
-
-}
-
-void __glXDispSwap_Minmax(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
-
-}
-
-void __glXDispSwap_ResetHistogram(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_ResetMinmax(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_CopyTexSubImage3D(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT(pc + 4);
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_INT(pc + 12);
- __GLX_SWAP_INT(pc + 16);
- __GLX_SWAP_INT(pc + 20);
- __GLX_SWAP_INT(pc + 24);
- __GLX_SWAP_INT(pc + 28);
- __GLX_SWAP_INT(pc + 32);
-
-}
-
-void __glXDispSwap_ActiveTextureARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
-
-}
-
-void __glXDispSwap_MultiTexCoord1dvARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 12);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 8);
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 1);
-
-}
-
-void __glXDispSwap_MultiTexCoord1fvARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 4, 1);
-
-}
-
-void __glXDispSwap_MultiTexCoord1ivARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 4, 1);
-
-}
-
-void __glXDispSwap_MultiTexCoord1svARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_SHORT_ARRAY(pc + 4, 1);
-
-}
-
-void __glXDispSwap_MultiTexCoord2dvARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 20);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 16);
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2);
-
-}
-
-void __glXDispSwap_MultiTexCoord2fvARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 4, 2);
-
-}
-
-void __glXDispSwap_MultiTexCoord2ivARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 4, 2);
-
-}
-
-void __glXDispSwap_MultiTexCoord2svARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_SHORT_ARRAY(pc + 4, 2);
-
-}
-
-void __glXDispSwap_MultiTexCoord3dvARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 28);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 24);
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3);
-
-}
-
-void __glXDispSwap_MultiTexCoord3fvARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 4, 3);
-
-}
-
-void __glXDispSwap_MultiTexCoord3ivARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 4, 3);
-
-}
-
-void __glXDispSwap_MultiTexCoord3svARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_SHORT_ARRAY(pc + 4, 3);
-
-}
-
-void __glXDispSwap_MultiTexCoord4dvARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
-
-#ifdef __GLX_ALIGN64
- if ((unsigned long)(pc) & 7) {
- __GLX_MEM_COPY(pc-4, pc, 36);
- pc -= 4;
- }
-#endif
- __GLX_SWAP_INT(pc + 32);
- __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4);
-
-}
-
-void __glXDispSwap_MultiTexCoord4fvARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_FLOAT_ARRAY(pc + 4, 4);
-
-}
-
-void __glXDispSwap_MultiTexCoord4ivARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_INT_ARRAY(pc + 4, 4);
-
-}
-
-void __glXDispSwap_MultiTexCoord4svARB(GLbyte *pc)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(pc + 0);
- __GLX_SWAP_SHORT_ARRAY(pc + 4, 4);
-
-}
-
+/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "glxserver.h" +#include "glxext.h" +#include "g_disptab.h" +#include "unpack.h" +#include "compsize.h" + +void __glXDispSwap_CallList(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_ListBase(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_Begin(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_Color3bv(GLbyte *pc) +{ +} + +void __glXDispSwap_Color3dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 24); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Color3fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3); +} + +void __glXDispSwap_Color3iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Color3sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Color3ubv(GLbyte *pc) +{ +} + +void __glXDispSwap_Color3uiv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 3); +} + +void __glXDispSwap_Color3usv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 3); +} + +void __glXDispSwap_Color4bv(GLbyte *pc) +{ +} + +void __glXDispSwap_Color4dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 32); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4); +} + +void __glXDispSwap_Color4fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Color4iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Color4sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Color4ubv(GLbyte *pc) +{ + +} + +void __glXDispSwap_Color4uiv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Color4usv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_EdgeFlagv(GLbyte *pc) +{ +} + +void __glXDispSwap_End(GLbyte *pc) +{ +} + +void __glXDispSwap_Indexdv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 8); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_Indexfv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_Indexiv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_Indexsv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_Normal3bv(GLbyte *pc) +{ +} + +void __glXDispSwap_Normal3dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 24); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Normal3fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Normal3iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Normal3sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_RasterPos2dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 16); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_RasterPos2fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_RasterPos2iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_RasterPos2sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_RasterPos3dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 24); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_RasterPos3fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_RasterPos3iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_RasterPos3sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_RasterPos4dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 32); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_RasterPos4fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_RasterPos4iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_RasterPos4sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Rectdv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 32); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2); + __GLX_SWAP_DOUBLE_ARRAY(pc + 16, 2); + +} + +void __glXDispSwap_Rectfv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, 2); + +} + +void __glXDispSwap_Rectiv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 2); + __GLX_SWAP_INT_ARRAY(pc + 8, 2); + +} + +void __glXDispSwap_Rectsv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 2); + __GLX_SWAP_SHORT_ARRAY(pc + 4, 2); + +} + +void __glXDispSwap_TexCoord1dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 8); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_TexCoord1fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_TexCoord1iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_TexCoord1sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_TexCoord2dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 16); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_TexCoord2fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_TexCoord2iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_TexCoord2sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_TexCoord3dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 24); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_TexCoord3fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_TexCoord3iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_TexCoord3sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_TexCoord4dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 32); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_TexCoord4fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_TexCoord4iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_TexCoord4sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Vertex2dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 16); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_Vertex2fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_Vertex2iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_Vertex2sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_Vertex3dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 24); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Vertex3fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Vertex3iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Vertex3sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_Vertex4dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 32); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Vertex4fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Vertex4iv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_Vertex4sv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_ClipPlane(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 36); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 32); + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_ColorMaterial(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_CullFace(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_Fogf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + +} + +void __glXDispSwap_Fogfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + pname = *(GLenum *)(pc + 0); + compsize = __glFogfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_FLOAT_ARRAY(pc + 4, compsize); + +} + +void __glXDispSwap_Fogi(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_Fogiv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + pname = *(GLenum *)(pc + 0); + compsize = __glFogiv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT_ARRAY(pc + 4, compsize); + +} + +void __glXDispSwap_FrontFace(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_Hint(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_Lightf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_Lightfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glLightfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_Lighti(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_Lightiv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glLightiv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_LightModelf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + +} + +void __glXDispSwap_LightModelfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + pname = *(GLenum *)(pc + 0); + compsize = __glLightModelfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_FLOAT_ARRAY(pc + 4, compsize); + +} + +void __glXDispSwap_LightModeli(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_LightModeliv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + pname = *(GLenum *)(pc + 0); + compsize = __glLightModeliv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT_ARRAY(pc + 4, compsize); + +} + +void __glXDispSwap_LineStipple(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_SHORT(pc + 4); + +} + +void __glXDispSwap_LineWidth(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + +} + +void __glXDispSwap_Materialf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_Materialfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glMaterialfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_Materiali(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_Materialiv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glMaterialiv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_PointSize(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + +} + +void __glXDispSwap_PolygonMode(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_Scissor(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + +} + +void __glXDispSwap_ShadeModel(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_TexParameterf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_TexParameterfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glTexParameterfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_TexParameteri(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_TexParameteriv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glTexParameteriv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_TexEnvf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_TexEnvfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glTexEnvfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_TexEnvi(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_TexEnviv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glTexEnviv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_TexGend(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 16); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_DOUBLE(pc + 0); + +} + +void __glXDispSwap_TexGendv(GLbyte *pc) +{ + GLenum pname; + GLint cmdlen; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glTexGendv_size(pname); + if (compsize < 0) compsize = 0; + cmdlen = __GLX_PAD(8+compsize*8); + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, cmdlen); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_DOUBLE_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_TexGenf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_TexGenfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glTexGenfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_TexGeni(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_TexGeniv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glTexGeniv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_InitNames(GLbyte *pc) +{ +} + +void __glXDispSwap_LoadName(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_PassThrough(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + +} + +void __glXDispSwap_PopName(GLbyte *pc) +{ +} + +void __glXDispSwap_PushName(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_DrawBuffer(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_Clear(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_ClearAccum(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + __GLX_SWAP_FLOAT(pc + 12); + +} + +void __glXDispSwap_ClearIndex(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + +} + +void __glXDispSwap_ClearColor(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + __GLX_SWAP_FLOAT(pc + 12); + +} + +void __glXDispSwap_ClearStencil(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_ClearDepth(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 8); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE(pc + 0); + +} + +void __glXDispSwap_StencilMask(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_ColorMask(GLbyte *pc) +{ +} + +void __glXDispSwap_DepthMask(GLbyte *pc) +{ +} + +void __glXDispSwap_IndexMask(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_Accum(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + +} + +void __glXDispSwap_Disable(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_Enable(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_PopAttrib(GLbyte *pc) +{ +} + +void __glXDispSwap_PushAttrib(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_MapGrid1d(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 20); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 16); + __GLX_SWAP_DOUBLE(pc + 0); + __GLX_SWAP_DOUBLE(pc + 8); + +} + +void __glXDispSwap_MapGrid1f(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_MapGrid2d(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 40); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 32); + __GLX_SWAP_DOUBLE(pc + 0); + __GLX_SWAP_DOUBLE(pc + 8); + __GLX_SWAP_INT(pc + 36); + __GLX_SWAP_DOUBLE(pc + 16); + __GLX_SWAP_DOUBLE(pc + 24); + +} + +void __glXDispSwap_MapGrid2f(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_FLOAT(pc + 16); + __GLX_SWAP_FLOAT(pc + 20); + +} + +void __glXDispSwap_EvalCoord1dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 8); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_EvalCoord1fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_EvalCoord2dv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 16); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_EvalCoord2fv(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_EvalMesh1(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_EvalPoint1(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_EvalMesh2(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + +} + +void __glXDispSwap_EvalPoint2(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_AlphaFunc(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + +} + +void __glXDispSwap_BlendFunc(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_LogicOp(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_StencilFunc(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_StencilOp(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_DepthFunc(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_PixelZoom(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + +} + +void __glXDispSwap_PixelTransferf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + +} + +void __glXDispSwap_PixelTransferi(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_PixelMapfv(GLbyte *pc) +{ + GLint mapsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + mapsize = *(GLint *)(pc + 4); + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, mapsize); + +} + +void __glXDispSwap_PixelMapuiv(GLbyte *pc) +{ + GLint mapsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + mapsize = *(GLint *)(pc + 4); + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 8, mapsize); + +} + +void __glXDispSwap_PixelMapusv(GLbyte *pc) +{ + GLint mapsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + mapsize = *(GLint *)(pc + 4); + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_SHORT_ARRAY(pc + 8, mapsize); + +} + +void __glXDispSwap_ReadBuffer(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_CopyPixels(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + +} + +void __glXDispSwap_DepthRange(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 16); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE(pc + 0); + __GLX_SWAP_DOUBLE(pc + 8); + +} + +void __glXDispSwap_Frustum(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 48); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE(pc + 0); + __GLX_SWAP_DOUBLE(pc + 8); + __GLX_SWAP_DOUBLE(pc + 16); + __GLX_SWAP_DOUBLE(pc + 24); + __GLX_SWAP_DOUBLE(pc + 32); + __GLX_SWAP_DOUBLE(pc + 40); + +} + +void __glXDispSwap_LoadIdentity(GLbyte *pc) +{ +} + +void __glXDispSwap_LoadMatrixf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 16); + +} + +void __glXDispSwap_LoadMatrixd(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 128); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 16); + +} + +void __glXDispSwap_MatrixMode(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_MultMatrixf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_FLOAT_ARRAY(pc + 0, 16); + +} + +void __glXDispSwap_MultMatrixd(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 128); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 16); + +} + +void __glXDispSwap_Ortho(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 48); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE(pc + 0); + __GLX_SWAP_DOUBLE(pc + 8); + __GLX_SWAP_DOUBLE(pc + 16); + __GLX_SWAP_DOUBLE(pc + 24); + __GLX_SWAP_DOUBLE(pc + 32); + __GLX_SWAP_DOUBLE(pc + 40); + +} + +void __glXDispSwap_PopMatrix(GLbyte *pc) +{ +} + +void __glXDispSwap_PushMatrix(GLbyte *pc) +{ +} + +void __glXDispSwap_Rotated(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 32); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE(pc + 0); + __GLX_SWAP_DOUBLE(pc + 8); + __GLX_SWAP_DOUBLE(pc + 16); + __GLX_SWAP_DOUBLE(pc + 24); + +} + +void __glXDispSwap_Rotatef(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + __GLX_SWAP_FLOAT(pc + 12); + +} + +void __glXDispSwap_Scaled(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 24); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE(pc + 0); + __GLX_SWAP_DOUBLE(pc + 8); + __GLX_SWAP_DOUBLE(pc + 16); + +} + +void __glXDispSwap_Scalef(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_Translated(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 24); + pc -= 4; + } +#endif + __GLX_SWAP_DOUBLE(pc + 0); + __GLX_SWAP_DOUBLE(pc + 8); + __GLX_SWAP_DOUBLE(pc + 16); + +} + +void __glXDispSwap_Translatef(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_Viewport(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + +} + +void __glXDispSwap_PolygonOffset(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + +} + +void __glXDispSwap_CopyTexImage1D(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + __GLX_SWAP_INT(pc + 20); + __GLX_SWAP_INT(pc + 24); + +} + +void __glXDispSwap_CopyTexImage2D(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + __GLX_SWAP_INT(pc + 20); + __GLX_SWAP_INT(pc + 24); + __GLX_SWAP_INT(pc + 28); + +} + +void __glXDispSwap_CopyTexSubImage1D(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + __GLX_SWAP_INT(pc + 20); + +} + +void __glXDispSwap_CopyTexSubImage2D(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + __GLX_SWAP_INT(pc + 20); + __GLX_SWAP_INT(pc + 24); + __GLX_SWAP_INT(pc + 28); + +} + +void __glXDispSwap_BindTexture(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_PrioritizeTextures(GLbyte *pc) +{ + GLsizei n; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + n = *(GLsizei *)(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 4, n); + __GLX_SWAP_FLOAT_ARRAY(pc + 4+n*4, n); + +} + +void __glXDispSwap_Indexubv(GLbyte *pc) +{ +} + +void __glXDispSwap_BlendColor(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_FLOAT(pc + 0); + __GLX_SWAP_FLOAT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + __GLX_SWAP_FLOAT(pc + 12); + +} + +void __glXDispSwap_BlendEquation(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_ColorTableParameterfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glColorTableParameterfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_ColorTableParameteriv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glColorTableParameteriv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_CopyColorTable(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + +} + +void __glXDispSwap_CopyColorSubTable(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + +} + +void __glXDispSwap_ConvolutionParameterf(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_FLOAT(pc + 8); + +} + +void __glXDispSwap_ConvolutionParameterfv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glConvolutionParameterfv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_ConvolutionParameteri(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_ConvolutionParameteriv(GLbyte *pc) +{ + GLenum pname; + GLint compsize; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 4); + pname = *(GLenum *)(pc + 4); + compsize = __glConvolutionParameteriv_size(pname); + if (compsize < 0) compsize = 0; + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 8, compsize); + +} + +void __glXDispSwap_CopyConvolutionFilter1D(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + +} + +void __glXDispSwap_CopyConvolutionFilter2D(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + __GLX_SWAP_INT(pc + 20); + +} + +void __glXDispSwap_Histogram(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + +} + +void __glXDispSwap_Minmax(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + +} + +void __glXDispSwap_ResetHistogram(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_ResetMinmax(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_CopyTexSubImage3D(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT(pc + 4); + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_INT(pc + 12); + __GLX_SWAP_INT(pc + 16); + __GLX_SWAP_INT(pc + 20); + __GLX_SWAP_INT(pc + 24); + __GLX_SWAP_INT(pc + 28); + __GLX_SWAP_INT(pc + 32); + +} + +void __glXDispSwap_ActiveTextureARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + +} + +void __glXDispSwap_MultiTexCoord1dvARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 12); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 8); + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 1); + +} + +void __glXDispSwap_MultiTexCoord1fvARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 4, 1); + +} + +void __glXDispSwap_MultiTexCoord1ivARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 4, 1); + +} + +void __glXDispSwap_MultiTexCoord1svARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_SHORT_ARRAY(pc + 4, 1); + +} + +void __glXDispSwap_MultiTexCoord2dvARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 20); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 16); + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 2); + +} + +void __glXDispSwap_MultiTexCoord2fvARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 4, 2); + +} + +void __glXDispSwap_MultiTexCoord2ivARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 4, 2); + +} + +void __glXDispSwap_MultiTexCoord2svARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_SHORT_ARRAY(pc + 4, 2); + +} + +void __glXDispSwap_MultiTexCoord3dvARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 28); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 24); + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 3); + +} + +void __glXDispSwap_MultiTexCoord3fvARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 4, 3); + +} + +void __glXDispSwap_MultiTexCoord3ivARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 4, 3); + +} + +void __glXDispSwap_MultiTexCoord3svARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_SHORT_ARRAY(pc + 4, 3); + +} + +void __glXDispSwap_MultiTexCoord4dvARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + +#ifdef __GLX_ALIGN64 + if ((unsigned long)(pc) & 7) { + __GLX_MEM_COPY(pc-4, pc, 36); + pc -= 4; + } +#endif + __GLX_SWAP_INT(pc + 32); + __GLX_SWAP_DOUBLE_ARRAY(pc + 0, 4); + +} + +void __glXDispSwap_MultiTexCoord4fvARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_FLOAT_ARRAY(pc + 4, 4); + +} + +void __glXDispSwap_MultiTexCoord4ivARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_INT_ARRAY(pc + 4, 4); + +} + +void __glXDispSwap_MultiTexCoord4svARB(GLbyte *pc) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(pc + 0); + __GLX_SWAP_SHORT_ARRAY(pc + 4, 4); + +} + diff --git a/xorg-server/hw/dmx/glxProxy/glxcmds.c b/xorg-server/hw/dmx/glxProxy/glxcmds.c index a76201da0..fb4bce850 100644 --- a/xorg-server/hw/dmx/glxProxy/glxcmds.c +++ b/xorg-server/hw/dmx/glxProxy/glxcmds.c @@ -52,6 +52,8 @@ #include "glxvisuals.h" #include "glxswap.h" +#include "glxcmds.h" + #ifdef PANORAMIX #include "panoramiXsrv.h" #endif diff --git a/xorg-server/hw/dmx/glxProxy/glxcmds.h b/xorg-server/hw/dmx/glxProxy/glxcmds.h new file mode 100644 index 000000000..ae866be29 --- /dev/null +++ b/xorg-server/hw/dmx/glxProxy/glxcmds.h @@ -0,0 +1,37 @@ +/* + * Copyright 2011 Apple Inc. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef __GLX_cmds_h__ +#define __GLX_cmds_h__ + +extern int __glXBindSwapBarrierSGIX(__GLXclientState *cl, GLbyte *pc); +extern int __glXCreateContextWithConfigSGIX(__GLXclientState *cl, GLbyte *pc); +extern int __glXJoinSwapGroupSGIX(__GLXclientState *cl, GLbyte *pc); +extern int __glXMakeCurrentReadSGI(__GLXclientState *cl, GLbyte *pc); +extern int __glXQueryMaxSwapBarriersSGIX(__GLXclientState *cl, GLbyte *pc); + +#endif /* !__GLX_cmds_h__ */ diff --git a/xorg-server/hw/dmx/glxProxy/glxcmdsswap.c b/xorg-server/hw/dmx/glxProxy/glxcmdsswap.c index ca41c1585..f28a79df6 100644 --- a/xorg-server/hw/dmx/glxProxy/glxcmdsswap.c +++ b/xorg-server/hw/dmx/glxProxy/glxcmdsswap.c @@ -1,1059 +1,1062 @@ -/*
- * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
- * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice including the dates of first publication and
- * either this permission notice or a reference to
- * http://oss.sgi.com/projects/FreeB/
- * shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Except as contained in this notice, the name of Silicon Graphics, Inc.
- * shall not be used in advertising or otherwise to promote the sale, use or
- * other dealings in this Software without prior written authorization from
- * Silicon Graphics, Inc.
- */
-
-#include "glxserver.h"
-#include "glxutil.h"
-#include <GL/glxtokens.h>
-#include <g_disptab.h>
-#include <pixmapstr.h>
-#include <windowstr.h>
-#include "unpack.h"
-#include "glxext.h"
-#include "glxvendor.h"
-
-extern int glxIsExtensionSupported( char *ext );
-
-/************************************************************************/
-
-/*
-** Byteswapping versions of GLX commands. In most cases they just swap
-** the incoming arguments and then call the unswapped routine. For commands
-** that have replies, a separate swapping routine for the reply is provided;
-** it is called at the end of the unswapped routine.
-*/
-
-int __glXSwapCreateContext(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXCreateContextReq *req = (xGLXCreateContextReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->visual);
- __GLX_SWAP_INT(&req->screen);
- __GLX_SWAP_INT(&req->shareList);
-
- return __glXCreateContext(cl, pc);
-}
-
-int __glXSwapCreateNewContext(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXCreateNewContextReq *req = (xGLXCreateNewContextReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->fbconfig);
- __GLX_SWAP_INT(&req->screen);
- __GLX_SWAP_INT(&req->shareList);
-
- return __glXCreateNewContext(cl, pc);
-}
-
-int __glXSwapCreateContextWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXCreateContextWithConfigSGIXReq *req = (xGLXCreateContextWithConfigSGIXReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->fbconfig);
- __GLX_SWAP_INT(&req->screen);
- __GLX_SWAP_INT(&req->shareList);
-
- return __glXCreateContextWithConfigSGIX(cl, pc);
-}
-
-int __glXSwapQueryMaxSwapBarriersSGIX(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXQueryMaxSwapBarriersSGIXReq *req =
- (xGLXQueryMaxSwapBarriersSGIXReq *)pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->screen);
-
- return __glXQueryMaxSwapBarriersSGIX(cl, pc);
-}
-
-int __glXSwapBindSwapBarrierSGIX(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXBindSwapBarrierSGIXReq *req = (xGLXBindSwapBarrierSGIXReq *)pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->barrier);
-
- return __glXBindSwapBarrierSGIX(cl, pc);
-}
-
-int __glXSwapJoinSwapGroupSGIX(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXJoinSwapGroupSGIXReq *req = (xGLXJoinSwapGroupSGIXReq *)pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->member);
-
- return __glXJoinSwapGroupSGIX(cl, pc);
-}
-
-int __glXSwapDestroyContext(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXDestroyContextReq *req = (xGLXDestroyContextReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->context);
-
- return __glXDestroyContext(cl, pc);
-}
-
-int __glXSwapMakeCurrent(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->oldContextTag);
-
- return __glXMakeCurrent(cl, pc);
-}
-
-int __glXSwapMakeContextCurrent(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXMakeContextCurrentReq *req = (xGLXMakeContextCurrentReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->readdrawable);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->oldContextTag);
-
- return __glXMakeContextCurrent(cl, pc);
-}
-
-int __glXSwapMakeCurrentReadSGI(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXMakeCurrentReadSGIReq *req = (xGLXMakeCurrentReadSGIReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->readable);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->oldContextTag);
-
- return __glXMakeCurrentReadSGI(cl, pc);
-}
-
-int __glXSwapIsDirect(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXIsDirectReq *req = (xGLXIsDirectReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->context);
-
- return __glXIsDirect(cl, pc);
-}
-
-int __glXSwapQueryVersion(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXQueryVersionReq *req = (xGLXQueryVersionReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->majorVersion);
- __GLX_SWAP_INT(&req->minorVersion);
-
- return __glXQueryVersion(cl, pc);
-}
-
-int __glXSwapWaitGL(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXWaitGLReq *req = (xGLXWaitGLReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->contextTag);
-
- return __glXWaitGL(cl, pc);
-}
-
-int __glXSwapWaitX(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXWaitXReq *req = (xGLXWaitXReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->contextTag);
-
- return __glXWaitX(cl, pc);
-}
-
-int __glXSwapCopyContext(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXCopyContextReq *req = (xGLXCopyContextReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->source);
- __GLX_SWAP_INT(&req->dest);
- __GLX_SWAP_INT(&req->mask);
-
- return __glXCopyContext(cl, pc);
-}
-
-int __glXSwapGetVisualConfigs(__GLXclientState *cl, GLbyte *pc)
-{
- ClientPtr client = cl->client;
- xGLXGetVisualConfigsReq *req = (xGLXGetVisualConfigsReq *) pc;
- xGLXGetVisualConfigsReply reply;
- __GLXscreenInfo *pGlxScreen;
- __GLXvisualConfig *pGlxVisual;
- CARD32 buf[__GLX_TOTAL_CONFIG];
- unsigned int screen;
- int i, p;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_INT(&req->screen);
- screen = req->screen;
- if (screen >= screenInfo.numScreens) {
- /* The client library must send a valid screen number. */
- client->errorValue = screen;
- return BadValue;
- }
- pGlxScreen = &__glXActiveScreens[screen];
-
- reply.numVisuals = pGlxScreen->numGLXVisuals;
- reply.numProps = __GLX_TOTAL_CONFIG;
- reply.length = (pGlxScreen->numGLXVisuals * __GLX_SIZE_CARD32 *
- __GLX_TOTAL_CONFIG) >> 2;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
-
- __GLX_SWAP_SHORT(&reply.sequenceNumber);
- __GLX_SWAP_INT(&reply.length);
- __GLX_SWAP_INT(&reply.numVisuals);
- __GLX_SWAP_INT(&reply.numProps);
- WriteToClient(client, sz_xGLXGetVisualConfigsReply, (char *)&reply);
-
- for (i=0; i < pGlxScreen->numVisuals; i++) {
- pGlxVisual = &pGlxScreen->pGlxVisual[i];
- if (!pGlxScreen->isGLXvis[i] || pGlxVisual->vid == 0) {
- /* not a usable visual */
- continue;
- }
- p = 0;
- buf[p++] = pGlxVisual->vid;
- buf[p++] = pGlxVisual->class;
- buf[p++] = pGlxVisual->rgba;
-
- buf[p++] = pGlxVisual->redSize;
- buf[p++] = pGlxVisual->greenSize;
- buf[p++] = pGlxVisual->blueSize;
- buf[p++] = pGlxVisual->alphaSize;
- buf[p++] = pGlxVisual->accumRedSize;
- buf[p++] = pGlxVisual->accumGreenSize;
- buf[p++] = pGlxVisual->accumBlueSize;
- buf[p++] = pGlxVisual->accumAlphaSize;
-
- buf[p++] = pGlxVisual->doubleBuffer;
- buf[p++] = pGlxVisual->stereo;
-
- buf[p++] = pGlxVisual->bufferSize;
- buf[p++] = pGlxVisual->depthSize;
- buf[p++] = pGlxVisual->stencilSize;
- buf[p++] = pGlxVisual->auxBuffers;
- buf[p++] = pGlxVisual->level;
- /*
- ** Add token/value pairs for extensions.
- */
- buf[p++] = GLX_VISUAL_CAVEAT_EXT;
- buf[p++] = pGlxVisual->visualRating;
- buf[p++] = GLX_TRANSPARENT_TYPE_EXT;
- buf[p++] = pGlxVisual->transparentPixel;
- buf[p++] = GLX_TRANSPARENT_RED_VALUE_EXT;
- buf[p++] = pGlxVisual->transparentRed;
- buf[p++] = GLX_TRANSPARENT_GREEN_VALUE_EXT;
- buf[p++] = pGlxVisual->transparentGreen;
- buf[p++] = GLX_TRANSPARENT_BLUE_VALUE_EXT;
- buf[p++] = pGlxVisual->transparentBlue;
- buf[p++] = GLX_TRANSPARENT_ALPHA_VALUE_EXT;
- buf[p++] = pGlxVisual->transparentAlpha;
- buf[p++] = GLX_TRANSPARENT_INDEX_VALUE_EXT;
- buf[p++] = pGlxVisual->transparentIndex;
-
- __GLX_SWAP_INT_ARRAY(buf, __GLX_TOTAL_CONFIG);
- WriteToClient(client, __GLX_SIZE_CARD32 * __GLX_TOTAL_CONFIG,
- (char *)buf);
- }
- return Success;
-}
-
-int __glXSwapCreateGLXPixmap(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXCreateGLXPixmapReq *req = (xGLXCreateGLXPixmapReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->screen);
- __GLX_SWAP_INT(&req->visual);
- __GLX_SWAP_INT(&req->pixmap);
- __GLX_SWAP_INT(&req->glxpixmap);
-
- return __glXCreateGLXPixmap(cl, pc);
-}
-
-int __glXSwapCreatePixmap(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXCreatePixmapReq *req = (xGLXCreatePixmapReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->screen);
- __GLX_SWAP_INT(&req->fbconfig);
- __GLX_SWAP_INT(&req->pixmap);
- __GLX_SWAP_INT(&req->glxpixmap);
- __GLX_SWAP_INT(&req->numAttribs);
-
- return __glXCreatePixmap(cl, pc);
-}
-
-int __glXSwapDestroyGLXPixmap(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXDestroyGLXPixmapReq *req = (xGLXDestroyGLXPixmapReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->glxpixmap);
-
- return __glXDestroyGLXPixmap(cl, pc);
-}
-
-int __glXSwapSwapBuffers(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXSwapBuffersReq *req = (xGLXSwapBuffersReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->contextTag);
- __GLX_SWAP_INT(&req->drawable);
-
- return __glXSwapBuffers(cl, pc);
-}
-
-int __glXSwapUseXFont(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXUseXFontReq *req = (xGLXUseXFontReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->contextTag);
- __GLX_SWAP_INT(&req->font);
- __GLX_SWAP_INT(&req->first);
- __GLX_SWAP_INT(&req->count);
- __GLX_SWAP_INT(&req->listBase);
-
- return __glXUseXFont(cl, pc);
-}
-
-
-int __glXSwapQueryExtensionsString(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXQueryExtensionsStringReq *req = NULL;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->screen);
-
- return __glXQueryExtensionsString(cl, pc);
-}
-
-int __glXSwapQueryServerString(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXQueryServerStringReq *req = (xGLXQueryServerStringReq *)pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->screen);
- __GLX_SWAP_INT(&req->name);
-
- return __glXQueryServerString(cl, pc);
-}
-
-int __glXSwapClientInfo(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXClientInfoReq *req = (xGLXClientInfoReq *)pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->major);
- __GLX_SWAP_INT(&req->minor);
- __GLX_SWAP_INT(&req->numbytes);
-
- return __glXClientInfo(cl, pc);
-}
-
-int __glXSwapQueryContextInfoEXT(__GLXclientState *cl, char *pc)
-{
- xGLXQueryContextInfoEXTReq *req = (xGLXQueryContextInfoEXTReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->context);
-
- return __glXQueryContextInfoEXT(cl, (GLbyte *)pc);
-}
-
-/************************************************************************/
-
-/*
-** Swap replies.
-*/
-
-void __glXSwapMakeCurrentReply(ClientPtr client, xGLXMakeCurrentReadSGIReply *reply)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- __GLX_SWAP_INT(&reply->contextTag);
- __GLX_SWAP_INT(&reply->writeVid);
- __GLX_SWAP_INT(&reply->writeType);
- __GLX_SWAP_INT(&reply->readVid);
- __GLX_SWAP_INT(&reply->readType);
- WriteToClient(client, sz_xGLXMakeCurrentReadSGIReply, (char *)reply);
-}
-
-void __glXSwapIsDirectReply(ClientPtr client, xGLXIsDirectReply *reply)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- WriteToClient(client, sz_xGLXIsDirectReply, (char *)reply);
-}
-
-void __glXSwapQueryVersionReply(ClientPtr client, xGLXQueryVersionReply *reply)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- __GLX_SWAP_INT(&reply->majorVersion);
- __GLX_SWAP_INT(&reply->minorVersion);
- WriteToClient(client, sz_xGLXQueryVersionReply, (char *)reply);
-}
-
-void glxSwapQueryExtensionsStringReply(ClientPtr client,
- xGLXQueryExtensionsStringReply *reply, char *buf)
-{
- int length = reply->length;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- __GLX_SWAP_INT(&reply->n);
- WriteToClient(client, sz_xGLXQueryExtensionsStringReply, (char *)reply);
- __GLX_SWAP_INT_ARRAY((int *)buf, length);
- WriteToClient(client, length << 2, buf);
-}
-
-void glxSwapQueryServerStringReply(ClientPtr client,
- xGLXQueryServerStringReply *reply, char *buf)
-{
- int length = reply->length;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- __GLX_SWAP_INT(&reply->n);
- WriteToClient(client, sz_xGLXQueryServerStringReply, (char *)reply);
- /** no swap is needed for an array of chars **/
- /* __GLX_SWAP_INT_ARRAY((int *)buf, length); */
- WriteToClient(client, length << 2, buf);
-}
-
-void __glXSwapQueryContextInfoEXTReply(ClientPtr client, xGLXQueryContextInfoEXTReply *reply, int *buf)
-{
- int length = reply->length;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- __GLX_SWAP_INT(&reply->n);
- WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, (char *)reply);
- __GLX_SWAP_INT_ARRAY((int *)buf, length);
- WriteToClient(client, length << 2, (char *)buf);
-}
-
-
-void __glXSwapQueryContextReply(ClientPtr client,
- xGLXQueryContextReply *reply, int *buf)
-{
- int length = reply->length;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- __GLX_SWAP_INT(&reply->n);
- WriteToClient(client, sz_xGLXQueryContextReply, (char *)reply);
- __GLX_SWAP_INT_ARRAY((int *)buf, length);
- WriteToClient(client, length << 2, (char *)buf);
-}
-
-void __glXSwapGetDrawableAttributesReply(ClientPtr client,
- xGLXGetDrawableAttributesReply *reply, int *buf)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- __GLX_SWAP_INT(&reply->numAttribs);
- __GLX_SWAP_INT_ARRAY( buf, reply->length );
- WriteToClient(client, sz_xGLXGetDrawableAttributesReply, (char *)reply);
- WriteToClient(client, reply->length << 2, (char *)buf);
-}
-
-void __glXSwapQueryMaxSwapBarriersSGIXReply(ClientPtr client, xGLXQueryMaxSwapBarriersSGIXReply *reply)
-{
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_SWAP_SHORT(&reply->sequenceNumber);
- __GLX_SWAP_INT(&reply->length);
- __GLX_SWAP_INT(&reply->max);
- WriteToClient(client, sz_xGLXQueryMaxSwapBarriersSGIXReply, (char *)reply);
-}
-
-/************************************************************************/
-
-/*
-** Render and Renderlarge are not in the GLX API. They are used by the GLX
-** client library to send batches of GL rendering commands.
-*/
-
-int __glXSwapRender(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXRenderReq *req;
- int left;
- __GLXrenderHeader *hdr;
- ClientPtr client = cl->client;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- /*
- ** NOTE: much of this code also appears in the nonswapping version of this
- ** routine, __glXRender(). Any changes made here should also be
- ** duplicated there.
- */
-
- req = (xGLXRenderReq *) pc;
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->contextTag);
-
- pc += sz_xGLXRenderReq;
- left = (req->length << 2) - sz_xGLXRenderReq;
- while (left > 0) {
- void (* proc)(GLbyte *);
- CARD16 opcode;
-
- /*
- ** Verify that the header length and the overall length agree.
- ** Also, each command must be word aligned.
- */
- hdr = (__GLXrenderHeader *) pc;
- __GLX_SWAP_SHORT(&hdr->length);
- __GLX_SWAP_SHORT(&hdr->opcode);
-
- /*
- * call the command procedure to swap any arguments
- */
- opcode = hdr->opcode;
- if ( (opcode >= __GLX_MIN_RENDER_OPCODE) &&
- (opcode <= __GLX_MAX_RENDER_OPCODE) ) {
- proc = __glXSwapRenderTable[opcode];
-#if __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT
- } else if ( (opcode >= __GLX_MIN_RENDER_OPCODE_EXT) &&
- (opcode <= __GLX_MAX_RENDER_OPCODE_EXT) ) {
- int index = opcode - __GLX_MIN_RENDER_OPCODE_EXT;
- __GLXRenderSwapInfo *info = &__glXSwapRenderTable_EXT[index];
- if (info->swapfunc) {
- proc = info->swapfunc;
- }
- else {
- proc = NULL;
- if (info->elem_size == 4 && info->nelems > 0) {
- __GLX_SWAP_INT_ARRAY( (int *)(pc + __GLX_RENDER_HDR_SIZE),
- info->nelems );
- }
- else if (info->elem_size == 2 && info->nelems > 0) {
- __GLX_SWAP_SHORT_ARRAY( (short *)(pc + __GLX_RENDER_HDR_SIZE),
- info->nelems );
- }
- else if (info->elem_size == 8 && info->nelems > 0) {
- __GLX_SWAP_DOUBLE_ARRAY( (double *)(pc + __GLX_RENDER_HDR_SIZE),
- info->nelems );
- }
- }
-#endif /* __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT */
- } else {
- client->errorValue = 0;
- return __glXBadRenderRequest;
- }
-
- if (proc != NULL)
- (*proc)(pc + __GLX_RENDER_HDR_SIZE);
-
- /*
- * proceed to the next command
- */
- pc += hdr->length;
- left -= hdr->length;
- }
-
- return __glXRender( cl, (GLbyte *)req );
-}
-
-/*
-** Execute a large rendering request (one that spans multiple X requests).
-*/
-int __glXSwapRenderLarge(__GLXclientState *cl, GLbyte *pc)
-{
- ClientPtr client = cl->client;
- xGLXRenderLargeReq *req;
- __GLXrenderLargeHeader *hdr;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- req = (xGLXRenderLargeReq *) pc;
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->contextTag);
- __GLX_SWAP_INT(&req->dataBytes);
- __GLX_SWAP_SHORT(&req->requestNumber);
- __GLX_SWAP_SHORT(&req->requestTotal);
-
- pc += sz_xGLXRenderLargeReq;
-
- if (req->requestNumber == 1) {
- void (* proc)(GLbyte *) = NULL;
- __GLXRenderSwapInfo *info = NULL;
- CARD16 opcode;
-
- hdr = (__GLXrenderLargeHeader *) pc;
- __GLX_SWAP_INT(&hdr->length);
- __GLX_SWAP_INT(&hdr->opcode);
-
- /*
- * call the command procedure to swap any arguments
- * Note that we are assuming that all arguments that needs to be
- * swaped are on the first req only !
- */
- opcode = hdr->opcode;
- if ( (opcode >= __GLX_MIN_RENDER_OPCODE) &&
- (opcode <= __GLX_MAX_RENDER_OPCODE) ) {
- proc = __glXSwapRenderTable[opcode];
-#if __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT
- } else if ( (opcode >= __GLX_MIN_RENDER_OPCODE_EXT) &&
- (opcode <= __GLX_MAX_RENDER_OPCODE_EXT) ) {
- int index = opcode - __GLX_MIN_RENDER_OPCODE_EXT;
- info = &__glXSwapRenderTable_EXT[index];
- if (info->swapfunc) {
- proc = info->swapfunc;
- }
-#endif /* __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT */
- } else {
- client->errorValue = 0;
- cl->largeCmdRequestsTotal = 0;
- return __glXBadLargeRequest;
- }
-
- /*
- ** Make enough space in the buffer, then copy the entire request.
- */
- if (cl->largeCmdBufSize < hdr->length) {
- if (!cl->largeCmdBuf) {
- cl->largeCmdBuf = (GLbyte *) malloc(hdr->length);
- } else {
- cl->largeCmdBuf = (GLbyte *) realloc(cl->largeCmdBuf, hdr->length);
- }
- if (!cl->largeCmdBuf) {
- cl->largeCmdRequestsTotal = 0;
- return BadAlloc;
- }
- cl->largeCmdBufSize = hdr->length;
- }
- memcpy(cl->largeCmdBuf, pc, req->dataBytes);
-
- cl->largeCmdBytesSoFar = req->dataBytes;
- cl->largeCmdBytesTotal = hdr->length;
- cl->largeCmdRequestsSoFar = 1;
- cl->largeCmdRequestsTotal = req->requestTotal;
- cl->largeCmdRequestsSwapProc = proc;
- cl->largeCmdMaxReqDataSize = req->dataBytes;
- cl->largeCmdRequestsSwap_info = info;
-
- return Success;
-
-
- }
- else if (req->requestNumber < cl->largeCmdRequestsTotal) {
- /*
- * This is not the first nor last request - just copy the data
- */
- if ( cl->largeCmdBytesSoFar + req->dataBytes > cl->largeCmdBytesTotal) {
- cl->largeCmdRequestsTotal = 0;
- return __glXBadLargeRequest;
- }
-
- memcpy(cl->largeCmdBuf + cl->largeCmdBytesSoFar,
- pc, req->dataBytes);
-
- cl->largeCmdBytesSoFar += req->dataBytes;
-
- if (req->dataBytes > cl->largeCmdMaxReqDataSize)
- cl->largeCmdMaxReqDataSize = req->dataBytes;
-
- return Success;
- }
- else if (req->requestNumber == cl->largeCmdRequestsTotal) {
- /*
- * this is the last request
- * copy the remainder bytes, call the procedure to swap any
- * needed data, and then call to transfer the command to all
- * back-end servers
- */
- if ( cl->largeCmdBytesSoFar + req->dataBytes > cl->largeCmdBytesTotal) {
- cl->largeCmdRequestsTotal = 0;
- return __glXBadLargeRequest;
- }
-
- memcpy(cl->largeCmdBuf + cl->largeCmdBytesSoFar,
- pc, req->dataBytes);
-
- cl->largeCmdBytesSoFar += req->dataBytes;
-
- if (req->dataBytes > cl->largeCmdMaxReqDataSize)
- cl->largeCmdMaxReqDataSize = req->dataBytes;
-
- if (cl->largeCmdRequestsSwapProc != NULL) {
- (*cl->largeCmdRequestsSwapProc)(cl->largeCmdBuf + __GLX_RENDER_LARGE_HDR_SIZE);
- }
- else if (cl->largeCmdRequestsSwap_info &&
- cl->largeCmdRequestsSwap_info->nelems > 0) {
- if (cl->largeCmdRequestsSwap_info->elem_size == 4) {
- __GLX_SWAP_INT_ARRAY( (int *)(pc + __GLX_RENDER_LARGE_HDR_SIZE),
- cl->largeCmdRequestsSwap_info->nelems );
- }
- else if (cl->largeCmdRequestsSwap_info->elem_size == 2) {
- __GLX_SWAP_SHORT_ARRAY( (short *)(pc + __GLX_RENDER_LARGE_HDR_SIZE),
- cl->largeCmdRequestsSwap_info->nelems );
- }
- else if (cl->largeCmdRequestsSwap_info->elem_size == 8) {
- __GLX_SWAP_DOUBLE_ARRAY( (double *)(pc + __GLX_RENDER_LARGE_HDR_SIZE),
- cl->largeCmdRequestsSwap_info->nelems );
- }
- }
-
- cl->largeCmdRequestsTotal = 0;
- return( __glXSendLargeCommand(cl, req->contextTag) );
-
- }
- else {
- cl->largeCmdRequestsTotal = 0;
- return __glXBadLargeRequest;
- }
-
-}
-
-/************************************************************************/
-
-/*
-** No support is provided for the vendor-private requests other than
-** allocating these entry points in the dispatch table.
-*/
-
-int __glXSwapVendorPrivate(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXVendorPrivateReq *req;
- CARD32 vendorCode;
-
- __GLX_DECLARE_SWAP_VARIABLES;
-
- req = (xGLXVendorPrivateReq *) pc;
- vendorCode = req->vendorCode;
- __GLX_SWAP_INT(&vendorCode);
-
-
- switch( vendorCode ) {
-
- case X_GLvop_DeleteTexturesEXT:
- return __glXVForwardSingleReqSwap( cl, pc );
- break;
-
- case X_GLXvop_SwapIntervalSGI:
- if (glxIsExtensionSupported("SGI_swap_control")) {
- return __glXVForwardSingleReqSwap( cl, pc );
- }
- else {
- return Success;
- }
- break;
-
-#if 0 /* glx 1.3 */
- case X_GLXvop_CreateGLXVideoSourceSGIX:
- break;
- case X_GLXvop_DestroyGLXVideoSourceSGIX:
- break;
- case X_GLXvop_CreateGLXPixmapWithConfigSGIX:
- break;
- case X_GLXvop_DestroyGLXPbufferSGIX:
- break;
- case X_GLXvop_ChangeDrawableAttributesSGIX:
- break;
-#endif
-
- case X_GLXvop_JoinSwapGroupSGIX:
- return __glXSwapJoinSwapGroupSGIX( cl, pc );
- break;
-
- case X_GLXvop_BindSwapBarrierSGIX:
- return __glXSwapBindSwapBarrierSGIX( cl, pc );
- break;
-
- case X_GLXvop_CreateContextWithConfigSGIX:
- return __glXSwapCreateContextWithConfigSGIX( cl, pc );
- break;
-
- default:
- /*
- ** unsupported private request
- */
- cl->client->errorValue = req->vendorCode;
- return __glXUnsupportedPrivateRequest;
- }
-
-}
-
-int __glXSwapVendorPrivateWithReply(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXVendorPrivateWithReplyReq *req;
- CARD32 vendorCode;
-
- __GLX_DECLARE_SWAP_VARIABLES;
-
- req = (xGLXVendorPrivateWithReplyReq *) pc;
- vendorCode = req->vendorCode;
- __GLX_SWAP_INT(&vendorCode);
-
- switch( vendorCode ) {
-
- case X_GLvop_GetConvolutionFilterEXT:
- case X_GLvop_GetSeparableFilterEXT:
- case X_GLvop_GetHistogramEXT:
- case X_GLvop_GetMinmaxEXT:
- return( __glXNoSuchSingleOpcode(cl, pc) );
- break;
-
- case X_GLvop_GetConvolutionParameterfvEXT:
- case X_GLvop_GetConvolutionParameterivEXT:
- case X_GLvop_GetHistogramParameterivEXT:
- case X_GLvop_GetMinmaxParameterfvEXT:
- case X_GLvop_GetMinmaxParameterivEXT:
- case X_GLvop_GenTexturesEXT:
- return( __glXVForwardAllWithReplySwapiv(cl, pc) );
- break;
-
- case X_GLvop_AreTexturesResidentEXT:
- case X_GLvop_IsTextureEXT:
- return( __glXVForwardPipe0WithReplySwap(cl, pc) );
- break;
-
-#if 0 /* glx1.3 */
- case X_GLvop_GetDetailTexFuncSGIS:
- case X_GLvop_GetSharpenTexFuncSGIS:
- case X_GLvop_GetColorTableSGI:
- case X_GLvop_GetColorTableParameterfvSGI:
- case X_GLvop_GetColorTableParameterivSGI:
- case X_GLvop_GetTexFilterFuncSGIS:
- case X_GLvop_GetInstrumentsSGIX:
- case X_GLvop_InstrumentsBufferSGIX:
- case X_GLvop_PollInstrumentsSGIX:
- case X_GLvop_FlushRasterSGIX:
- case X_GLXvop_CreateGLXPbufferSGIX:
- case X_GLXvop_GetDrawableAttributesSGIX:
- case X_GLXvop_QueryHyperpipeNetworkSGIX:
- case X_GLXvop_QueryHyperpipeConfigSGIX:
- case X_GLXvop_HyperpipeConfigSGIX:
- case X_GLXvop_DestroyHyperpipeConfigSGIX:
-#endif
- case X_GLXvop_QueryMaxSwapBarriersSGIX:
- return( __glXSwapQueryMaxSwapBarriersSGIX(cl, pc) );
- break;
-
- case X_GLXvop_GetFBConfigsSGIX:
- return( __glXSwapGetFBConfigsSGIX(cl, pc) );
- break;
-
- case X_GLXvop_MakeCurrentReadSGI:
- return( __glXSwapMakeCurrentReadSGI(cl, pc) );
- break;
-
- case X_GLXvop_QueryContextInfoEXT:
- return( __glXSwapQueryContextInfoEXT(cl,(char *)pc) );
- break;
-
- default:
- /*
- ** unsupported private request
- */
- cl->client->errorValue = req->vendorCode;
- return __glXUnsupportedPrivateRequest;
- }
-
-}
-
-int __glXSwapGetFBConfigs(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXGetFBConfigsReq *req = (xGLXGetFBConfigsReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->screen);
-
- return __glXGetFBConfigs(cl, pc);
-}
-
-int __glXSwapGetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXGetFBConfigsSGIXReq *req = (xGLXGetFBConfigsSGIXReq *)pc;
- xGLXGetFBConfigsReq new_req;
-
- new_req.reqType = req->reqType;
- new_req.glxCode = req->glxCode;
- new_req.length = req->length;
- new_req.screen = req->screen;
-
- return( __glXSwapGetFBConfigs( cl, (GLbyte *)&new_req ) );
-}
-
-int __glXSwapCreateWindow(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXCreateWindowReq *req = (xGLXCreateWindowReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->screen);
- __GLX_SWAP_INT(&req->fbconfig);
- __GLX_SWAP_INT(&req->window);
- __GLX_SWAP_INT(&req->glxwindow);
- __GLX_SWAP_INT(&req->numAttribs);
-
- return( __glXCreateWindow( cl, (GLbyte *)pc ) );
-}
-
-int __glXSwapDestroyWindow(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->glxwindow);
-
- return( __glXDestroyWindow( cl, (GLbyte *)pc ) );
-}
-
-int __glXSwapQueryContext(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXQueryContextReq *req = (xGLXQueryContextReq *)pc;
-
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->context);
-
- return( __glXQueryContext(cl, (GLbyte *)pc) );
-
-}
-
-int __glXSwapCreatePbuffer(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXCreatePbufferReq *req = (xGLXCreatePbufferReq *)pc;
- int nattr = req->numAttribs;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->screen);
- __GLX_SWAP_INT(&req->fbconfig);
- __GLX_SWAP_INT(&req->pbuffer);
- __GLX_SWAP_INT(&req->numAttribs);
- __GLX_SWAP_INT_ARRAY( (int *)(req+1), nattr*2 );
-
- return( __glXCreatePbuffer( cl, pc ) );
-}
-
-int __glXSwapDestroyPbuffer(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXDestroyPbufferReq *req = (xGLXDestroyPbufferReq *) pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->pbuffer);
-
- return( __glXDestroyPbuffer( cl, (GLbyte *)pc ) );
-}
-
-int __glXSwapGetDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXGetDrawableAttributesReq *req = (xGLXGetDrawableAttributesReq *)pc;
- __GLX_DECLARE_SWAP_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
-
- return( __glXGetDrawableAttributes(cl, pc) );
-}
-
-int __glXSwapChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
-{
- xGLXChangeDrawableAttributesReq *req = (xGLXChangeDrawableAttributesReq *)pc;
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->numAttribs);
- __GLX_SWAP_INT_ARRAY( (int *)(req+1), req->numAttribs * 2 );
-
- return( __glXChangeDrawableAttributes(cl, pc) );
-}
+/* + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) + * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice including the dates of first publication and + * either this permission notice or a reference to + * http://oss.sgi.com/projects/FreeB/ + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of Silicon Graphics, Inc. + * shall not be used in advertising or otherwise to promote the sale, use or + * other dealings in this Software without prior written authorization from + * Silicon Graphics, Inc. + */ + +#include "glxserver.h" +#include "glxutil.h" +#include <GL/glxtokens.h> +#include <g_disptab.h> +#include <pixmapstr.h> +#include <windowstr.h> +#include "unpack.h" +#include "glxcmds.h" +#include "glxext.h" +#include "glxvendor.h" + +extern int glxIsExtensionSupported( char *ext ); + +int __glXSwapGetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc); + +/************************************************************************/ + +/* +** Byteswapping versions of GLX commands. In most cases they just swap +** the incoming arguments and then call the unswapped routine. For commands +** that have replies, a separate swapping routine for the reply is provided; +** it is called at the end of the unswapped routine. +*/ + +int __glXSwapCreateContext(__GLXclientState *cl, GLbyte *pc) +{ + xGLXCreateContextReq *req = (xGLXCreateContextReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->context); + __GLX_SWAP_INT(&req->visual); + __GLX_SWAP_INT(&req->screen); + __GLX_SWAP_INT(&req->shareList); + + return __glXCreateContext(cl, pc); +} + +int __glXSwapCreateNewContext(__GLXclientState *cl, GLbyte *pc) +{ + xGLXCreateNewContextReq *req = (xGLXCreateNewContextReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->context); + __GLX_SWAP_INT(&req->fbconfig); + __GLX_SWAP_INT(&req->screen); + __GLX_SWAP_INT(&req->shareList); + + return __glXCreateNewContext(cl, pc); +} + +int __glXSwapCreateContextWithConfigSGIX(__GLXclientState *cl, GLbyte *pc) +{ + xGLXCreateContextWithConfigSGIXReq *req = (xGLXCreateContextWithConfigSGIXReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->context); + __GLX_SWAP_INT(&req->fbconfig); + __GLX_SWAP_INT(&req->screen); + __GLX_SWAP_INT(&req->shareList); + + return __glXCreateContextWithConfigSGIX(cl, pc); +} + +int __glXSwapQueryMaxSwapBarriersSGIX(__GLXclientState *cl, GLbyte *pc) +{ + xGLXQueryMaxSwapBarriersSGIXReq *req = + (xGLXQueryMaxSwapBarriersSGIXReq *)pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->screen); + + return __glXQueryMaxSwapBarriersSGIX(cl, pc); +} + +int __glXSwapBindSwapBarrierSGIX(__GLXclientState *cl, GLbyte *pc) +{ + xGLXBindSwapBarrierSGIXReq *req = (xGLXBindSwapBarrierSGIXReq *)pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->drawable); + __GLX_SWAP_INT(&req->barrier); + + return __glXBindSwapBarrierSGIX(cl, pc); +} + +int __glXSwapJoinSwapGroupSGIX(__GLXclientState *cl, GLbyte *pc) +{ + xGLXJoinSwapGroupSGIXReq *req = (xGLXJoinSwapGroupSGIXReq *)pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->drawable); + __GLX_SWAP_INT(&req->member); + + return __glXJoinSwapGroupSGIX(cl, pc); +} + +int __glXSwapDestroyContext(__GLXclientState *cl, GLbyte *pc) +{ + xGLXDestroyContextReq *req = (xGLXDestroyContextReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->context); + + return __glXDestroyContext(cl, pc); +} + +int __glXSwapMakeCurrent(__GLXclientState *cl, GLbyte *pc) +{ + xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->drawable); + __GLX_SWAP_INT(&req->context); + __GLX_SWAP_INT(&req->oldContextTag); + + return __glXMakeCurrent(cl, pc); +} + +int __glXSwapMakeContextCurrent(__GLXclientState *cl, GLbyte *pc) +{ + xGLXMakeContextCurrentReq *req = (xGLXMakeContextCurrentReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->drawable); + __GLX_SWAP_INT(&req->readdrawable); + __GLX_SWAP_INT(&req->context); + __GLX_SWAP_INT(&req->oldContextTag); + + return __glXMakeContextCurrent(cl, pc); +} + +int __glXSwapMakeCurrentReadSGI(__GLXclientState *cl, GLbyte *pc) +{ + xGLXMakeCurrentReadSGIReq *req = (xGLXMakeCurrentReadSGIReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->drawable); + __GLX_SWAP_INT(&req->readable); + __GLX_SWAP_INT(&req->context); + __GLX_SWAP_INT(&req->oldContextTag); + + return __glXMakeCurrentReadSGI(cl, pc); +} + +int __glXSwapIsDirect(__GLXclientState *cl, GLbyte *pc) +{ + xGLXIsDirectReq *req = (xGLXIsDirectReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->context); + + return __glXIsDirect(cl, pc); +} + +int __glXSwapQueryVersion(__GLXclientState *cl, GLbyte *pc) +{ + xGLXQueryVersionReq *req = (xGLXQueryVersionReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->majorVersion); + __GLX_SWAP_INT(&req->minorVersion); + + return __glXQueryVersion(cl, pc); +} + +int __glXSwapWaitGL(__GLXclientState *cl, GLbyte *pc) +{ + xGLXWaitGLReq *req = (xGLXWaitGLReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->contextTag); + + return __glXWaitGL(cl, pc); +} + +int __glXSwapWaitX(__GLXclientState *cl, GLbyte *pc) +{ + xGLXWaitXReq *req = (xGLXWaitXReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->contextTag); + + return __glXWaitX(cl, pc); +} + +int __glXSwapCopyContext(__GLXclientState *cl, GLbyte *pc) +{ + xGLXCopyContextReq *req = (xGLXCopyContextReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->source); + __GLX_SWAP_INT(&req->dest); + __GLX_SWAP_INT(&req->mask); + + return __glXCopyContext(cl, pc); +} + +int __glXSwapGetVisualConfigs(__GLXclientState *cl, GLbyte *pc) +{ + ClientPtr client = cl->client; + xGLXGetVisualConfigsReq *req = (xGLXGetVisualConfigsReq *) pc; + xGLXGetVisualConfigsReply reply; + __GLXscreenInfo *pGlxScreen; + __GLXvisualConfig *pGlxVisual; + CARD32 buf[__GLX_TOTAL_CONFIG]; + unsigned int screen; + int i, p; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_INT(&req->screen); + screen = req->screen; + if (screen >= screenInfo.numScreens) { + /* The client library must send a valid screen number. */ + client->errorValue = screen; + return BadValue; + } + pGlxScreen = &__glXActiveScreens[screen]; + + reply.numVisuals = pGlxScreen->numGLXVisuals; + reply.numProps = __GLX_TOTAL_CONFIG; + reply.length = (pGlxScreen->numGLXVisuals * __GLX_SIZE_CARD32 * + __GLX_TOTAL_CONFIG) >> 2; + reply.type = X_Reply; + reply.sequenceNumber = client->sequence; + + __GLX_SWAP_SHORT(&reply.sequenceNumber); + __GLX_SWAP_INT(&reply.length); + __GLX_SWAP_INT(&reply.numVisuals); + __GLX_SWAP_INT(&reply.numProps); + WriteToClient(client, sz_xGLXGetVisualConfigsReply, (char *)&reply); + + for (i=0; i < pGlxScreen->numVisuals; i++) { + pGlxVisual = &pGlxScreen->pGlxVisual[i]; + if (!pGlxScreen->isGLXvis[i] || pGlxVisual->vid == 0) { + /* not a usable visual */ + continue; + } + p = 0; + buf[p++] = pGlxVisual->vid; + buf[p++] = pGlxVisual->class; + buf[p++] = pGlxVisual->rgba; + + buf[p++] = pGlxVisual->redSize; + buf[p++] = pGlxVisual->greenSize; + buf[p++] = pGlxVisual->blueSize; + buf[p++] = pGlxVisual->alphaSize; + buf[p++] = pGlxVisual->accumRedSize; + buf[p++] = pGlxVisual->accumGreenSize; + buf[p++] = pGlxVisual->accumBlueSize; + buf[p++] = pGlxVisual->accumAlphaSize; + + buf[p++] = pGlxVisual->doubleBuffer; + buf[p++] = pGlxVisual->stereo; + + buf[p++] = pGlxVisual->bufferSize; + buf[p++] = pGlxVisual->depthSize; + buf[p++] = pGlxVisual->stencilSize; + buf[p++] = pGlxVisual->auxBuffers; + buf[p++] = pGlxVisual->level; + /* + ** Add token/value pairs for extensions. + */ + buf[p++] = GLX_VISUAL_CAVEAT_EXT; + buf[p++] = pGlxVisual->visualRating; + buf[p++] = GLX_TRANSPARENT_TYPE_EXT; + buf[p++] = pGlxVisual->transparentPixel; + buf[p++] = GLX_TRANSPARENT_RED_VALUE_EXT; + buf[p++] = pGlxVisual->transparentRed; + buf[p++] = GLX_TRANSPARENT_GREEN_VALUE_EXT; + buf[p++] = pGlxVisual->transparentGreen; + buf[p++] = GLX_TRANSPARENT_BLUE_VALUE_EXT; + buf[p++] = pGlxVisual->transparentBlue; + buf[p++] = GLX_TRANSPARENT_ALPHA_VALUE_EXT; + buf[p++] = pGlxVisual->transparentAlpha; + buf[p++] = GLX_TRANSPARENT_INDEX_VALUE_EXT; + buf[p++] = pGlxVisual->transparentIndex; + + __GLX_SWAP_INT_ARRAY(buf, __GLX_TOTAL_CONFIG); + WriteToClient(client, __GLX_SIZE_CARD32 * __GLX_TOTAL_CONFIG, + (char *)buf); + } + return Success; +} + +int __glXSwapCreateGLXPixmap(__GLXclientState *cl, GLbyte *pc) +{ + xGLXCreateGLXPixmapReq *req = (xGLXCreateGLXPixmapReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->screen); + __GLX_SWAP_INT(&req->visual); + __GLX_SWAP_INT(&req->pixmap); + __GLX_SWAP_INT(&req->glxpixmap); + + return __glXCreateGLXPixmap(cl, pc); +} + +int __glXSwapCreatePixmap(__GLXclientState *cl, GLbyte *pc) +{ + xGLXCreatePixmapReq *req = (xGLXCreatePixmapReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->screen); + __GLX_SWAP_INT(&req->fbconfig); + __GLX_SWAP_INT(&req->pixmap); + __GLX_SWAP_INT(&req->glxpixmap); + __GLX_SWAP_INT(&req->numAttribs); + + return __glXCreatePixmap(cl, pc); +} + +int __glXSwapDestroyGLXPixmap(__GLXclientState *cl, GLbyte *pc) +{ + xGLXDestroyGLXPixmapReq *req = (xGLXDestroyGLXPixmapReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->glxpixmap); + + return __glXDestroyGLXPixmap(cl, pc); +} + +int __glXSwapSwapBuffers(__GLXclientState *cl, GLbyte *pc) +{ + xGLXSwapBuffersReq *req = (xGLXSwapBuffersReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->contextTag); + __GLX_SWAP_INT(&req->drawable); + + return __glXSwapBuffers(cl, pc); +} + +int __glXSwapUseXFont(__GLXclientState *cl, GLbyte *pc) +{ + xGLXUseXFontReq *req = (xGLXUseXFontReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->contextTag); + __GLX_SWAP_INT(&req->font); + __GLX_SWAP_INT(&req->first); + __GLX_SWAP_INT(&req->count); + __GLX_SWAP_INT(&req->listBase); + + return __glXUseXFont(cl, pc); +} + + +int __glXSwapQueryExtensionsString(__GLXclientState *cl, GLbyte *pc) +{ + xGLXQueryExtensionsStringReq *req = NULL; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->screen); + + return __glXQueryExtensionsString(cl, pc); +} + +int __glXSwapQueryServerString(__GLXclientState *cl, GLbyte *pc) +{ + xGLXQueryServerStringReq *req = (xGLXQueryServerStringReq *)pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->screen); + __GLX_SWAP_INT(&req->name); + + return __glXQueryServerString(cl, pc); +} + +int __glXSwapClientInfo(__GLXclientState *cl, GLbyte *pc) +{ + xGLXClientInfoReq *req = (xGLXClientInfoReq *)pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->major); + __GLX_SWAP_INT(&req->minor); + __GLX_SWAP_INT(&req->numbytes); + + return __glXClientInfo(cl, pc); +} + +int __glXSwapQueryContextInfoEXT(__GLXclientState *cl, char *pc) +{ + xGLXQueryContextInfoEXTReq *req = (xGLXQueryContextInfoEXTReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->context); + + return __glXQueryContextInfoEXT(cl, (GLbyte *)pc); +} + +/************************************************************************/ + +/* +** Swap replies. +*/ + +void __glXSwapMakeCurrentReply(ClientPtr client, xGLXMakeCurrentReadSGIReply *reply) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + __GLX_SWAP_INT(&reply->contextTag); + __GLX_SWAP_INT(&reply->writeVid); + __GLX_SWAP_INT(&reply->writeType); + __GLX_SWAP_INT(&reply->readVid); + __GLX_SWAP_INT(&reply->readType); + WriteToClient(client, sz_xGLXMakeCurrentReadSGIReply, (char *)reply); +} + +void __glXSwapIsDirectReply(ClientPtr client, xGLXIsDirectReply *reply) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + WriteToClient(client, sz_xGLXIsDirectReply, (char *)reply); +} + +void __glXSwapQueryVersionReply(ClientPtr client, xGLXQueryVersionReply *reply) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + __GLX_SWAP_INT(&reply->majorVersion); + __GLX_SWAP_INT(&reply->minorVersion); + WriteToClient(client, sz_xGLXQueryVersionReply, (char *)reply); +} + +void glxSwapQueryExtensionsStringReply(ClientPtr client, + xGLXQueryExtensionsStringReply *reply, char *buf) +{ + int length = reply->length; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + __GLX_SWAP_INT(&reply->n); + WriteToClient(client, sz_xGLXQueryExtensionsStringReply, (char *)reply); + __GLX_SWAP_INT_ARRAY((int *)buf, length); + WriteToClient(client, length << 2, buf); +} + +void glxSwapQueryServerStringReply(ClientPtr client, + xGLXQueryServerStringReply *reply, char *buf) +{ + int length = reply->length; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + __GLX_SWAP_INT(&reply->n); + WriteToClient(client, sz_xGLXQueryServerStringReply, (char *)reply); + /** no swap is needed for an array of chars **/ + /* __GLX_SWAP_INT_ARRAY((int *)buf, length); */ + WriteToClient(client, length << 2, buf); +} + +void __glXSwapQueryContextInfoEXTReply(ClientPtr client, xGLXQueryContextInfoEXTReply *reply, int *buf) +{ + int length = reply->length; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + __GLX_SWAP_INT(&reply->n); + WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, (char *)reply); + __GLX_SWAP_INT_ARRAY((int *)buf, length); + WriteToClient(client, length << 2, (char *)buf); +} + + +void __glXSwapQueryContextReply(ClientPtr client, + xGLXQueryContextReply *reply, int *buf) +{ + int length = reply->length; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + __GLX_SWAP_INT(&reply->n); + WriteToClient(client, sz_xGLXQueryContextReply, (char *)reply); + __GLX_SWAP_INT_ARRAY((int *)buf, length); + WriteToClient(client, length << 2, (char *)buf); +} + +void __glXSwapGetDrawableAttributesReply(ClientPtr client, + xGLXGetDrawableAttributesReply *reply, int *buf) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + __GLX_SWAP_INT(&reply->numAttribs); + __GLX_SWAP_INT_ARRAY( buf, reply->length ); + WriteToClient(client, sz_xGLXGetDrawableAttributesReply, (char *)reply); + WriteToClient(client, reply->length << 2, (char *)buf); +} + +void __glXSwapQueryMaxSwapBarriersSGIXReply(ClientPtr client, xGLXQueryMaxSwapBarriersSGIXReply *reply) +{ + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_SWAP_SHORT(&reply->sequenceNumber); + __GLX_SWAP_INT(&reply->length); + __GLX_SWAP_INT(&reply->max); + WriteToClient(client, sz_xGLXQueryMaxSwapBarriersSGIXReply, (char *)reply); +} + +/************************************************************************/ + +/* +** Render and Renderlarge are not in the GLX API. They are used by the GLX +** client library to send batches of GL rendering commands. +*/ + +int __glXSwapRender(__GLXclientState *cl, GLbyte *pc) +{ + xGLXRenderReq *req; + int left; + __GLXrenderHeader *hdr; + ClientPtr client = cl->client; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + /* + ** NOTE: much of this code also appears in the nonswapping version of this + ** routine, __glXRender(). Any changes made here should also be + ** duplicated there. + */ + + req = (xGLXRenderReq *) pc; + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->contextTag); + + pc += sz_xGLXRenderReq; + left = (req->length << 2) - sz_xGLXRenderReq; + while (left > 0) { + void (* proc)(GLbyte *); + CARD16 opcode; + + /* + ** Verify that the header length and the overall length agree. + ** Also, each command must be word aligned. + */ + hdr = (__GLXrenderHeader *) pc; + __GLX_SWAP_SHORT(&hdr->length); + __GLX_SWAP_SHORT(&hdr->opcode); + + /* + * call the command procedure to swap any arguments + */ + opcode = hdr->opcode; + if ( (opcode >= __GLX_MIN_RENDER_OPCODE) && + (opcode <= __GLX_MAX_RENDER_OPCODE) ) { + proc = __glXSwapRenderTable[opcode]; +#if __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT + } else if ( (opcode >= __GLX_MIN_RENDER_OPCODE_EXT) && + (opcode <= __GLX_MAX_RENDER_OPCODE_EXT) ) { + int index = opcode - __GLX_MIN_RENDER_OPCODE_EXT; + __GLXRenderSwapInfo *info = &__glXSwapRenderTable_EXT[index]; + if (info->swapfunc) { + proc = info->swapfunc; + } + else { + proc = NULL; + if (info->elem_size == 4 && info->nelems > 0) { + __GLX_SWAP_INT_ARRAY( (int *)(pc + __GLX_RENDER_HDR_SIZE), + info->nelems ); + } + else if (info->elem_size == 2 && info->nelems > 0) { + __GLX_SWAP_SHORT_ARRAY( (short *)(pc + __GLX_RENDER_HDR_SIZE), + info->nelems ); + } + else if (info->elem_size == 8 && info->nelems > 0) { + __GLX_SWAP_DOUBLE_ARRAY( (double *)(pc + __GLX_RENDER_HDR_SIZE), + info->nelems ); + } + } +#endif /* __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT */ + } else { + client->errorValue = 0; + return __glXBadRenderRequest; + } + + if (proc != NULL) + (*proc)(pc + __GLX_RENDER_HDR_SIZE); + + /* + * proceed to the next command + */ + pc += hdr->length; + left -= hdr->length; + } + + return __glXRender( cl, (GLbyte *)req ); +} + +/* +** Execute a large rendering request (one that spans multiple X requests). +*/ +int __glXSwapRenderLarge(__GLXclientState *cl, GLbyte *pc) +{ + ClientPtr client = cl->client; + xGLXRenderLargeReq *req; + __GLXrenderLargeHeader *hdr; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + req = (xGLXRenderLargeReq *) pc; + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->contextTag); + __GLX_SWAP_INT(&req->dataBytes); + __GLX_SWAP_SHORT(&req->requestNumber); + __GLX_SWAP_SHORT(&req->requestTotal); + + pc += sz_xGLXRenderLargeReq; + + if (req->requestNumber == 1) { + void (* proc)(GLbyte *) = NULL; + __GLXRenderSwapInfo *info = NULL; + CARD16 opcode; + + hdr = (__GLXrenderLargeHeader *) pc; + __GLX_SWAP_INT(&hdr->length); + __GLX_SWAP_INT(&hdr->opcode); + + /* + * call the command procedure to swap any arguments + * Note that we are assuming that all arguments that needs to be + * swaped are on the first req only ! + */ + opcode = hdr->opcode; + if ( (opcode >= __GLX_MIN_RENDER_OPCODE) && + (opcode <= __GLX_MAX_RENDER_OPCODE) ) { + proc = __glXSwapRenderTable[opcode]; +#if __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT + } else if ( (opcode >= __GLX_MIN_RENDER_OPCODE_EXT) && + (opcode <= __GLX_MAX_RENDER_OPCODE_EXT) ) { + int index = opcode - __GLX_MIN_RENDER_OPCODE_EXT; + info = &__glXSwapRenderTable_EXT[index]; + if (info->swapfunc) { + proc = info->swapfunc; + } +#endif /* __GLX_MAX_RENDER_OPCODE_EXT > __GLX_MIN_RENDER_OPCODE_EXT */ + } else { + client->errorValue = 0; + cl->largeCmdRequestsTotal = 0; + return __glXBadLargeRequest; + } + + /* + ** Make enough space in the buffer, then copy the entire request. + */ + if (cl->largeCmdBufSize < hdr->length) { + if (!cl->largeCmdBuf) { + cl->largeCmdBuf = (GLbyte *) malloc(hdr->length); + } else { + cl->largeCmdBuf = (GLbyte *) realloc(cl->largeCmdBuf, hdr->length); + } + if (!cl->largeCmdBuf) { + cl->largeCmdRequestsTotal = 0; + return BadAlloc; + } + cl->largeCmdBufSize = hdr->length; + } + memcpy(cl->largeCmdBuf, pc, req->dataBytes); + + cl->largeCmdBytesSoFar = req->dataBytes; + cl->largeCmdBytesTotal = hdr->length; + cl->largeCmdRequestsSoFar = 1; + cl->largeCmdRequestsTotal = req->requestTotal; + cl->largeCmdRequestsSwapProc = proc; + cl->largeCmdMaxReqDataSize = req->dataBytes; + cl->largeCmdRequestsSwap_info = info; + + return Success; + + + } + else if (req->requestNumber < cl->largeCmdRequestsTotal) { + /* + * This is not the first nor last request - just copy the data + */ + if ( cl->largeCmdBytesSoFar + req->dataBytes > cl->largeCmdBytesTotal) { + cl->largeCmdRequestsTotal = 0; + return __glXBadLargeRequest; + } + + memcpy(cl->largeCmdBuf + cl->largeCmdBytesSoFar, + pc, req->dataBytes); + + cl->largeCmdBytesSoFar += req->dataBytes; + + if (req->dataBytes > cl->largeCmdMaxReqDataSize) + cl->largeCmdMaxReqDataSize = req->dataBytes; + + return Success; + } + else if (req->requestNumber == cl->largeCmdRequestsTotal) { + /* + * this is the last request + * copy the remainder bytes, call the procedure to swap any + * needed data, and then call to transfer the command to all + * back-end servers + */ + if ( cl->largeCmdBytesSoFar + req->dataBytes > cl->largeCmdBytesTotal) { + cl->largeCmdRequestsTotal = 0; + return __glXBadLargeRequest; + } + + memcpy(cl->largeCmdBuf + cl->largeCmdBytesSoFar, + pc, req->dataBytes); + + cl->largeCmdBytesSoFar += req->dataBytes; + + if (req->dataBytes > cl->largeCmdMaxReqDataSize) + cl->largeCmdMaxReqDataSize = req->dataBytes; + + if (cl->largeCmdRequestsSwapProc != NULL) { + (*cl->largeCmdRequestsSwapProc)(cl->largeCmdBuf + __GLX_RENDER_LARGE_HDR_SIZE); + } + else if (cl->largeCmdRequestsSwap_info && + cl->largeCmdRequestsSwap_info->nelems > 0) { + if (cl->largeCmdRequestsSwap_info->elem_size == 4) { + __GLX_SWAP_INT_ARRAY( (int *)(pc + __GLX_RENDER_LARGE_HDR_SIZE), + cl->largeCmdRequestsSwap_info->nelems ); + } + else if (cl->largeCmdRequestsSwap_info->elem_size == 2) { + __GLX_SWAP_SHORT_ARRAY( (short *)(pc + __GLX_RENDER_LARGE_HDR_SIZE), + cl->largeCmdRequestsSwap_info->nelems ); + } + else if (cl->largeCmdRequestsSwap_info->elem_size == 8) { + __GLX_SWAP_DOUBLE_ARRAY( (double *)(pc + __GLX_RENDER_LARGE_HDR_SIZE), + cl->largeCmdRequestsSwap_info->nelems ); + } + } + + cl->largeCmdRequestsTotal = 0; + return( __glXSendLargeCommand(cl, req->contextTag) ); + + } + else { + cl->largeCmdRequestsTotal = 0; + return __glXBadLargeRequest; + } + +} + +/************************************************************************/ + +/* +** No support is provided for the vendor-private requests other than +** allocating these entry points in the dispatch table. +*/ + +int __glXSwapVendorPrivate(__GLXclientState *cl, GLbyte *pc) +{ + xGLXVendorPrivateReq *req; + CARD32 vendorCode; + + __GLX_DECLARE_SWAP_VARIABLES; + + req = (xGLXVendorPrivateReq *) pc; + vendorCode = req->vendorCode; + __GLX_SWAP_INT(&vendorCode); + + + switch( vendorCode ) { + + case X_GLvop_DeleteTexturesEXT: + return __glXVForwardSingleReqSwap( cl, pc ); + break; + + case X_GLXvop_SwapIntervalSGI: + if (glxIsExtensionSupported("SGI_swap_control")) { + return __glXVForwardSingleReqSwap( cl, pc ); + } + else { + return Success; + } + break; + +#if 0 /* glx 1.3 */ + case X_GLXvop_CreateGLXVideoSourceSGIX: + break; + case X_GLXvop_DestroyGLXVideoSourceSGIX: + break; + case X_GLXvop_CreateGLXPixmapWithConfigSGIX: + break; + case X_GLXvop_DestroyGLXPbufferSGIX: + break; + case X_GLXvop_ChangeDrawableAttributesSGIX: + break; +#endif + + case X_GLXvop_JoinSwapGroupSGIX: + return __glXSwapJoinSwapGroupSGIX( cl, pc ); + break; + + case X_GLXvop_BindSwapBarrierSGIX: + return __glXSwapBindSwapBarrierSGIX( cl, pc ); + break; + + case X_GLXvop_CreateContextWithConfigSGIX: + return __glXSwapCreateContextWithConfigSGIX( cl, pc ); + break; + + default: + /* + ** unsupported private request + */ + cl->client->errorValue = req->vendorCode; + return __glXUnsupportedPrivateRequest; + } + +} + +int __glXSwapVendorPrivateWithReply(__GLXclientState *cl, GLbyte *pc) +{ + xGLXVendorPrivateWithReplyReq *req; + CARD32 vendorCode; + + __GLX_DECLARE_SWAP_VARIABLES; + + req = (xGLXVendorPrivateWithReplyReq *) pc; + vendorCode = req->vendorCode; + __GLX_SWAP_INT(&vendorCode); + + switch( vendorCode ) { + + case X_GLvop_GetConvolutionFilterEXT: + case X_GLvop_GetSeparableFilterEXT: + case X_GLvop_GetHistogramEXT: + case X_GLvop_GetMinmaxEXT: + return( __glXNoSuchSingleOpcode(cl, pc) ); + break; + + case X_GLvop_GetConvolutionParameterfvEXT: + case X_GLvop_GetConvolutionParameterivEXT: + case X_GLvop_GetHistogramParameterivEXT: + case X_GLvop_GetMinmaxParameterfvEXT: + case X_GLvop_GetMinmaxParameterivEXT: + case X_GLvop_GenTexturesEXT: + return( __glXVForwardAllWithReplySwapiv(cl, pc) ); + break; + + case X_GLvop_AreTexturesResidentEXT: + case X_GLvop_IsTextureEXT: + return( __glXVForwardPipe0WithReplySwap(cl, pc) ); + break; + +#if 0 /* glx1.3 */ + case X_GLvop_GetDetailTexFuncSGIS: + case X_GLvop_GetSharpenTexFuncSGIS: + case X_GLvop_GetColorTableSGI: + case X_GLvop_GetColorTableParameterfvSGI: + case X_GLvop_GetColorTableParameterivSGI: + case X_GLvop_GetTexFilterFuncSGIS: + case X_GLvop_GetInstrumentsSGIX: + case X_GLvop_InstrumentsBufferSGIX: + case X_GLvop_PollInstrumentsSGIX: + case X_GLvop_FlushRasterSGIX: + case X_GLXvop_CreateGLXPbufferSGIX: + case X_GLXvop_GetDrawableAttributesSGIX: + case X_GLXvop_QueryHyperpipeNetworkSGIX: + case X_GLXvop_QueryHyperpipeConfigSGIX: + case X_GLXvop_HyperpipeConfigSGIX: + case X_GLXvop_DestroyHyperpipeConfigSGIX: +#endif + case X_GLXvop_QueryMaxSwapBarriersSGIX: + return( __glXSwapQueryMaxSwapBarriersSGIX(cl, pc) ); + break; + + case X_GLXvop_GetFBConfigsSGIX: + return( __glXSwapGetFBConfigsSGIX(cl, pc) ); + break; + + case X_GLXvop_MakeCurrentReadSGI: + return( __glXSwapMakeCurrentReadSGI(cl, pc) ); + break; + + case X_GLXvop_QueryContextInfoEXT: + return( __glXSwapQueryContextInfoEXT(cl,(char *)pc) ); + break; + + default: + /* + ** unsupported private request + */ + cl->client->errorValue = req->vendorCode; + return __glXUnsupportedPrivateRequest; + } + +} + +int __glXSwapGetFBConfigs(__GLXclientState *cl, GLbyte *pc) +{ + xGLXGetFBConfigsReq *req = (xGLXGetFBConfigsReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->screen); + + return __glXGetFBConfigs(cl, pc); +} + +int __glXSwapGetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc) +{ + xGLXGetFBConfigsSGIXReq *req = (xGLXGetFBConfigsSGIXReq *)pc; + xGLXGetFBConfigsReq new_req; + + new_req.reqType = req->reqType; + new_req.glxCode = req->glxCode; + new_req.length = req->length; + new_req.screen = req->screen; + + return( __glXSwapGetFBConfigs( cl, (GLbyte *)&new_req ) ); +} + +int __glXSwapCreateWindow(__GLXclientState *cl, GLbyte *pc) +{ + xGLXCreateWindowReq *req = (xGLXCreateWindowReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->screen); + __GLX_SWAP_INT(&req->fbconfig); + __GLX_SWAP_INT(&req->window); + __GLX_SWAP_INT(&req->glxwindow); + __GLX_SWAP_INT(&req->numAttribs); + + return( __glXCreateWindow( cl, (GLbyte *)pc ) ); +} + +int __glXSwapDestroyWindow(__GLXclientState *cl, GLbyte *pc) +{ + xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->glxwindow); + + return( __glXDestroyWindow( cl, (GLbyte *)pc ) ); +} + +int __glXSwapQueryContext(__GLXclientState *cl, GLbyte *pc) +{ + xGLXQueryContextReq *req = (xGLXQueryContextReq *)pc; + + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->context); + + return( __glXQueryContext(cl, (GLbyte *)pc) ); + +} + +int __glXSwapCreatePbuffer(__GLXclientState *cl, GLbyte *pc) +{ + xGLXCreatePbufferReq *req = (xGLXCreatePbufferReq *)pc; + int nattr = req->numAttribs; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->screen); + __GLX_SWAP_INT(&req->fbconfig); + __GLX_SWAP_INT(&req->pbuffer); + __GLX_SWAP_INT(&req->numAttribs); + __GLX_SWAP_INT_ARRAY( (int *)(req+1), nattr*2 ); + + return( __glXCreatePbuffer( cl, pc ) ); +} + +int __glXSwapDestroyPbuffer(__GLXclientState *cl, GLbyte *pc) +{ + xGLXDestroyPbufferReq *req = (xGLXDestroyPbufferReq *) pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->pbuffer); + + return( __glXDestroyPbuffer( cl, (GLbyte *)pc ) ); +} + +int __glXSwapGetDrawableAttributes(__GLXclientState *cl, GLbyte *pc) +{ + xGLXGetDrawableAttributesReq *req = (xGLXGetDrawableAttributesReq *)pc; + __GLX_DECLARE_SWAP_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->drawable); + + return( __glXGetDrawableAttributes(cl, pc) ); +} + +int __glXSwapChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc) +{ + xGLXChangeDrawableAttributesReq *req = (xGLXChangeDrawableAttributesReq *)pc; + __GLX_DECLARE_SWAP_VARIABLES; + __GLX_DECLARE_SWAP_ARRAY_VARIABLES; + + __GLX_SWAP_SHORT(&req->length); + __GLX_SWAP_INT(&req->drawable); + __GLX_SWAP_INT(&req->numAttribs); + __GLX_SWAP_INT_ARRAY( (int *)(req+1), req->numAttribs * 2 ); + + return( __glXChangeDrawableAttributes(cl, pc) ); +} diff --git a/xorg-server/hw/dmx/glxProxy/glxscreens.c b/xorg-server/hw/dmx/glxProxy/glxscreens.c index 01e041c8f..baa4a65a7 100644 --- a/xorg-server/hw/dmx/glxProxy/glxscreens.c +++ b/xorg-server/hw/dmx/glxProxy/glxscreens.c @@ -120,8 +120,9 @@ static void CalcServerVersionAndExtensions( void ) __glXVersionMinor = GLX_SERVER_MINOR_VERSION; } - sprintf(GLXServerVersion, "%d.%d DMX %d back-end server(s)", - __glXVersionMajor, __glXVersionMinor, __glXNumActiveScreens ); + snprintf(GLXServerVersion, sizeof(GLXServerVersion), + "%d.%d DMX %d back-end server(s)", + __glXVersionMajor, __glXVersionMinor, __glXNumActiveScreens ); /* * set the ExtensionsString to the minimum extensions string */ diff --git a/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.c b/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.c index 94feb7826..69ad8a517 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.c +++ b/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.c @@ -1,1015 +1,1016 @@ -/*
- * Xephyr - A kdrive X server thats runs in a host X window.
- * Authored by Matthew Allum <mallum@openedhand.com>
- *
- * Copyright © 2007 OpenedHand Ltd
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of OpenedHand Ltd not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. OpenedHand Ltd makes no
- * representations about the suitability of this software for any purpose. It
- * is provided "as is" without express or implied warranty.
- *
- * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:
- * Dodji Seketeli <dodji@openedhand.com>
- */
-#ifdef HAVE_CONFIG_H
-#include <kdrive-config.h>
-#endif
-/*
- * including some server headers (like kdrive-config.h)
- * might define the macro _XSERVER64
- * on 64 bits machines. That macro must _NOT_ be defined for Xlib
- * client code, otherwise bad things happen.
- * So let's undef that macro if necessary.
- */
-#ifdef _XSERVER64
-#undef _XSERVER64
-#endif
-#include <X11/Xutil.h>
-#include <X11/Xlibint.h>
-#include <X11/extensions/Xvlib.h>
-#include <X11/extensions/Xvproto.h>
-#include <X11/extensions/Xext.h>
-#include <X11/extensions/extutil.h>
-#define _HAVE_XALLOC_DECLS
-
-#include "hostx.h"
-#include "ephyrhostvideo.h"
-#include "ephyrlog.h"
-
-#ifndef TRUE
-#define TRUE 1
-#endif /*TRUE*/
-
-#ifndef FALSE
-#define FALSE 0
-#endif /*FALSE*/
-
-static XExtensionInfo _xv_info_data;
-static XExtensionInfo *xv_info = &_xv_info_data;
-static char *xv_extension_name = XvName;
-static char *xv_error_string(Display *dpy, int code, XExtCodes *codes,
- char * buf, int n);
-static int xv_close_display(Display *dpy, XExtCodes *codes);
-static Bool xv_wire_to_event(Display *dpy, XEvent *host, xEvent *wire);
-
-static XExtensionHooks xv_extension_hooks = {
- NULL, /* create_gc */
- NULL, /* copy_gc */
- NULL, /* flush_gc */
- NULL, /* free_gc */
- NULL, /* create_font */
- NULL, /* free_font */
- xv_close_display, /* close_display */
- xv_wire_to_event, /* wire_to_event */
- NULL, /* event_to_wire */
- NULL, /* error */
- xv_error_string /* error_string */
-};
-
-
-static char *xv_error_list[] =
-{
- "BadPort", /* XvBadPort */
- "BadEncoding", /* XvBadEncoding */
- "BadControl" /* XvBadControl */
-};
-
-
-#define XvCheckExtension(dpy, i, val) \
- XextCheckExtension(dpy, i, xv_extension_name, val)
-#define XvGetReq(name, req) \
- WORD64ALIGN\
- if ((dpy->bufptr + SIZEOF(xv##name##Req)) > dpy->bufmax)\
- _XFlush(dpy);\
- req = (xv##name##Req *)(dpy->last_req = dpy->bufptr);\
- req->reqType = info->codes->major_opcode;\
- req->xvReqType = xv_##name; \
- req->length = (SIZEOF(xv##name##Req))>>2;\
- dpy->bufptr += SIZEOF(xv##name##Req);\
- dpy->request++
-
-static XEXT_GENERATE_CLOSE_DISPLAY (xv_close_display, xv_info)
-
-
-static XEXT_GENERATE_FIND_DISPLAY (xv_find_display, xv_info,
- xv_extension_name,
- &xv_extension_hooks,
- XvNumEvents, NULL)
-
-static XEXT_GENERATE_ERROR_STRING (xv_error_string, xv_extension_name,
- XvNumErrors, xv_error_list)
-
-struct _EphyrHostXVAdaptorArray {
- XvAdaptorInfo *adaptors ;
- unsigned int nb_adaptors ;
-};
-
-/*heavily copied from libx11*/
-#define BUFSIZE 2048
-static void
-ephyrHostXVLogXErrorEvent (Display *a_display,
- XErrorEvent *a_err_event,
- FILE *a_fp)
-{
- char buffer[BUFSIZ];
- char mesg[BUFSIZ];
- char number[32];
- const char *mtype = "XlibMessage";
- register _XExtension *ext = (_XExtension *)NULL;
- _XExtension *bext = (_XExtension *)NULL;
- Display *dpy = a_display ;
-
- XGetErrorText(dpy, a_err_event->error_code, buffer, BUFSIZ);
- XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
- (void) fprintf(a_fp, "%s: %s\n ", mesg, buffer);
- XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
- mesg, BUFSIZ);
- (void) fprintf(a_fp, mesg, a_err_event->request_code);
- if (a_err_event->request_code < 128) {
- sprintf(number, "%d", a_err_event->request_code);
- XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
- } else {
- for (ext = dpy->ext_procs;
- ext && (ext->codes.major_opcode != a_err_event->request_code);
- ext = ext->next)
- ;
- if (ext)
- strcpy(buffer, ext->name);
- else
- buffer[0] = '\0';
- }
- (void) fprintf(a_fp, " (%s)\n", buffer);
- if (a_err_event->request_code >= 128) {
- XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
- mesg, BUFSIZ);
- fputs(" ", a_fp);
- (void) fprintf(a_fp, mesg, a_err_event->minor_code);
- if (ext) {
- sprintf(mesg, "%s.%d", ext->name, a_err_event->minor_code);
- XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
- (void) fprintf(a_fp, " (%s)", buffer);
- }
- fputs("\n", a_fp);
- }
- if (a_err_event->error_code >= 128) {
- /* kludge, try to find the extension that caused it */
- buffer[0] = '\0';
- for (ext = dpy->ext_procs; ext; ext = ext->next) {
- if (ext->error_string)
- (*ext->error_string)(dpy, a_err_event->error_code, &ext->codes,
- buffer, BUFSIZ);
- if (buffer[0]) {
- bext = ext;
- break;
- }
- if (ext->codes.first_error &&
- ext->codes.first_error < (int)a_err_event->error_code &&
- (!bext || ext->codes.first_error > bext->codes.first_error))
- bext = ext;
- }
- if (bext)
- sprintf(buffer, "%s.%d", bext->name,
- a_err_event->error_code - bext->codes.first_error);
- else
- strcpy(buffer, "Value");
- XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
- if (mesg[0]) {
- fputs(" ", a_fp);
- (void) fprintf(a_fp, mesg, a_err_event->resourceid);
- fputs("\n", a_fp);
- }
- /* let extensions try to print the values */
- for (ext = dpy->ext_procs; ext; ext = ext->next) {
- if (ext->error_values)
- (*ext->error_values)(dpy, a_err_event, a_fp);
- }
- } else if ((a_err_event->error_code == BadWindow) ||
- (a_err_event->error_code == BadPixmap) ||
- (a_err_event->error_code == BadCursor) ||
- (a_err_event->error_code == BadFont) ||
- (a_err_event->error_code == BadDrawable) ||
- (a_err_event->error_code == BadColor) ||
- (a_err_event->error_code == BadGC) ||
- (a_err_event->error_code == BadIDChoice) ||
- (a_err_event->error_code == BadValue) ||
- (a_err_event->error_code == BadAtom)) {
- if (a_err_event->error_code == BadValue)
- XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
- mesg, BUFSIZ);
- else if (a_err_event->error_code == BadAtom)
- XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
- mesg, BUFSIZ);
- else
- XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
- mesg, BUFSIZ);
- fputs(" ", a_fp);
- (void) fprintf(a_fp, mesg, a_err_event->resourceid);
- fputs("\n", a_fp);
- }
- XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
- mesg, BUFSIZ);
- fputs(" ", a_fp);
- (void) fprintf(a_fp, mesg, a_err_event->serial);
- XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
- mesg, BUFSIZ);
- fputs("\n ", a_fp);
- (void) fprintf(a_fp, mesg, dpy->request);
- fputs("\n", a_fp);
-}
-
-static int
-ephyrHostXVErrorHandler (Display *a_display,
- XErrorEvent *a_error_event)
-{
- EPHYR_LOG_ERROR ("got an error from the host xserver:\n") ;
- ephyrHostXVLogXErrorEvent (a_display, a_error_event, stderr) ;
- return Success ;
-}
-
-void
-ephyrHostXVInit (void)
-{
- static Bool s_initialized ;
-
- if (s_initialized)
- return ;
- XSetErrorHandler (ephyrHostXVErrorHandler) ;
- s_initialized = TRUE ;
-}
-
-Bool
-ephyrHostXVQueryAdaptors (EphyrHostXVAdaptorArray **a_adaptors)
-{
- EphyrHostXVAdaptorArray *result=NULL ;
- int ret=0 ;
- Bool is_ok=FALSE ;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_adaptors, FALSE) ;
-
- EPHYR_LOG ("enter\n") ;
-
- result = calloc (1, sizeof (EphyrHostXVAdaptorArray)) ;
- if (!result)
- goto out ;
-
- ret = XvQueryAdaptors (hostx_get_display (),
- DefaultRootWindow (hostx_get_display ()),
- &result->nb_adaptors,
- &result->adaptors) ;
- if (ret != Success) {
- EPHYR_LOG_ERROR ("failed to query host adaptors: %d\n", ret) ;
- goto out ;
- }
- *a_adaptors = result ;
- is_ok = TRUE ;
-
-out:
- EPHYR_LOG ("leave\n") ;
- return is_ok ;
-}
-
-void
-ephyrHostXVAdaptorArrayDelete (EphyrHostXVAdaptorArray *a_adaptors)
-{
- if (!a_adaptors)
- return ;
- if (a_adaptors->adaptors) {
- XvFreeAdaptorInfo (a_adaptors->adaptors) ;
- a_adaptors->adaptors = NULL ;
- a_adaptors->nb_adaptors = 0 ;
- }
- XFree (a_adaptors) ;
-}
-
-int
-ephyrHostXVAdaptorArrayGetSize (const EphyrHostXVAdaptorArray *a_this)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this, -1) ;
- return a_this->nb_adaptors ;
-}
-
-EphyrHostXVAdaptor*
-ephyrHostXVAdaptorArrayAt (const EphyrHostXVAdaptorArray *a_this,
- int a_index)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this, NULL) ;
-
- if (a_index >= a_this->nb_adaptors)
- return NULL ;
- return (EphyrHostXVAdaptor*)&a_this->adaptors[a_index] ;
-}
-
-char
-ephyrHostXVAdaptorGetType (const EphyrHostXVAdaptor *a_this)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this, -1) ;
- return ((XvAdaptorInfo*)a_this)->type ;
-}
-
-const char*
-ephyrHostXVAdaptorGetName (const EphyrHostXVAdaptor *a_this)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this, NULL) ;
-
- return ((XvAdaptorInfo*)a_this)->name ;
-}
-
-EphyrHostVideoFormat*
-ephyrHostXVAdaptorGetVideoFormats (const EphyrHostXVAdaptor *a_this,
- int *a_nb_formats)
-{
- EphyrHostVideoFormat *formats=NULL ;
- int nb_formats=0, i=0 ;
- XVisualInfo *visual_info, visual_info_template ;
- int nb_visual_info ;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_this, NULL) ;
-
- nb_formats = ((XvAdaptorInfo*)a_this)->num_formats ;
- formats = calloc (nb_formats, sizeof (EphyrHostVideoFormat)) ;
- for (i=0; i < nb_formats; i++) {
- memset (&visual_info_template, 0, sizeof (visual_info_template)) ;
- visual_info_template.visualid =
- ((XvAdaptorInfo*)a_this)->formats[i].visual_id;
- visual_info = XGetVisualInfo (hostx_get_display (),
- VisualIDMask,
- &visual_info_template,
- &nb_visual_info) ;
- formats[i].depth = ((XvAdaptorInfo*)a_this)->formats[i].depth ;
- formats[i].visual_class = visual_info->class ;
- XFree (visual_info) ;
- }
- if (a_nb_formats)
- *a_nb_formats = nb_formats ;
- return formats ;
-}
-
-int
-ephyrHostXVAdaptorGetNbPorts (const EphyrHostXVAdaptor *a_this)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this, -1) ;
-
- return ((XvAdaptorInfo*)a_this)->num_ports ;
-}
-
-int
-ephyrHostXVAdaptorGetFirstPortID (const EphyrHostXVAdaptor *a_this)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this, -1) ;
-
- return ((XvAdaptorInfo*)a_this)->base_id ;
-}
-
-Bool
-ephyrHostXVAdaptorHasPutVideo (const EphyrHostXVAdaptor *a_this,
- Bool *a_result)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this && a_result, FALSE) ;
-
- if ((((XvAdaptorInfo*)a_this)->type & (XvVideoMask | XvInputMask)) ==
- (XvVideoMask | XvInputMask))
- *a_result = TRUE ;
- else
- *a_result = FALSE ;
- return TRUE ;
-}
-
-Bool
-ephyrHostXVAdaptorHasGetVideo (const EphyrHostXVAdaptor *a_this,
- Bool *a_result)
-{
- if ((((XvAdaptorInfo*)a_this)->type & (XvVideoMask | XvOutputMask)) ==
- (XvVideoMask | XvOutputMask))
- *a_result = TRUE ;
- else
- *a_result = FALSE ;
- return TRUE ;
-}
-
-Bool
-ephyrHostXVAdaptorHasPutStill (const EphyrHostXVAdaptor *a_this,
- Bool *a_result)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this && a_result, FALSE) ;
-
- if ((((XvAdaptorInfo*)a_this)->type & (XvStillMask | XvInputMask)) ==
- (XvStillMask | XvInputMask))
- *a_result = TRUE ;
- else
- *a_result = FALSE ;
- return TRUE ;
-}
-
-Bool
-ephyrHostXVAdaptorHasGetStill (const EphyrHostXVAdaptor *a_this,
- Bool *a_result)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this && a_result, FALSE) ;
-
- if ((((XvAdaptorInfo*)a_this)->type & (XvStillMask | XvOutputMask)) ==
- (XvStillMask | XvOutputMask))
- *a_result = TRUE ;
- else
- *a_result = FALSE ;
- return TRUE ;
-}
-
-Bool
-ephyrHostXVAdaptorHasPutImage (const EphyrHostXVAdaptor *a_this,
- Bool *a_result)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_this && a_result, FALSE) ;
-
- if ((((XvAdaptorInfo*)a_this)->type & (XvImageMask | XvInputMask)) ==
- (XvImageMask | XvInputMask))
- *a_result = TRUE ;
- else
- *a_result = FALSE ;
- return TRUE ;
-}
-
-Bool
-ephyrHostXVQueryEncodings (int a_port_id,
- EphyrHostEncoding **a_encodings,
- unsigned int *a_num_encodings)
-{
- EphyrHostEncoding *encodings=NULL ;
- XvEncodingInfo *encoding_info=NULL ;
- unsigned int num_encodings=0, i;
- int ret=0 ;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_encodings && a_num_encodings, FALSE) ;
-
- ret = XvQueryEncodings (hostx_get_display (),
- a_port_id,
- &num_encodings,
- &encoding_info) ;
- if (num_encodings && encoding_info) {
- encodings = calloc (num_encodings, sizeof (EphyrHostEncoding)) ;
- for (i=0; i<num_encodings; i++) {
- encodings[i].id = encoding_info[i].encoding_id ;
- encodings[i].name = strdup (encoding_info[i].name) ;
- encodings[i].width = encoding_info[i].width ;
- encodings[i].height = encoding_info[i].height ;
- encodings[i].rate.numerator = encoding_info[i].rate.numerator ;
- encodings[i].rate.denominator = encoding_info[i].rate.denominator ;
- }
- }
- if (encoding_info) {
- XvFreeEncodingInfo (encoding_info) ;
- encoding_info = NULL ;
- }
- *a_encodings = encodings ;
- *a_num_encodings = num_encodings ;
-
- if (ret != Success)
- return FALSE ;
- return TRUE ;
-}
-
-void
-ephyrHostEncodingsDelete (EphyrHostEncoding *a_encodings,
- int a_num_encodings)
-{
- int i=0 ;
-
- if (!a_encodings)
- return ;
- for (i=0; i < a_num_encodings; i++) {
- free(a_encodings[i].name) ;
- a_encodings[i].name = NULL ;
- }
- free(a_encodings) ;
-}
-
-void
-ephyrHostAttributesDelete (EphyrHostAttribute *a_attributes)
-{
- if (!a_attributes)
- return ;
- XFree (a_attributes) ;
-}
-
-Bool
-ephyrHostXVQueryPortAttributes (int a_port_id,
- EphyrHostAttribute **a_attributes,
- int *a_num_attributes)
-{
- EPHYR_RETURN_VAL_IF_FAIL (a_attributes && a_num_attributes, FALSE) ;
-
- *a_attributes =
- (EphyrHostAttribute*)XvQueryPortAttributes (hostx_get_display (),
- a_port_id,
- a_num_attributes);
-
- return TRUE ;
-}
-
-Bool
-ephyrHostXVQueryImageFormats (int a_port_id,
- EphyrHostImageFormat **a_formats,
- int *a_num_format)
-{
- XvImageFormatValues *result=NULL ;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_formats && a_num_format, FALSE) ;
-
- result = XvListImageFormats (hostx_get_display (),
- a_port_id,
- a_num_format) ;
- *a_formats = (EphyrHostImageFormat*) result ;
- return TRUE ;
-
-}
-
-Bool
-ephyrHostXVSetPortAttribute (int a_port_id,
- int a_atom,
- int a_attr_value)
-{
- int res=Success ;
-
- EPHYR_LOG ("atom,name,value: (%d,%s,%d)\n",
- a_atom,
- XGetAtomName (hostx_get_display (), a_atom),
- a_attr_value) ;
-
- res = XvSetPortAttribute (hostx_get_display (),
- a_port_id,
- a_atom,
- a_attr_value) ;
- if (res != Success) {
- EPHYR_LOG_ERROR ("XvSetPortAttribute() failed: %d\n", res) ;
- return FALSE ;
- }
- XFlush (hostx_get_display ()) ;
- EPHYR_LOG ("leave\n") ;
-
- return TRUE ;
-}
-
-Bool
-ephyrHostXVGetPortAttribute (int a_port_id,
- int a_atom,
- int *a_attr_value)
-{
- int res=Success ;
- Bool ret=FALSE ;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_attr_value, FALSE) ;
-
- EPHYR_LOG ("enter, a_port_id: %d, a_atomid: %d, attr_name: %s\n",
- a_port_id, a_atom, XGetAtomName (hostx_get_display (), a_atom)) ;
-
- res = XvGetPortAttribute (hostx_get_display (),
- a_port_id,
- a_atom,
- a_attr_value) ;
- if (res != Success) {
- EPHYR_LOG_ERROR ("XvGetPortAttribute() failed: %d \n", res) ;
- goto out ;
- }
- EPHYR_LOG ("atom,value: (%d, %d)\n", a_atom, *a_attr_value) ;
-
- ret = TRUE ;
-
-out:
- EPHYR_LOG ("leave\n") ;
- return ret ;
-}
-
-Bool
-ephyrHostXVQueryBestSize (int a_port_id,
- Bool a_motion,
- unsigned int a_frame_w,
- unsigned int a_frame_h,
- unsigned int a_drw_w,
- unsigned int a_drw_h,
- unsigned int *a_actual_w,
- unsigned int *a_actual_h)
-{
- int res=0 ;
- Bool is_ok=FALSE ;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_actual_w && a_actual_h, FALSE) ;
-
- EPHYR_LOG ("enter: frame (%dx%d), drw (%dx%d)\n",
- a_frame_w, a_frame_h,
- a_drw_w, a_drw_h) ;
-
- res = XvQueryBestSize (hostx_get_display (),
- a_port_id,
- a_motion,
- a_frame_w, a_frame_h,
- a_drw_w, a_drw_h,
- a_actual_w, a_actual_h) ;
- if (res != Success) {
- EPHYR_LOG_ERROR ("XvQueryBestSize() failed: %d\n", res) ;
- goto out ;
- }
- XSync (hostx_get_display (), FALSE) ;
-
- EPHYR_LOG ("actual (%dx%d)\n", *a_actual_w, *a_actual_h) ;
- is_ok = TRUE ;
-
-out:
- EPHYR_LOG ("leave\n") ;
- return is_ok ;
-}
-
-static Bool
-xv_wire_to_event(Display *dpy, XEvent *host, xEvent *wire)
-{
- XExtDisplayInfo *info = xv_find_display (dpy);
- XvEvent *re = (XvEvent *)host;
- xvEvent *event = (xvEvent *)wire;
-
- XvCheckExtension(dpy, info, False);
-
- switch ((event->u.u.type & 0x7F) - info->codes->first_event) {
- case XvVideoNotify:
- re->xvvideo.type = event->u.u.type & 0x7f;
- re->xvvideo.serial =
- _XSetLastRequestRead(dpy, (xGenericReply *)event);
- re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0);
- re->xvvideo.display = dpy;
- re->xvvideo.time = event->u.videoNotify.time;
- re->xvvideo.reason = event->u.videoNotify.reason;
- re->xvvideo.drawable = event->u.videoNotify.drawable;
- re->xvvideo.port_id = event->u.videoNotify.port;
- break;
- case XvPortNotify:
- re->xvport.type = event->u.u.type & 0x7f;
- re->xvport.serial =
- _XSetLastRequestRead(dpy, (xGenericReply *)event);
- re->xvport.send_event = ((event->u.u.type & 0x80) != 0);
- re->xvport.display = dpy;
- re->xvport.time = event->u.portNotify.time;
- re->xvport.port_id = event->u.portNotify.port;
- re->xvport.attribute = event->u.portNotify.attribute;
- re->xvport.value = event->u.portNotify.value;
- break;
- default:
- return False;
- }
-
- return True ;
-}
-
-Bool
-ephyrHostXVQueryImageAttributes (int a_port_id,
- int a_image_id /*image fourcc code*/,
- unsigned short *a_width,
- unsigned short *a_height,
- int *a_image_size,
- int *a_pitches,
- int *a_offsets)
-{
- Display *dpy = hostx_get_display () ;
- Bool ret=FALSE ;
- XExtDisplayInfo *info = xv_find_display (dpy);
- xvQueryImageAttributesReq *req=NULL;
- xvQueryImageAttributesReply rep;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_width, FALSE) ;
- EPHYR_RETURN_VAL_IF_FAIL (a_height, FALSE) ;
- EPHYR_RETURN_VAL_IF_FAIL (a_image_size, FALSE) ;
-
- XvCheckExtension (dpy, info, FALSE);
-
- LockDisplay (dpy);
-
- XvGetReq (QueryImageAttributes, req);
- req->id = a_image_id;
- req->port = a_port_id;
- req->width = *a_width;
- req->height = *a_height;
- /*
- * read the reply
- */
- if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) {
- EPHYR_LOG_ERROR ("QeryImageAttribute req failed\n") ;
- goto out ;
- }
- if (a_pitches && a_offsets) {
- _XRead (dpy,
- (char*)a_pitches,
- rep.num_planes << 2);
- _XRead (dpy,
- (char*)a_offsets,
- rep.num_planes << 2);
- } else {
- _XEatData(dpy, rep.length << 2);
- }
- *a_width = rep.width ;
- *a_height = rep.height ;
- *a_image_size = rep.data_size ;
-
- ret = TRUE ;
-
-out:
- UnlockDisplay (dpy) ;
- SyncHandle ();
- return ret ;
-}
-
-Bool
-ephyrHostGetAtom (const char* a_name,
- Bool a_create_if_not_exists,
- int *a_atom)
-{
- int atom=None ;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_atom, FALSE) ;
-
- atom = XInternAtom (hostx_get_display (), a_name, a_create_if_not_exists);
- if (atom == None) {
- return FALSE ;
- }
- *a_atom = atom ;
- return TRUE ;
-}
-
-char*
-ephyrHostGetAtomName (int a_atom)
-{
- return XGetAtomName (hostx_get_display (), a_atom) ;
-}
-
-void
-ephyrHostFree (void *a_pointer)
-{
- if (a_pointer)
- XFree (a_pointer) ;
-}
-
-Bool
-ephyrHostXVPutImage (int a_screen_num,
- int a_port_id,
- int a_image_id,
- int a_drw_x,
- int a_drw_y,
- int a_drw_w,
- int a_drw_h,
- int a_src_x,
- int a_src_y,
- int a_src_w,
- int a_src_h,
- int a_image_width,
- int a_image_height,
- unsigned char *a_buf,
- EphyrHostBox *a_clip_rects,
- int a_clip_rect_nums )
-{
- Bool is_ok=TRUE ;
- XvImage *xv_image=NULL ;
- GC gc=0 ;
- XGCValues gc_values;
- Display *dpy = hostx_get_display () ;
- XRectangle *rects=NULL ;
- int res = 0 ;
-
- EPHYR_RETURN_VAL_IF_FAIL (a_buf, FALSE) ;
-
- EPHYR_LOG ("enter, num_clip_rects: %d\n", a_clip_rect_nums) ;
-
- memset (&gc_values, 0, sizeof (gc_values)) ;
- gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values);
- if (!gc) {
- EPHYR_LOG_ERROR ("failed to create gc \n") ;
- goto out ;
- }
- xv_image = (XvImage*) XvCreateImage (hostx_get_display (),
- a_port_id, a_image_id,
- NULL, a_image_width, a_image_height) ;
- if (!xv_image) {
- EPHYR_LOG_ERROR ("failed to create image\n") ;
- goto out ;
- }
- xv_image->data = (char*)a_buf ;
- if (a_clip_rect_nums) {
- int i=0 ;
- rects = calloc (a_clip_rect_nums, sizeof (XRectangle)) ;
- for (i=0; i < a_clip_rect_nums; i++) {
- rects[i].x = a_clip_rects[i].x1 ;
- rects[i].y = a_clip_rects[i].y1 ;
- rects[i].width = a_clip_rects[i].x2 - a_clip_rects[i].x1;
- rects[i].height = a_clip_rects[i].y2 - a_clip_rects[i].y1;
- EPHYR_LOG ("(x,y,w,h): (%d,%d,%d,%d)\n",
- rects[i].x, rects[i].y,
- rects[i].width, rects[i].height) ;
- }
- XSetClipRectangles (dpy, gc, 0, 0, rects, a_clip_rect_nums, YXBanded) ;
- /*this always returns 1*/
- }
- res = XvPutImage (dpy, a_port_id,
- hostx_get_window (a_screen_num),
- gc, xv_image,
- a_src_x, a_src_y, a_src_w, a_src_h,
- a_drw_x, a_drw_y, a_drw_w, a_drw_h) ;
- if (res != Success) {
- EPHYR_LOG_ERROR ("XvPutImage() failed: %d\n", res) ;
- goto out ;
- }
- is_ok = TRUE ;
-
-out:
- if (xv_image) {
- XFree (xv_image) ;
- xv_image = NULL ;
- }
- if (gc) {
- XFreeGC (dpy, gc) ;
- gc = NULL ;
- }
- free(rects);
- rects = NULL;
- EPHYR_LOG ("leave\n") ;
- return is_ok ;
-}
-
-Bool
-ephyrHostXVPutVideo (int a_screen_num, int a_port_id,
- int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
- int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
- Bool is_ok=FALSE ;
- int res=FALSE ;
- GC gc=0 ;
- XGCValues gc_values;
- Display *dpy=hostx_get_display () ;
-
- EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ;
-
- gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values);
- if (!gc) {
- EPHYR_LOG_ERROR ("failed to create gc \n") ;
- goto out ;
- }
- res = XvPutVideo (dpy, a_port_id, hostx_get_window (a_screen_num), gc,
- a_vid_x, a_vid_y, a_vid_w, a_vid_h,
- a_drw_x, a_drw_y, a_drw_w, a_drw_h) ;
-
- if (res != Success) {
- EPHYR_LOG_ERROR ("XvPutVideo() failed: %d\n", res) ;
- goto out ;
- }
-
- is_ok = TRUE ;
-
-out:
- if (gc) {
- XFreeGC (dpy, gc) ;
- gc = NULL ;
- }
- return is_ok ;
-}
-
-Bool
-ephyrHostXVGetVideo (int a_screen_num, int a_port_id,
- int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
- int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
- Bool is_ok=FALSE ;
- int res=FALSE ;
- GC gc=0 ;
- XGCValues gc_values;
- Display *dpy=hostx_get_display () ;
-
- EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ;
-
- gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values);
- if (!gc) {
- EPHYR_LOG_ERROR ("failed to create gc \n") ;
- goto out ;
- }
- res = XvGetVideo (dpy, a_port_id, hostx_get_window (a_screen_num), gc,
- a_vid_x, a_vid_y, a_vid_w, a_vid_h,
- a_drw_x, a_drw_y, a_drw_w, a_drw_h) ;
-
- if (res != Success) {
- EPHYR_LOG_ERROR ("XvGetVideo() failed: %d\n", res) ;
- goto out ;
- }
-
- is_ok = TRUE ;
-
-out:
- if (gc) {
- XFreeGC (dpy, gc) ;
- gc = NULL ;
- }
- return is_ok ;
-}
-
-Bool
-ephyrHostXVPutStill (int a_screen_num, int a_port_id,
- int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
- int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
- Bool is_ok=FALSE ;
- int res=FALSE ;
- GC gc=0 ;
- XGCValues gc_values;
- Display *dpy=hostx_get_display () ;
-
- EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ;
-
- gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values);
- if (!gc) {
- EPHYR_LOG_ERROR ("failed to create gc \n") ;
- goto out ;
- }
- res = XvPutStill (dpy, a_port_id, hostx_get_window (a_screen_num), gc,
- a_vid_x, a_vid_y, a_vid_w, a_vid_h,
- a_drw_x, a_drw_y, a_drw_w, a_drw_h) ;
-
- if (res != Success) {
- EPHYR_LOG_ERROR ("XvPutStill() failed: %d\n", res) ;
- goto out ;
- }
-
- is_ok = TRUE ;
-
-out:
- if (gc) {
- XFreeGC (dpy, gc) ;
- gc = NULL ;
- }
- return is_ok ;
-}
-
-Bool
-ephyrHostXVGetStill (int a_screen_num, int a_port_id,
- int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
- int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
- Bool is_ok=FALSE ;
- int res=FALSE ;
- GC gc=0 ;
- XGCValues gc_values;
- Display *dpy=hostx_get_display () ;
-
- EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ;
-
- gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values);
- if (!gc) {
- EPHYR_LOG_ERROR ("failed to create gc \n") ;
- goto out ;
- }
- res = XvGetStill (dpy, a_port_id, hostx_get_window (a_screen_num), gc,
- a_vid_x, a_vid_y, a_vid_w, a_vid_h,
- a_drw_x, a_drw_y, a_drw_w, a_drw_h) ;
-
- if (res != Success) {
- EPHYR_LOG_ERROR ("XvGetStill() failed: %d\n", res) ;
- goto out ;
- }
-
- is_ok = TRUE ;
-
-out:
- if (gc) {
- XFreeGC (dpy, gc) ;
- gc = NULL ;
- }
- return is_ok ;
-}
-
-Bool
-ephyrHostXVStopVideo (int a_screen_num, int a_port_id)
-{
- int ret=0 ;
- Bool is_ok=FALSE ;
- Display *dpy = hostx_get_display () ;
-
- EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ;
-
- EPHYR_LOG ("enter\n") ;
-
- ret = XvStopVideo (dpy, a_port_id, hostx_get_window (a_screen_num)) ;
- if (ret != Success) {
- EPHYR_LOG_ERROR ("XvStopVideo() failed: %d \n", ret) ;
- goto out ;
- }
- is_ok = TRUE ;
-
-out:
- EPHYR_LOG ("leave\n") ;
- return is_ok ;
-}
-
+/* + * Xephyr - A kdrive X server thats runs in a host X window. + * Authored by Matthew Allum <mallum@openedhand.com> + * + * Copyright © 2007 OpenedHand Ltd + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of OpenedHand Ltd not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. OpenedHand Ltd makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * Authors: + * Dodji Seketeli <dodji@openedhand.com> + */ +#ifdef HAVE_CONFIG_H +#include <kdrive-config.h> +#endif +/* + * including some server headers (like kdrive-config.h) + * might define the macro _XSERVER64 + * on 64 bits machines. That macro must _NOT_ be defined for Xlib + * client code, otherwise bad things happen. + * So let's undef that macro if necessary. + */ +#ifdef _XSERVER64 +#undef _XSERVER64 +#endif +#include <X11/Xutil.h> +#include <X11/Xlibint.h> +#include <X11/extensions/Xvlib.h> +#include <X11/extensions/Xvproto.h> +#include <X11/extensions/Xext.h> +#include <X11/extensions/extutil.h> +#define _HAVE_XALLOC_DECLS + +#include "hostx.h" +#include "ephyrhostvideo.h" +#include "ephyrlog.h" + +#ifndef TRUE +#define TRUE 1 +#endif /*TRUE*/ + +#ifndef FALSE +#define FALSE 0 +#endif /*FALSE*/ + +static XExtensionInfo _xv_info_data; +static XExtensionInfo *xv_info = &_xv_info_data; +static char *xv_extension_name = XvName; +static char *xv_error_string(Display *dpy, int code, XExtCodes *codes, + char * buf, int n); +static int xv_close_display(Display *dpy, XExtCodes *codes); +static Bool xv_wire_to_event(Display *dpy, XEvent *host, xEvent *wire); + +static XExtensionHooks xv_extension_hooks = { + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + xv_close_display, /* close_display */ + xv_wire_to_event, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + xv_error_string /* error_string */ +}; + + +static char *xv_error_list[] = +{ + "BadPort", /* XvBadPort */ + "BadEncoding", /* XvBadEncoding */ + "BadControl" /* XvBadControl */ +}; + + +#define XvCheckExtension(dpy, i, val) \ + XextCheckExtension(dpy, i, xv_extension_name, val) +#define XvGetReq(name, req) \ + WORD64ALIGN\ + if ((dpy->bufptr + SIZEOF(xv##name##Req)) > dpy->bufmax)\ + _XFlush(dpy);\ + req = (xv##name##Req *)(dpy->last_req = dpy->bufptr);\ + req->reqType = info->codes->major_opcode;\ + req->xvReqType = xv_##name; \ + req->length = (SIZEOF(xv##name##Req))>>2;\ + dpy->bufptr += SIZEOF(xv##name##Req);\ + dpy->request++ + +static XEXT_GENERATE_CLOSE_DISPLAY (xv_close_display, xv_info) + + +static XEXT_GENERATE_FIND_DISPLAY (xv_find_display, xv_info, + xv_extension_name, + &xv_extension_hooks, + XvNumEvents, NULL) + +static XEXT_GENERATE_ERROR_STRING (xv_error_string, xv_extension_name, + XvNumErrors, xv_error_list) + +struct _EphyrHostXVAdaptorArray { + XvAdaptorInfo *adaptors ; + unsigned int nb_adaptors ; +}; + +/*heavily copied from libx11*/ +#define BUFSIZE 2048 +static void +ephyrHostXVLogXErrorEvent (Display *a_display, + XErrorEvent *a_err_event, + FILE *a_fp) +{ + char buffer[BUFSIZ]; + char mesg[BUFSIZ]; + char number[32]; + const char *mtype = "XlibMessage"; + register _XExtension *ext = (_XExtension *)NULL; + _XExtension *bext = (_XExtension *)NULL; + Display *dpy = a_display ; + + XGetErrorText(dpy, a_err_event->error_code, buffer, BUFSIZ); + XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); + (void) fprintf(a_fp, "%s: %s\n ", mesg, buffer); + XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", + mesg, BUFSIZ); + (void) fprintf(a_fp, mesg, a_err_event->request_code); + if (a_err_event->request_code < 128) { + snprintf(number, sizeof(number), "%d", a_err_event->request_code); + XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); + } else { + for (ext = dpy->ext_procs; + ext && (ext->codes.major_opcode != a_err_event->request_code); + ext = ext->next) + ; + if (ext) + strcpy(buffer, ext->name); + else + buffer[0] = '\0'; + } + (void) fprintf(a_fp, " (%s)\n", buffer); + if (a_err_event->request_code >= 128) { + XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", + mesg, BUFSIZ); + fputs(" ", a_fp); + (void) fprintf(a_fp, mesg, a_err_event->minor_code); + if (ext) { + snprintf(mesg, sizeof(mesg), "%s.%d", + ext->name, a_err_event->minor_code); + XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ); + (void) fprintf(a_fp, " (%s)", buffer); + } + fputs("\n", a_fp); + } + if (a_err_event->error_code >= 128) { + /* kludge, try to find the extension that caused it */ + buffer[0] = '\0'; + for (ext = dpy->ext_procs; ext; ext = ext->next) { + if (ext->error_string) + (*ext->error_string)(dpy, a_err_event->error_code, &ext->codes, + buffer, BUFSIZ); + if (buffer[0]) { + bext = ext; + break; + } + if (ext->codes.first_error && + ext->codes.first_error < (int)a_err_event->error_code && + (!bext || ext->codes.first_error > bext->codes.first_error)) + bext = ext; + } + if (bext) + snprintf(buffer, sizeof(buffer), "%s.%d", bext->name, + a_err_event->error_code - bext->codes.first_error); + else + strcpy(buffer, "Value"); + XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ); + if (mesg[0]) { + fputs(" ", a_fp); + (void) fprintf(a_fp, mesg, a_err_event->resourceid); + fputs("\n", a_fp); + } + /* let extensions try to print the values */ + for (ext = dpy->ext_procs; ext; ext = ext->next) { + if (ext->error_values) + (*ext->error_values)(dpy, a_err_event, a_fp); + } + } else if ((a_err_event->error_code == BadWindow) || + (a_err_event->error_code == BadPixmap) || + (a_err_event->error_code == BadCursor) || + (a_err_event->error_code == BadFont) || + (a_err_event->error_code == BadDrawable) || + (a_err_event->error_code == BadColor) || + (a_err_event->error_code == BadGC) || + (a_err_event->error_code == BadIDChoice) || + (a_err_event->error_code == BadValue) || + (a_err_event->error_code == BadAtom)) { + if (a_err_event->error_code == BadValue) + XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", + mesg, BUFSIZ); + else if (a_err_event->error_code == BadAtom) + XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", + mesg, BUFSIZ); + else + XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", + mesg, BUFSIZ); + fputs(" ", a_fp); + (void) fprintf(a_fp, mesg, a_err_event->resourceid); + fputs("\n", a_fp); + } + XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", + mesg, BUFSIZ); + fputs(" ", a_fp); + (void) fprintf(a_fp, mesg, a_err_event->serial); + XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d", + mesg, BUFSIZ); + fputs("\n ", a_fp); + (void) fprintf(a_fp, mesg, dpy->request); + fputs("\n", a_fp); +} + +static int +ephyrHostXVErrorHandler (Display *a_display, + XErrorEvent *a_error_event) +{ + EPHYR_LOG_ERROR ("got an error from the host xserver:\n") ; + ephyrHostXVLogXErrorEvent (a_display, a_error_event, stderr) ; + return Success ; +} + +void +ephyrHostXVInit (void) +{ + static Bool s_initialized ; + + if (s_initialized) + return ; + XSetErrorHandler (ephyrHostXVErrorHandler) ; + s_initialized = TRUE ; +} + +Bool +ephyrHostXVQueryAdaptors (EphyrHostXVAdaptorArray **a_adaptors) +{ + EphyrHostXVAdaptorArray *result=NULL ; + int ret=0 ; + Bool is_ok=FALSE ; + + EPHYR_RETURN_VAL_IF_FAIL (a_adaptors, FALSE) ; + + EPHYR_LOG ("enter\n") ; + + result = calloc (1, sizeof (EphyrHostXVAdaptorArray)) ; + if (!result) + goto out ; + + ret = XvQueryAdaptors (hostx_get_display (), + DefaultRootWindow (hostx_get_display ()), + &result->nb_adaptors, + &result->adaptors) ; + if (ret != Success) { + EPHYR_LOG_ERROR ("failed to query host adaptors: %d\n", ret) ; + goto out ; + } + *a_adaptors = result ; + is_ok = TRUE ; + +out: + EPHYR_LOG ("leave\n") ; + return is_ok ; +} + +void +ephyrHostXVAdaptorArrayDelete (EphyrHostXVAdaptorArray *a_adaptors) +{ + if (!a_adaptors) + return ; + if (a_adaptors->adaptors) { + XvFreeAdaptorInfo (a_adaptors->adaptors) ; + a_adaptors->adaptors = NULL ; + a_adaptors->nb_adaptors = 0 ; + } + XFree (a_adaptors) ; +} + +int +ephyrHostXVAdaptorArrayGetSize (const EphyrHostXVAdaptorArray *a_this) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this, -1) ; + return a_this->nb_adaptors ; +} + +EphyrHostXVAdaptor* +ephyrHostXVAdaptorArrayAt (const EphyrHostXVAdaptorArray *a_this, + int a_index) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this, NULL) ; + + if (a_index >= a_this->nb_adaptors) + return NULL ; + return (EphyrHostXVAdaptor*)&a_this->adaptors[a_index] ; +} + +char +ephyrHostXVAdaptorGetType (const EphyrHostXVAdaptor *a_this) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this, -1) ; + return ((XvAdaptorInfo*)a_this)->type ; +} + +const char* +ephyrHostXVAdaptorGetName (const EphyrHostXVAdaptor *a_this) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this, NULL) ; + + return ((XvAdaptorInfo*)a_this)->name ; +} + +EphyrHostVideoFormat* +ephyrHostXVAdaptorGetVideoFormats (const EphyrHostXVAdaptor *a_this, + int *a_nb_formats) +{ + EphyrHostVideoFormat *formats=NULL ; + int nb_formats=0, i=0 ; + XVisualInfo *visual_info, visual_info_template ; + int nb_visual_info ; + + EPHYR_RETURN_VAL_IF_FAIL (a_this, NULL) ; + + nb_formats = ((XvAdaptorInfo*)a_this)->num_formats ; + formats = calloc (nb_formats, sizeof (EphyrHostVideoFormat)) ; + for (i=0; i < nb_formats; i++) { + memset (&visual_info_template, 0, sizeof (visual_info_template)) ; + visual_info_template.visualid = + ((XvAdaptorInfo*)a_this)->formats[i].visual_id; + visual_info = XGetVisualInfo (hostx_get_display (), + VisualIDMask, + &visual_info_template, + &nb_visual_info) ; + formats[i].depth = ((XvAdaptorInfo*)a_this)->formats[i].depth ; + formats[i].visual_class = visual_info->class ; + XFree (visual_info) ; + } + if (a_nb_formats) + *a_nb_formats = nb_formats ; + return formats ; +} + +int +ephyrHostXVAdaptorGetNbPorts (const EphyrHostXVAdaptor *a_this) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this, -1) ; + + return ((XvAdaptorInfo*)a_this)->num_ports ; +} + +int +ephyrHostXVAdaptorGetFirstPortID (const EphyrHostXVAdaptor *a_this) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this, -1) ; + + return ((XvAdaptorInfo*)a_this)->base_id ; +} + +Bool +ephyrHostXVAdaptorHasPutVideo (const EphyrHostXVAdaptor *a_this, + Bool *a_result) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this && a_result, FALSE) ; + + if ((((XvAdaptorInfo*)a_this)->type & (XvVideoMask | XvInputMask)) == + (XvVideoMask | XvInputMask)) + *a_result = TRUE ; + else + *a_result = FALSE ; + return TRUE ; +} + +Bool +ephyrHostXVAdaptorHasGetVideo (const EphyrHostXVAdaptor *a_this, + Bool *a_result) +{ + if ((((XvAdaptorInfo*)a_this)->type & (XvVideoMask | XvOutputMask)) == + (XvVideoMask | XvOutputMask)) + *a_result = TRUE ; + else + *a_result = FALSE ; + return TRUE ; +} + +Bool +ephyrHostXVAdaptorHasPutStill (const EphyrHostXVAdaptor *a_this, + Bool *a_result) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this && a_result, FALSE) ; + + if ((((XvAdaptorInfo*)a_this)->type & (XvStillMask | XvInputMask)) == + (XvStillMask | XvInputMask)) + *a_result = TRUE ; + else + *a_result = FALSE ; + return TRUE ; +} + +Bool +ephyrHostXVAdaptorHasGetStill (const EphyrHostXVAdaptor *a_this, + Bool *a_result) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this && a_result, FALSE) ; + + if ((((XvAdaptorInfo*)a_this)->type & (XvStillMask | XvOutputMask)) == + (XvStillMask | XvOutputMask)) + *a_result = TRUE ; + else + *a_result = FALSE ; + return TRUE ; +} + +Bool +ephyrHostXVAdaptorHasPutImage (const EphyrHostXVAdaptor *a_this, + Bool *a_result) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_this && a_result, FALSE) ; + + if ((((XvAdaptorInfo*)a_this)->type & (XvImageMask | XvInputMask)) == + (XvImageMask | XvInputMask)) + *a_result = TRUE ; + else + *a_result = FALSE ; + return TRUE ; +} + +Bool +ephyrHostXVQueryEncodings (int a_port_id, + EphyrHostEncoding **a_encodings, + unsigned int *a_num_encodings) +{ + EphyrHostEncoding *encodings=NULL ; + XvEncodingInfo *encoding_info=NULL ; + unsigned int num_encodings=0, i; + int ret=0 ; + + EPHYR_RETURN_VAL_IF_FAIL (a_encodings && a_num_encodings, FALSE) ; + + ret = XvQueryEncodings (hostx_get_display (), + a_port_id, + &num_encodings, + &encoding_info) ; + if (num_encodings && encoding_info) { + encodings = calloc (num_encodings, sizeof (EphyrHostEncoding)) ; + for (i=0; i<num_encodings; i++) { + encodings[i].id = encoding_info[i].encoding_id ; + encodings[i].name = strdup (encoding_info[i].name) ; + encodings[i].width = encoding_info[i].width ; + encodings[i].height = encoding_info[i].height ; + encodings[i].rate.numerator = encoding_info[i].rate.numerator ; + encodings[i].rate.denominator = encoding_info[i].rate.denominator ; + } + } + if (encoding_info) { + XvFreeEncodingInfo (encoding_info) ; + encoding_info = NULL ; + } + *a_encodings = encodings ; + *a_num_encodings = num_encodings ; + + if (ret != Success) + return FALSE ; + return TRUE ; +} + +void +ephyrHostEncodingsDelete (EphyrHostEncoding *a_encodings, + int a_num_encodings) +{ + int i=0 ; + + if (!a_encodings) + return ; + for (i=0; i < a_num_encodings; i++) { + free(a_encodings[i].name) ; + a_encodings[i].name = NULL ; + } + free(a_encodings) ; +} + +void +ephyrHostAttributesDelete (EphyrHostAttribute *a_attributes) +{ + if (!a_attributes) + return ; + XFree (a_attributes) ; +} + +Bool +ephyrHostXVQueryPortAttributes (int a_port_id, + EphyrHostAttribute **a_attributes, + int *a_num_attributes) +{ + EPHYR_RETURN_VAL_IF_FAIL (a_attributes && a_num_attributes, FALSE) ; + + *a_attributes = + (EphyrHostAttribute*)XvQueryPortAttributes (hostx_get_display (), + a_port_id, + a_num_attributes); + + return TRUE ; +} + +Bool +ephyrHostXVQueryImageFormats (int a_port_id, + EphyrHostImageFormat **a_formats, + int *a_num_format) +{ + XvImageFormatValues *result=NULL ; + + EPHYR_RETURN_VAL_IF_FAIL (a_formats && a_num_format, FALSE) ; + + result = XvListImageFormats (hostx_get_display (), + a_port_id, + a_num_format) ; + *a_formats = (EphyrHostImageFormat*) result ; + return TRUE ; + +} + +Bool +ephyrHostXVSetPortAttribute (int a_port_id, + int a_atom, + int a_attr_value) +{ + int res=Success ; + + EPHYR_LOG ("atom,name,value: (%d,%s,%d)\n", + a_atom, + XGetAtomName (hostx_get_display (), a_atom), + a_attr_value) ; + + res = XvSetPortAttribute (hostx_get_display (), + a_port_id, + a_atom, + a_attr_value) ; + if (res != Success) { + EPHYR_LOG_ERROR ("XvSetPortAttribute() failed: %d\n", res) ; + return FALSE ; + } + XFlush (hostx_get_display ()) ; + EPHYR_LOG ("leave\n") ; + + return TRUE ; +} + +Bool +ephyrHostXVGetPortAttribute (int a_port_id, + int a_atom, + int *a_attr_value) +{ + int res=Success ; + Bool ret=FALSE ; + + EPHYR_RETURN_VAL_IF_FAIL (a_attr_value, FALSE) ; + + EPHYR_LOG ("enter, a_port_id: %d, a_atomid: %d, attr_name: %s\n", + a_port_id, a_atom, XGetAtomName (hostx_get_display (), a_atom)) ; + + res = XvGetPortAttribute (hostx_get_display (), + a_port_id, + a_atom, + a_attr_value) ; + if (res != Success) { + EPHYR_LOG_ERROR ("XvGetPortAttribute() failed: %d \n", res) ; + goto out ; + } + EPHYR_LOG ("atom,value: (%d, %d)\n", a_atom, *a_attr_value) ; + + ret = TRUE ; + +out: + EPHYR_LOG ("leave\n") ; + return ret ; +} + +Bool +ephyrHostXVQueryBestSize (int a_port_id, + Bool a_motion, + unsigned int a_frame_w, + unsigned int a_frame_h, + unsigned int a_drw_w, + unsigned int a_drw_h, + unsigned int *a_actual_w, + unsigned int *a_actual_h) +{ + int res=0 ; + Bool is_ok=FALSE ; + + EPHYR_RETURN_VAL_IF_FAIL (a_actual_w && a_actual_h, FALSE) ; + + EPHYR_LOG ("enter: frame (%dx%d), drw (%dx%d)\n", + a_frame_w, a_frame_h, + a_drw_w, a_drw_h) ; + + res = XvQueryBestSize (hostx_get_display (), + a_port_id, + a_motion, + a_frame_w, a_frame_h, + a_drw_w, a_drw_h, + a_actual_w, a_actual_h) ; + if (res != Success) { + EPHYR_LOG_ERROR ("XvQueryBestSize() failed: %d\n", res) ; + goto out ; + } + XSync (hostx_get_display (), FALSE) ; + + EPHYR_LOG ("actual (%dx%d)\n", *a_actual_w, *a_actual_h) ; + is_ok = TRUE ; + +out: + EPHYR_LOG ("leave\n") ; + return is_ok ; +} + +static Bool +xv_wire_to_event(Display *dpy, XEvent *host, xEvent *wire) +{ + XExtDisplayInfo *info = xv_find_display (dpy); + XvEvent *re = (XvEvent *)host; + xvEvent *event = (xvEvent *)wire; + + XvCheckExtension(dpy, info, False); + + switch ((event->u.u.type & 0x7F) - info->codes->first_event) { + case XvVideoNotify: + re->xvvideo.type = event->u.u.type & 0x7f; + re->xvvideo.serial = + _XSetLastRequestRead(dpy, (xGenericReply *)event); + re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0); + re->xvvideo.display = dpy; + re->xvvideo.time = event->u.videoNotify.time; + re->xvvideo.reason = event->u.videoNotify.reason; + re->xvvideo.drawable = event->u.videoNotify.drawable; + re->xvvideo.port_id = event->u.videoNotify.port; + break; + case XvPortNotify: + re->xvport.type = event->u.u.type & 0x7f; + re->xvport.serial = + _XSetLastRequestRead(dpy, (xGenericReply *)event); + re->xvport.send_event = ((event->u.u.type & 0x80) != 0); + re->xvport.display = dpy; + re->xvport.time = event->u.portNotify.time; + re->xvport.port_id = event->u.portNotify.port; + re->xvport.attribute = event->u.portNotify.attribute; + re->xvport.value = event->u.portNotify.value; + break; + default: + return False; + } + + return True ; +} + +Bool +ephyrHostXVQueryImageAttributes (int a_port_id, + int a_image_id /*image fourcc code*/, + unsigned short *a_width, + unsigned short *a_height, + int *a_image_size, + int *a_pitches, + int *a_offsets) +{ + Display *dpy = hostx_get_display () ; + Bool ret=FALSE ; + XExtDisplayInfo *info = xv_find_display (dpy); + xvQueryImageAttributesReq *req=NULL; + xvQueryImageAttributesReply rep; + + EPHYR_RETURN_VAL_IF_FAIL (a_width, FALSE) ; + EPHYR_RETURN_VAL_IF_FAIL (a_height, FALSE) ; + EPHYR_RETURN_VAL_IF_FAIL (a_image_size, FALSE) ; + + XvCheckExtension (dpy, info, FALSE); + + LockDisplay (dpy); + + XvGetReq (QueryImageAttributes, req); + req->id = a_image_id; + req->port = a_port_id; + req->width = *a_width; + req->height = *a_height; + /* + * read the reply + */ + if (!_XReply (dpy, (xReply *)&rep, 0, xFalse)) { + EPHYR_LOG_ERROR ("QeryImageAttribute req failed\n") ; + goto out ; + } + if (a_pitches && a_offsets) { + _XRead (dpy, + (char*)a_pitches, + rep.num_planes << 2); + _XRead (dpy, + (char*)a_offsets, + rep.num_planes << 2); + } else { + _XEatData(dpy, rep.length << 2); + } + *a_width = rep.width ; + *a_height = rep.height ; + *a_image_size = rep.data_size ; + + ret = TRUE ; + +out: + UnlockDisplay (dpy) ; + SyncHandle (); + return ret ; +} + +Bool +ephyrHostGetAtom (const char* a_name, + Bool a_create_if_not_exists, + int *a_atom) +{ + int atom=None ; + + EPHYR_RETURN_VAL_IF_FAIL (a_atom, FALSE) ; + + atom = XInternAtom (hostx_get_display (), a_name, a_create_if_not_exists); + if (atom == None) { + return FALSE ; + } + *a_atom = atom ; + return TRUE ; +} + +char* +ephyrHostGetAtomName (int a_atom) +{ + return XGetAtomName (hostx_get_display (), a_atom) ; +} + +void +ephyrHostFree (void *a_pointer) +{ + if (a_pointer) + XFree (a_pointer) ; +} + +Bool +ephyrHostXVPutImage (int a_screen_num, + int a_port_id, + int a_image_id, + int a_drw_x, + int a_drw_y, + int a_drw_w, + int a_drw_h, + int a_src_x, + int a_src_y, + int a_src_w, + int a_src_h, + int a_image_width, + int a_image_height, + unsigned char *a_buf, + EphyrHostBox *a_clip_rects, + int a_clip_rect_nums ) +{ + Bool is_ok=TRUE ; + XvImage *xv_image=NULL ; + GC gc=0 ; + XGCValues gc_values; + Display *dpy = hostx_get_display () ; + XRectangle *rects=NULL ; + int res = 0 ; + + EPHYR_RETURN_VAL_IF_FAIL (a_buf, FALSE) ; + + EPHYR_LOG ("enter, num_clip_rects: %d\n", a_clip_rect_nums) ; + + memset (&gc_values, 0, sizeof (gc_values)) ; + gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values); + if (!gc) { + EPHYR_LOG_ERROR ("failed to create gc \n") ; + goto out ; + } + xv_image = (XvImage*) XvCreateImage (hostx_get_display (), + a_port_id, a_image_id, + NULL, a_image_width, a_image_height) ; + if (!xv_image) { + EPHYR_LOG_ERROR ("failed to create image\n") ; + goto out ; + } + xv_image->data = (char*)a_buf ; + if (a_clip_rect_nums) { + int i=0 ; + rects = calloc (a_clip_rect_nums, sizeof (XRectangle)) ; + for (i=0; i < a_clip_rect_nums; i++) { + rects[i].x = a_clip_rects[i].x1 ; + rects[i].y = a_clip_rects[i].y1 ; + rects[i].width = a_clip_rects[i].x2 - a_clip_rects[i].x1; + rects[i].height = a_clip_rects[i].y2 - a_clip_rects[i].y1; + EPHYR_LOG ("(x,y,w,h): (%d,%d,%d,%d)\n", + rects[i].x, rects[i].y, + rects[i].width, rects[i].height) ; + } + XSetClipRectangles (dpy, gc, 0, 0, rects, a_clip_rect_nums, YXBanded) ; + /*this always returns 1*/ + } + res = XvPutImage (dpy, a_port_id, + hostx_get_window (a_screen_num), + gc, xv_image, + a_src_x, a_src_y, a_src_w, a_src_h, + a_drw_x, a_drw_y, a_drw_w, a_drw_h) ; + if (res != Success) { + EPHYR_LOG_ERROR ("XvPutImage() failed: %d\n", res) ; + goto out ; + } + is_ok = TRUE ; + +out: + if (xv_image) { + XFree (xv_image) ; + xv_image = NULL ; + } + if (gc) { + XFreeGC (dpy, gc) ; + gc = NULL ; + } + free(rects); + rects = NULL; + EPHYR_LOG ("leave\n") ; + return is_ok ; +} + +Bool +ephyrHostXVPutVideo (int a_screen_num, int a_port_id, + int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, + int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h) +{ + Bool is_ok=FALSE ; + int res=FALSE ; + GC gc=0 ; + XGCValues gc_values; + Display *dpy=hostx_get_display () ; + + EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ; + + gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values); + if (!gc) { + EPHYR_LOG_ERROR ("failed to create gc \n") ; + goto out ; + } + res = XvPutVideo (dpy, a_port_id, hostx_get_window (a_screen_num), gc, + a_vid_x, a_vid_y, a_vid_w, a_vid_h, + a_drw_x, a_drw_y, a_drw_w, a_drw_h) ; + + if (res != Success) { + EPHYR_LOG_ERROR ("XvPutVideo() failed: %d\n", res) ; + goto out ; + } + + is_ok = TRUE ; + +out: + if (gc) { + XFreeGC (dpy, gc) ; + gc = NULL ; + } + return is_ok ; +} + +Bool +ephyrHostXVGetVideo (int a_screen_num, int a_port_id, + int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, + int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h) +{ + Bool is_ok=FALSE ; + int res=FALSE ; + GC gc=0 ; + XGCValues gc_values; + Display *dpy=hostx_get_display () ; + + EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ; + + gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values); + if (!gc) { + EPHYR_LOG_ERROR ("failed to create gc \n") ; + goto out ; + } + res = XvGetVideo (dpy, a_port_id, hostx_get_window (a_screen_num), gc, + a_vid_x, a_vid_y, a_vid_w, a_vid_h, + a_drw_x, a_drw_y, a_drw_w, a_drw_h) ; + + if (res != Success) { + EPHYR_LOG_ERROR ("XvGetVideo() failed: %d\n", res) ; + goto out ; + } + + is_ok = TRUE ; + +out: + if (gc) { + XFreeGC (dpy, gc) ; + gc = NULL ; + } + return is_ok ; +} + +Bool +ephyrHostXVPutStill (int a_screen_num, int a_port_id, + int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, + int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h) +{ + Bool is_ok=FALSE ; + int res=FALSE ; + GC gc=0 ; + XGCValues gc_values; + Display *dpy=hostx_get_display () ; + + EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ; + + gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values); + if (!gc) { + EPHYR_LOG_ERROR ("failed to create gc \n") ; + goto out ; + } + res = XvPutStill (dpy, a_port_id, hostx_get_window (a_screen_num), gc, + a_vid_x, a_vid_y, a_vid_w, a_vid_h, + a_drw_x, a_drw_y, a_drw_w, a_drw_h) ; + + if (res != Success) { + EPHYR_LOG_ERROR ("XvPutStill() failed: %d\n", res) ; + goto out ; + } + + is_ok = TRUE ; + +out: + if (gc) { + XFreeGC (dpy, gc) ; + gc = NULL ; + } + return is_ok ; +} + +Bool +ephyrHostXVGetStill (int a_screen_num, int a_port_id, + int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, + int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h) +{ + Bool is_ok=FALSE ; + int res=FALSE ; + GC gc=0 ; + XGCValues gc_values; + Display *dpy=hostx_get_display () ; + + EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ; + + gc = XCreateGC (dpy, hostx_get_window (a_screen_num), 0L, &gc_values); + if (!gc) { + EPHYR_LOG_ERROR ("failed to create gc \n") ; + goto out ; + } + res = XvGetStill (dpy, a_port_id, hostx_get_window (a_screen_num), gc, + a_vid_x, a_vid_y, a_vid_w, a_vid_h, + a_drw_x, a_drw_y, a_drw_w, a_drw_h) ; + + if (res != Success) { + EPHYR_LOG_ERROR ("XvGetStill() failed: %d\n", res) ; + goto out ; + } + + is_ok = TRUE ; + +out: + if (gc) { + XFreeGC (dpy, gc) ; + gc = NULL ; + } + return is_ok ; +} + +Bool +ephyrHostXVStopVideo (int a_screen_num, int a_port_id) +{ + int ret=0 ; + Bool is_ok=FALSE ; + Display *dpy = hostx_get_display () ; + + EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ; + + EPHYR_LOG ("enter\n") ; + + ret = XvStopVideo (dpy, a_port_id, hostx_get_window (a_screen_num)) ; + if (ret != Success) { + EPHYR_LOG_ERROR ("XvStopVideo() failed: %d \n", ret) ; + goto out ; + } + is_ok = TRUE ; + +out: + EPHYR_LOG ("leave\n") ; + return is_ok ; +} + diff --git a/xorg-server/hw/kdrive/linux/linux.c b/xorg-server/hw/kdrive/linux/linux.c index a53db4965..194e7cd59 100644 --- a/xorg-server/hw/kdrive/linux/linux.c +++ b/xorg-server/hw/kdrive/linux/linux.c @@ -109,7 +109,7 @@ LinuxInit (void) close(fd); } - sprintf(vtname,"/dev/tty%d",vtno); /* /dev/tty1-64 */ + snprintf(vtname,sizeof(vtname),"/dev/tty%d",vtno); /* /dev/tty1-64 */ if ((LinuxConsoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) < 0) { diff --git a/xorg-server/hw/kdrive/src/kinput.c b/xorg-server/hw/kdrive/src/kinput.c index 6a1ce49e0..9c0b34fe1 100644 --- a/xorg-server/hw/kdrive/src/kinput.c +++ b/xorg-server/hw/kdrive/src/kinput.c @@ -1049,12 +1049,10 @@ KdGetOptions (InputOption **options, char *string) if (strchr(string, '=')) { tam_key = (strchr(string, '=') - string); - key = malloc(tam_key + 1); + key = strndup(string, tam_key); if (!key) goto out; - strncpy(key, string, tam_key); - key[tam_key] = '\0'; value = strdup(strchr(string, '=') + 1); if (!value) goto out; diff --git a/xorg-server/hw/vfb/InitOutput.c b/xorg-server/hw/vfb/InitOutput.c index 121854781..3e5d05100 100644 --- a/xorg-server/hw/vfb/InitOutput.c +++ b/xorg-server/hw/vfb/InitOutput.c @@ -560,7 +560,8 @@ vfbAllocateMmappedFramebuffer(vfbScreenInfoPtr pvfb) char dummyBuffer[DUMMY_BUFFER_SIZE]; int currentFileSize, writeThisTime; - sprintf(pvfb->mmap_file, "%s/Xvfb_screen%d", pfbdir, (int) (pvfb - vfbScreens)); + snprintf(pvfb->mmap_file, sizeof(pvfb->mmap_file), "%s/Xvfb_screen%d", + pfbdir, (int) (pvfb - vfbScreens)); if (-1 == (pvfb->mmap_fd = open(pvfb->mmap_file, O_CREAT|O_RDWR, 0666))) { perror("open"); diff --git a/xorg-server/hw/xfree86/common/Makefile.am b/xorg-server/hw/xfree86/common/Makefile.am index a27372103..27921777d 100644 --- a/xorg-server/hw/xfree86/common/Makefile.am +++ b/xorg-server/hw/xfree86/common/Makefile.am @@ -35,7 +35,7 @@ xf86DefModeSet.c: $(srcdir)/modeline2c.awk $(MODEDEFSOURCES) BUILT_SOURCES = xf86DefModeSet.c AM_LDFLAGS = -r -libcommon_la_SOURCES = xf86Configure.c xf86ShowOpts.c xf86Bus.c xf86Config.c \ +libcommon_la_SOURCES = xf86Configure.c xf86Bus.c xf86Config.c \ xf86Cursor.c $(DGASOURCES) xf86DPMS.c \ xf86Events.c xf86Globals.c xf86AutoConfig.c \ xf86Option.c xf86Init.c \ diff --git a/xorg-server/hw/xfree86/common/xf86.h b/xorg-server/hw/xfree86/common/xf86.h index 3185baf3a..f216d5e8c 100644 --- a/xorg-server/hw/xfree86/common/xf86.h +++ b/xorg-server/hw/xfree86/common/xf86.h @@ -104,7 +104,6 @@ extern _X_EXPORT Bool xf86ParsePciBusString(const char *busID, int *bus, int *device, int *func); extern _X_EXPORT Bool xf86ComparePciBusString(const char *busID, int bus, int device, int func); -extern _X_EXPORT void xf86FormatPciBusNumber(int busnum, char *buffer); extern _X_EXPORT Bool xf86IsPrimaryPci(struct pci_device * pPci); extern _X_EXPORT Bool xf86CheckPciMemBase(struct pci_device * pPci, memType base); diff --git a/xorg-server/hw/xfree86/common/xf86AutoConfig.c b/xorg-server/hw/xfree86/common/xf86AutoConfig.c index 7fc6518d3..0c465682a 100644 --- a/xorg-server/hw/xfree86/common/xf86AutoConfig.c +++ b/xorg-server/hw/xfree86/common/xf86AutoConfig.c @@ -267,6 +267,7 @@ listPossibleVideoDrivers(char *matches[], int nmatches) #endif } +#if !defined(sun) /* Fallback to platform default frame buffer driver */ if (i < (nmatches - 1)) { #if !defined(__linux__) && defined(__sparc__) @@ -275,6 +276,7 @@ listPossibleVideoDrivers(char *matches[], int nmatches) matches[i++] = xnfstrdup("fbdev"); #endif } +#endif /* !sun */ } /* copy a screen section and enter the desired driver diff --git a/xorg-server/hw/xfree86/common/xf86Config.c b/xorg-server/hw/xfree86/common/xf86Config.c index cb4be4210..fef4bf1fe 100644 --- a/xorg-server/hw/xfree86/common/xf86Config.c +++ b/xorg-server/hw/xfree86/common/xf86Config.c @@ -195,8 +195,7 @@ xf86ValidateFontPath(char *path) dirlen = p1 - path_elem; else dirlen = strlen(path_elem); - strncpy(dir_elem, path_elem, dirlen); - dir_elem[dirlen] = '\0'; + strlcpy(dir_elem, path_elem, dirlen + 1); flag = stat(dir_elem, &stat_buf); if (flag == 0) if (!S_ISDIR(stat_buf.st_mode)) @@ -249,9 +248,9 @@ xf86ModulelistFromConfig(pointer **optlist) { int count = 0, i = 0; char **modulearray; - char *ignore[] = { "GLcore", "speedo", "bitmap", "drm", - "freetype", "type1", - NULL }; + const char *ignore[] = { "GLcore", "speedo", "bitmap", "drm", + "freetype", "type1", + NULL }; pointer *optarray; XF86LoadPtr modp; Bool found; @@ -523,7 +522,7 @@ fixup_video_driver_list(char **drivers) } static char ** -GenerateDriverlist(char * dirname) +GenerateDriverlist(const char * dirname) { char **ret; const char *subdirs[] = { dirname, NULL }; @@ -554,7 +553,7 @@ xf86DriverlistFromCompile(void) * available is printed. */ static void -xf86ConfigError(char *msg, ...) +xf86ConfigError(const char *msg, ...) { va_list ap; @@ -2301,8 +2300,8 @@ checkInput(serverLayoutPtr layout, Bool implicit_layout) { ConfigStatus xf86HandleConfigFile(Bool autoconfig) { - const char *filename, *dirname, *sysdirname; - char *filesearch, *dirsearch; + char *filename, *dirname, *sysdirname; + const char *filesearch, *dirsearch; MessageType filefrom = X_DEFAULT; MessageType dirfrom = X_DEFAULT; char *scanptr; @@ -2353,6 +2352,10 @@ xf86HandleConfigFile(Bool autoconfig) return CONFIG_NOFILE; } + free(filename); + free(dirname); + free(sysdirname); + if ((xf86configptr = xf86readConfigFile ()) == NULL) { xf86Msg(X_ERROR, "Problem parsing the config file\n"); return CONFIG_PARSE_ERROR; diff --git a/xorg-server/hw/xfree86/common/xf86Config.h b/xorg-server/hw/xfree86/common/xf86Config.h index de287041a..411fc2cc1 100644 --- a/xorg-server/hw/xfree86/common/xf86Config.h +++ b/xorg-server/hw/xfree86/common/xf86Config.h @@ -51,7 +51,7 @@ typedef enum _ConfigStatus { } ConfigStatus; typedef struct _ModuleDefault { - char *name; + const char *name; Bool toLoad; XF86OptionPtr load_opt; } ModuleDefault; diff --git a/xorg-server/hw/xfree86/common/xf86Configure.c b/xorg-server/hw/xfree86/common/xf86Configure.c index 99b8b48d7..24f367ec0 100644 --- a/xorg-server/hw/xfree86/common/xf86Configure.c +++ b/xorg-server/hw/xfree86/common/xf86Configure.c @@ -58,17 +58,17 @@ Bool xf86DoConfigurePass1 = TRUE; static Bool foundMouse = FALSE; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) -static char *DFLT_MOUSE_DEV = "/dev/sysmouse"; -static char *DFLT_MOUSE_PROTO = "auto"; +static const char *DFLT_MOUSE_DEV = "/dev/sysmouse"; +static const char *DFLT_MOUSE_PROTO = "auto"; #elif defined(linux) -static char DFLT_MOUSE_DEV[] = "/dev/input/mice"; -static char DFLT_MOUSE_PROTO[] = "auto"; +static const char *DFLT_MOUSE_DEV = "/dev/input/mice"; +static const char *DFLT_MOUSE_PROTO = "auto"; #elif defined(WSCONS_SUPPORT) -static char *DFLT_MOUSE_DEV = "/dev/wsmouse"; -static char *DFLT_MOUSE_PROTO = "wsmouse"; +static const char *DFLT_MOUSE_DEV = "/dev/wsmouse"; +static const char *DFLT_MOUSE_PROTO = "wsmouse"; #else -static char *DFLT_MOUSE_DEV = "/dev/mouse"; -static char *DFLT_MOUSE_PROTO = "auto"; +static const char *DFLT_MOUSE_DEV = "/dev/mouse"; +static const char *DFLT_MOUSE_PROTO = "auto"; #endif /* @@ -516,9 +516,9 @@ void DoConfigure(void) { int i,j, screennum = -1; - char *home = NULL; + const char *home = NULL; char filename[PATH_MAX]; - char *addslash = ""; + const char *addslash = ""; XF86ConfigPtr xf86config = NULL; char **vlist, **vl; int *dev2screen; @@ -757,3 +757,54 @@ bail: fflush(stderr); exit(0); } + +/* Xorg -showopts: + * For each driver module installed, print out the list + * of options and their argument types, then exit + * + * Author: Marcus Schaefer, ms@suse.de + */ + +void DoShowOptions (void) { + int i = 0; + char **vlist = 0; + char *pSymbol = 0; + XF86ModuleData *initData = 0; + if (! (vlist = xf86DriverlistFromCompile())) { + ErrorF("Missing output drivers\n"); + goto bail; + } + xf86LoadModules (vlist,0); + free(vlist); + for (i = 0; i < xf86NumDrivers; i++) { + if (xf86DriverList[i]->AvailableOptions) { + OptionInfoPtr pOption = (OptionInfoPtr)(*xf86DriverList[i]->AvailableOptions)(0,0); + if (! pOption) { + ErrorF ("(EE) Couldn't read option table for %s driver\n", + xf86DriverList[i]->driverName + ); + continue; + } + XNFasprintf(&pSymbol, "%sModuleData", + xf86DriverList[i]->driverName); + initData = LoaderSymbol (pSymbol); + if (initData) { + XF86ModuleVersionInfo *vers = initData->vers; + OptionInfoPtr p; + ErrorF ("Driver[%d]:%s[%s] {\n", + i,xf86DriverList[i]->driverName,vers->vendor + ); + for (p = pOption; p->name != NULL; p++) { + ErrorF ("\t%s:%s\n", p->name, + optionTypeToString(p->type)); + } + ErrorF ("}\n"); + } + } + } + bail: + OsCleanup (TRUE); + AbortDDX (EXIT_ERR_DRIVERS); + fflush (stderr); + exit (0); +} diff --git a/xorg-server/hw/xfree86/common/xf86Globals.c b/xorg-server/hw/xfree86/common/xf86Globals.c index f46799615..d576fb915 100644 --- a/xorg-server/hw/xfree86/common/xf86Globals.c +++ b/xorg-server/hw/xfree86/common/xf86Globals.c @@ -163,7 +163,7 @@ const char *xf86VisualNames[] = { }; /* Parameters set only from the command line */ -char *xf86ServerName = "no-name"; +const char *xf86ServerName = "no-name"; Bool xf86fpFlag = FALSE; Bool xf86sFlag = FALSE; Bool xf86bsEnableFlag = FALSE; diff --git a/xorg-server/hw/xfree86/common/xf86Mode.c b/xorg-server/hw/xfree86/common/xf86Mode.c index df0884794..d202d4079 100644 --- a/xorg-server/hw/xfree86/common/xf86Mode.c +++ b/xorg-server/hw/xfree86/common/xf86Mode.c @@ -1,2130 +1,2130 @@ -/*
- * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of the copyright holder(s)
- * and author(s) shall not be used in advertising or otherwise to promote
- * the sale, use or other dealings in this Software without prior written
- * authorization from the copyright holder(s) and author(s).
- */
-
-/*
- * LCM() and scanLineWidth() are:
- *
- * Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting documentation, and
- * that the name of Marc Aurele La France not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. Marc Aurele La France makes no representations
- * about the suitability of this software for any purpose. It is provided
- * "as-is" without express or implied warranty.
- *
- * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
- * EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Copyright 1990,91,92,93 by Thomas Roell, Germany.
- * Copyright 1991,92,93 by SGCS (Snitily Graphics Consulting Services), USA.
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation, and that the name of Thomas Roell nor
- * SGCS be used in advertising or publicity pertaining to distribution
- * of the software without specific, written prior permission.
- * Thomas Roell nor SGCS makes no representations about the suitability
- * of this software for any purpose. It is provided "as is" without
- * express or implied warranty.
- *
- * THOMAS ROELL AND SGCS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR SGCS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-/*
- * Authors: Dirk Hohndel <hohndel@XFree86.Org>
- * David Dawes <dawes@XFree86.Org>
- * Marc La France <tsi@XFree86.Org>
- * ... and others
- *
- * This file includes helper functions for mode related things.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include "xf86Modes.h"
-#include "os.h"
-#include "servermd.h"
-#include "globals.h"
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "edid.h"
-
-static void
-printModeRejectMessage(int index, DisplayModePtr p, int status)
-{
- char *type;
-
- if (p->type & M_T_BUILTIN)
- type = "built-in ";
- else if (p->type & M_T_DEFAULT)
- type = "default ";
- else if (p->type & M_T_DRIVER)
- type = "driver ";
- else
- type = "";
-
- xf86DrvMsg(index, X_INFO, "Not using %smode \"%s\" (%s)\n", type, p->name,
- xf86ModeStatusToString(status));
-}
-
-/*
- * xf86GetNearestClock --
- * Find closest clock to given frequency (in kHz). This assumes the
- * number of clocks is greater than zero.
- */
-int
-xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
- int DivFactor, int MulFactor, int *divider)
-{
- int nearestClock = 0, nearestDiv = 1;
- int minimumGap = abs(freq - scrp->clock[0]);
- int i, j, k, gap;
-
- if (allowDiv2)
- k = 2;
- else
- k = 1;
-
- /* Must set this here in case the best match is scrp->clock[0] */
- if (divider != NULL)
- *divider = 0;
-
- for (i = 0; i < scrp->numClocks; i++) {
- for (j = 1; j <= k; j++) {
- gap = abs((freq * j) - ((scrp->clock[i] * DivFactor) / MulFactor));
- if ((gap < minimumGap) ||
- ((gap == minimumGap) && (j < nearestDiv))) {
- minimumGap = gap;
- nearestClock = i;
- nearestDiv = j;
- if (divider != NULL)
- *divider = (j - 1) * V_CLKDIV2;
- }
- }
- }
- return nearestClock;
-}
-
-/*
- * xf86ModeStatusToString
- *
- * Convert a ModeStatus value to a printable message
- */
-
-const char *
-xf86ModeStatusToString(ModeStatus status)
-{
- switch (status) {
- case MODE_OK:
- return "Mode OK";
- case MODE_HSYNC:
- return "hsync out of range";
- case MODE_VSYNC:
- return "vrefresh out of range";
- case MODE_H_ILLEGAL:
- return "illegal horizontal timings";
- case MODE_V_ILLEGAL:
- return "illegal vertical timings";
- case MODE_BAD_WIDTH:
- return "width requires unsupported line pitch";
- case MODE_NOMODE:
- return "no mode of this name";
- case MODE_NO_INTERLACE:
- return "interlace mode not supported";
- case MODE_NO_DBLESCAN:
- return "doublescan mode not supported";
- case MODE_NO_VSCAN:
- return "multiscan mode not supported";
- case MODE_MEM:
- return "insufficient memory for mode";
- case MODE_VIRTUAL_X:
- return "width too large for virtual size";
- case MODE_VIRTUAL_Y:
- return "height too large for virtual size";
- case MODE_MEM_VIRT:
- return "insufficient memory given virtual size";
- case MODE_NOCLOCK:
- return "no clock available for mode";
- case MODE_CLOCK_HIGH:
- return "mode clock too high";
- case MODE_CLOCK_LOW:
- return "mode clock too low";
- case MODE_CLOCK_RANGE:
- return "bad mode clock/interlace/doublescan";
- case MODE_BAD_HVALUE:
- return "horizontal timing out of range";
- case MODE_BAD_VVALUE:
- return "vertical timing out of range";
- case MODE_BAD_VSCAN:
- return "VScan value out of range";
- case MODE_HSYNC_NARROW:
- return "horizontal sync too narrow";
- case MODE_HSYNC_WIDE:
- return "horizontal sync too wide";
- case MODE_HBLANK_NARROW:
- return "horizontal blanking too narrow";
- case MODE_HBLANK_WIDE:
- return "horizontal blanking too wide";
- case MODE_VSYNC_NARROW:
- return "vertical sync too narrow";
- case MODE_VSYNC_WIDE:
- return "vertical sync too wide";
- case MODE_VBLANK_NARROW:
- return "vertical blanking too narrow";
- case MODE_VBLANK_WIDE:
- return "vertical blanking too wide";
- case MODE_PANEL:
- return "exceeds panel dimensions";
- case MODE_INTERLACE_WIDTH:
- return "width too large for interlaced mode";
- case MODE_ONE_WIDTH:
- return "all modes must have the same width";
- case MODE_ONE_HEIGHT:
- return "all modes must have the same height";
- case MODE_ONE_SIZE:
- return "all modes must have the same resolution";
- case MODE_NO_REDUCED:
- return "monitor doesn't support reduced blanking";
- case MODE_BANDWIDTH:
- return "mode requires too much memory bandwidth";
- case MODE_BAD:
- return "unknown reason";
- case MODE_ERROR:
- return "internal error";
- default:
- return "unknown";
- }
-}
-
-/*
- * xf86ShowClockRanges() -- Print the clock ranges allowed
- * and the clock values scaled by ClockMulFactor and ClockDivFactor
- */
-void
-xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges)
-{
- ClockRangePtr cp;
- int MulFactor = 1;
- int DivFactor = 1;
- int i, j;
- int scaledClock;
-
- for (cp = clockRanges; cp != NULL; cp = cp->next) {
- DivFactor = max(1, cp->ClockDivFactor);
- MulFactor = max(1, cp->ClockMulFactor);
- if (scrp->progClock) {
- if (cp->minClock) {
- if (cp->maxClock) {
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "Clock range: %6.2f to %6.2f MHz\n",
- (double)cp->minClock / 1000.0,
- (double)cp->maxClock / 1000.0);
- } else {
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "Minimum clock: %6.2f MHz\n",
- (double)cp->minClock / 1000.0);
- }
- } else {
- if (cp->maxClock) {
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "Maximum clock: %6.2f MHz\n",
- (double)cp->maxClock / 1000.0);
- }
- }
- } else if (DivFactor > 1 || MulFactor > 1) {
- j = 0;
- for (i = 0; i < scrp->numClocks; i++) {
- scaledClock = (scrp->clock[i] * DivFactor) / MulFactor;
- if (scaledClock >= cp->minClock && scaledClock <= cp->maxClock) {
- if ((j % 8) == 0) {
- if (j > 0)
- xf86ErrorF("\n");
- xf86DrvMsg(scrp->scrnIndex, X_INFO, "scaled clocks:");
- }
- xf86ErrorF(" %6.2f", (double)scaledClock / 1000.0);
- j++;
- }
- }
- xf86ErrorF("\n");
- }
- }
-}
-
-static Bool
-modeInClockRange(ClockRangePtr cp, DisplayModePtr p)
-{
- return ((p->Clock >= cp->minClock) &&
- (p->Clock <= cp->maxClock) &&
- (cp->interlaceAllowed || !(p->Flags & V_INTERLACE)) &&
- (cp->doubleScanAllowed ||
- ((p->VScan <= 1) && !(p->Flags & V_DBLSCAN))));
-}
-
-/*
- * xf86FindClockRangeForMode() [... like the name says ...]
- */
-static ClockRangePtr
-xf86FindClockRangeForMode(ClockRangePtr clockRanges, DisplayModePtr p)
-{
- ClockRangePtr cp;
-
- for (cp = clockRanges; ; cp = cp->next)
- if (!cp || modeInClockRange(cp, p))
- return cp;
-}
-
-
-/*
- * xf86HandleBuiltinMode() - handles built-in modes
- */
-static ModeStatus
-xf86HandleBuiltinMode(ScrnInfoPtr scrp,
- DisplayModePtr p,
- DisplayModePtr modep,
- ClockRangePtr clockRanges,
- Bool allowDiv2)
-{
- ClockRangePtr cp;
- int extraFlags = 0;
- int MulFactor = 1;
- int DivFactor = 1;
- int clockIndex;
-
- /* Reject previously rejected modes */
- if (p->status != MODE_OK)
- return p->status;
-
- /* Reject previously considered modes */
- if (p->prev)
- return MODE_NOMODE;
-
- if ((p->type & M_T_CLOCK_C) == M_T_CLOCK_C) {
- /* Check clock is in range */
- cp = xf86FindClockRangeForMode(clockRanges, p);
- if (cp == NULL){
- modep->type = p->type;
- p->status = MODE_CLOCK_RANGE;
- return MODE_CLOCK_RANGE;
- }
- DivFactor = cp->ClockDivFactor;
- MulFactor = cp->ClockMulFactor;
- if (!scrp->progClock) {
- clockIndex = xf86GetNearestClock(scrp, p->Clock, allowDiv2,
- cp->ClockDivFactor,
- cp->ClockMulFactor, &extraFlags);
- modep->Clock = (scrp->clock[clockIndex] * DivFactor)
- / MulFactor;
- modep->ClockIndex = clockIndex;
- modep->SynthClock = scrp->clock[clockIndex];
- if (extraFlags & V_CLKDIV2) {
- modep->Clock /= 2;
- modep->SynthClock /= 2;
- }
- } else {
- modep->Clock = p->Clock;
- modep->ClockIndex = -1;
- modep->SynthClock = (modep->Clock * MulFactor)
- / DivFactor;
- }
- modep->PrivFlags = cp->PrivFlags;
- } else {
- if(!scrp->progClock) {
- modep->Clock = p->Clock;
- modep->ClockIndex = p->ClockIndex;
- modep->SynthClock = p->SynthClock;
- } else {
- modep->Clock = p->Clock;
- modep->ClockIndex = -1;
- modep->SynthClock = p->SynthClock;
- }
- modep->PrivFlags = p->PrivFlags;
- }
- modep->type = p->type;
- modep->HDisplay = p->HDisplay;
- modep->HSyncStart = p->HSyncStart;
- modep->HSyncEnd = p->HSyncEnd;
- modep->HTotal = p->HTotal;
- modep->HSkew = p->HSkew;
- modep->VDisplay = p->VDisplay;
- modep->VSyncStart = p->VSyncStart;
- modep->VSyncEnd = p->VSyncEnd;
- modep->VTotal = p->VTotal;
- modep->VScan = p->VScan;
- modep->Flags = p->Flags | extraFlags;
- modep->CrtcHDisplay = p->CrtcHDisplay;
- modep->CrtcHBlankStart = p->CrtcHBlankStart;
- modep->CrtcHSyncStart = p->CrtcHSyncStart;
- modep->CrtcHSyncEnd = p->CrtcHSyncEnd;
- modep->CrtcHBlankEnd = p->CrtcHBlankEnd;
- modep->CrtcHTotal = p->CrtcHTotal;
- modep->CrtcHSkew = p->CrtcHSkew;
- modep->CrtcVDisplay = p->CrtcVDisplay;
- modep->CrtcVBlankStart = p->CrtcVBlankStart;
- modep->CrtcVSyncStart = p->CrtcVSyncStart;
- modep->CrtcVSyncEnd = p->CrtcVSyncEnd;
- modep->CrtcVBlankEnd = p->CrtcVBlankEnd;
- modep->CrtcVTotal = p->CrtcVTotal;
- modep->CrtcHAdjusted = p->CrtcHAdjusted;
- modep->CrtcVAdjusted = p->CrtcVAdjusted;
- modep->HSync = p->HSync;
- modep->VRefresh = p->VRefresh;
- modep->Private = p->Private;
- modep->PrivSize = p->PrivSize;
-
- p->prev = modep;
-
- return MODE_OK;
-}
-
-/*
- * xf86LookupMode
- *
- * This function returns a mode from the given list which matches the
- * given name. When multiple modes with the same name are available,
- * the method of picking the matching mode is determined by the
- * strategy selected.
- *
- * This function takes the following parameters:
- * scrp ScrnInfoPtr
- * modep pointer to the returned mode, which must have the name
- * field filled in.
- * clockRanges a list of clock ranges. This is optional when all the
- * modes are built-in modes.
- * strategy how to decide which mode to use from multiple modes with
- * the same name
- *
- * In addition, the following fields from the ScrnInfoRec are used:
- * modePool the list of monitor modes compatible with the driver
- * clocks a list of discrete clocks
- * numClocks number of discrete clocks
- * progClock clock is programmable
- *
- * If a mode was found, its values are filled in to the area pointed to
- * by modep, If a mode was not found the return value indicates the
- * reason.
- */
-
-ModeStatus
-xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
- ClockRangePtr clockRanges, LookupModeFlags strategy)
-{
- DisplayModePtr p, bestMode = NULL;
- ClockRangePtr cp;
- int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1;
- double refresh, bestRefresh = 0.0;
- Bool found = FALSE;
- int extraFlags = 0;
- int clockIndex = -1;
- int MulFactor = 1;
- int DivFactor = 1;
- int ModePrivFlags = 0;
- ModeStatus status = MODE_NOMODE;
- Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0;
- int n;
- const int types[] = {
- M_T_BUILTIN | M_T_PREFERRED,
- M_T_BUILTIN,
- M_T_USERDEF | M_T_PREFERRED,
- M_T_USERDEF,
- M_T_DRIVER | M_T_PREFERRED,
- M_T_DRIVER,
- 0
- };
- const int ntypes = sizeof(types) / sizeof(int);
-
- strategy &= ~(LOOKUP_CLKDIV2 | LOOKUP_OPTIONAL_TOLERANCES);
-
- /* Some sanity checking */
- if (scrp == NULL || scrp->modePool == NULL ||
- (!scrp->progClock && scrp->numClocks == 0)) {
- ErrorF("xf86LookupMode: called with invalid scrnInfoRec\n");
- return MODE_ERROR;
- }
- if (modep == NULL || modep->name == NULL) {
- ErrorF("xf86LookupMode: called with invalid modep\n");
- return MODE_ERROR;
- }
- for (cp = clockRanges; cp != NULL; cp = cp->next) {
- /* DivFactor and MulFactor must be > 0 */
- cp->ClockDivFactor = max(1, cp->ClockDivFactor);
- cp->ClockMulFactor = max(1, cp->ClockMulFactor);
- }
-
- /* Scan the mode pool for matching names */
- for (n = 0; n < ntypes; n++) {
- int type = types[n];
- for (p = scrp->modePool; p != NULL; p = p->next) {
-
- /* scan through the modes in the sort order above */
- if ((p->type & type) != type)
- continue;
-
- if (strcmp(p->name, modep->name) == 0) {
-
- /* Skip over previously rejected modes */
- if (p->status != MODE_OK) {
- if (!found)
- status = p->status;
- continue;
- }
-
- /* Skip over previously considered modes */
- if (p->prev)
- continue;
-
- if (p->type & M_T_BUILTIN) {
- return xf86HandleBuiltinMode(scrp, p,modep, clockRanges,
- allowDiv2);
- }
-
- /* Check clock is in range */
- cp = xf86FindClockRangeForMode(clockRanges, p);
- if (cp == NULL) {
- /*
- * XXX Could do more here to provide a more detailed
- * reason for not finding a mode.
- */
- p->status = MODE_CLOCK_RANGE;
- if (!found)
- status = MODE_CLOCK_RANGE;
- continue;
- }
-
- /*
- * If programmable clock and strategy is not
- * LOOKUP_BEST_REFRESH, the required mode has been found,
- * otherwise record the refresh and continue looking.
- */
- if (scrp->progClock) {
- found = TRUE;
- if (strategy != LOOKUP_BEST_REFRESH) {
- bestMode = p;
- DivFactor = cp->ClockDivFactor;
- MulFactor = cp->ClockMulFactor;
- ModePrivFlags = cp->PrivFlags;
- break;
- }
- refresh = xf86ModeVRefresh(p);
- if (p->Flags & V_INTERLACE)
- refresh /= INTERLACE_REFRESH_WEIGHT;
- if (refresh > bestRefresh) {
- bestMode = p;
- DivFactor = cp->ClockDivFactor;
- MulFactor = cp->ClockMulFactor;
- ModePrivFlags = cp->PrivFlags;
- bestRefresh = refresh;
- }
- continue;
- }
-
- /*
- * Clock is in range, so if it is not a programmable clock, find
- * a matching clock.
- */
-
- i = xf86GetNearestClock(scrp, p->Clock, allowDiv2,
- cp->ClockDivFactor, cp->ClockMulFactor, &k);
- /*
- * If the clock is too far from the requested clock, this
- * mode is no good.
- */
- if (k & V_CLKDIV2)
- gap = abs((p->Clock * 2) -
- ((scrp->clock[i] * cp->ClockDivFactor) /
- cp->ClockMulFactor));
- else
- gap = abs(p->Clock -
- ((scrp->clock[i] * cp->ClockDivFactor) /
- cp->ClockMulFactor));
- if (gap > minimumGap) {
- p->status = MODE_NOCLOCK;
- if (!found)
- status = MODE_NOCLOCK;
- continue;
- }
- found = TRUE;
-
- if (strategy == LOOKUP_BEST_REFRESH) {
- refresh = xf86ModeVRefresh(p);
- if (p->Flags & V_INTERLACE)
- refresh /= INTERLACE_REFRESH_WEIGHT;
- if (refresh > bestRefresh) {
- bestMode = p;
- DivFactor = cp->ClockDivFactor;
- MulFactor = cp->ClockMulFactor;
- ModePrivFlags = cp->PrivFlags;
- extraFlags = k;
- clockIndex = i;
- bestRefresh = refresh;
- }
- continue;
- }
- if (strategy == LOOKUP_CLOSEST_CLOCK) {
- if (gap < minimumGap) {
- bestMode = p;
- DivFactor = cp->ClockDivFactor;
- MulFactor = cp->ClockMulFactor;
- ModePrivFlags = cp->PrivFlags;
- extraFlags = k;
- clockIndex = i;
- minimumGap = gap;
- }
- continue;
- }
- /*
- * If strategy is neither LOOKUP_BEST_REFRESH or
- * LOOKUP_CLOSEST_CLOCK the required mode has been found.
- */
- bestMode = p;
- DivFactor = cp->ClockDivFactor;
- MulFactor = cp->ClockMulFactor;
- ModePrivFlags = cp->PrivFlags;
- extraFlags = k;
- clockIndex = i;
- break;
- }
- }
- if (found) break;
- }
- if (!found || bestMode == NULL)
- return status;
-
- /* Fill in the mode parameters */
- if (scrp->progClock) {
- modep->Clock = bestMode->Clock;
- modep->ClockIndex = -1;
- modep->SynthClock = (modep->Clock * MulFactor) / DivFactor;
- } else {
- modep->Clock = (scrp->clock[clockIndex] * DivFactor) /
- MulFactor;
- modep->ClockIndex = clockIndex;
- modep->SynthClock = scrp->clock[clockIndex];
- if (extraFlags & V_CLKDIV2) {
- modep->Clock /= 2;
- modep->SynthClock /= 2;
- }
- }
- modep->type = bestMode->type;
- modep->PrivFlags = ModePrivFlags;
- modep->HDisplay = bestMode->HDisplay;
- modep->HSyncStart = bestMode->HSyncStart;
- modep->HSyncEnd = bestMode->HSyncEnd;
- modep->HTotal = bestMode->HTotal;
- modep->HSkew = bestMode->HSkew;
- modep->VDisplay = bestMode->VDisplay;
- modep->VSyncStart = bestMode->VSyncStart;
- modep->VSyncEnd = bestMode->VSyncEnd;
- modep->VTotal = bestMode->VTotal;
- modep->VScan = bestMode->VScan;
- modep->Flags = bestMode->Flags | extraFlags;
- modep->CrtcHDisplay = bestMode->CrtcHDisplay;
- modep->CrtcHBlankStart = bestMode->CrtcHBlankStart;
- modep->CrtcHSyncStart = bestMode->CrtcHSyncStart;
- modep->CrtcHSyncEnd = bestMode->CrtcHSyncEnd;
- modep->CrtcHBlankEnd = bestMode->CrtcHBlankEnd;
- modep->CrtcHTotal = bestMode->CrtcHTotal;
- modep->CrtcHSkew = bestMode->CrtcHSkew;
- modep->CrtcVDisplay = bestMode->CrtcVDisplay;
- modep->CrtcVBlankStart = bestMode->CrtcVBlankStart;
- modep->CrtcVSyncStart = bestMode->CrtcVSyncStart;
- modep->CrtcVSyncEnd = bestMode->CrtcVSyncEnd;
- modep->CrtcVBlankEnd = bestMode->CrtcVBlankEnd;
- modep->CrtcVTotal = bestMode->CrtcVTotal;
- modep->CrtcHAdjusted = bestMode->CrtcHAdjusted;
- modep->CrtcVAdjusted = bestMode->CrtcVAdjusted;
- modep->HSync = bestMode->HSync;
- modep->VRefresh = bestMode->VRefresh;
- modep->Private = bestMode->Private;
- modep->PrivSize = bestMode->PrivSize;
-
- bestMode->prev = modep;
-
- return MODE_OK;
-}
-
-/*
- * xf86CheckModeForMonitor
- *
- * This function takes a mode and monitor description, and determines
- * if the mode is valid for the monitor.
- */
-ModeStatus
-xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor)
-{
- int i;
-
- /* Sanity checks */
- if (mode == NULL || monitor == NULL) {
- ErrorF("xf86CheckModeForMonitor: called with invalid parameters\n");
- return MODE_ERROR;
- }
-
- DebugF("xf86CheckModeForMonitor(%p %s, %p %s)\n",
- mode, mode->name, monitor, monitor->id);
-
- /* Some basic mode validity checks */
- if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart ||
- mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal)
- return MODE_H_ILLEGAL;
-
- if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart ||
- mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal)
- return MODE_V_ILLEGAL;
-
- if (monitor->nHsync > 0) {
- /* Check hsync against the allowed ranges */
- float hsync = xf86ModeHSync(mode);
- for (i = 0; i < monitor->nHsync; i++)
- if ((hsync > monitor->hsync[i].lo * (1.0 - SYNC_TOLERANCE)) &&
- (hsync < monitor->hsync[i].hi * (1.0 + SYNC_TOLERANCE)))
- break;
-
- /* Now see whether we ran out of sync ranges without finding a match */
- if (i == monitor->nHsync)
- return MODE_HSYNC;
- }
-
- if (monitor->nVrefresh > 0) {
- /* Check vrefresh against the allowed ranges */
- float vrefrsh = xf86ModeVRefresh(mode);
- for (i = 0; i < monitor->nVrefresh; i++)
- if ((vrefrsh > monitor->vrefresh[i].lo * (1.0 - SYNC_TOLERANCE)) &&
- (vrefrsh < monitor->vrefresh[i].hi * (1.0 + SYNC_TOLERANCE)))
- break;
-
- /* Now see whether we ran out of refresh ranges without finding a match */
- if (i == monitor->nVrefresh)
- return MODE_VSYNC;
- }
-
- /* Force interlaced modes to have an odd VTotal */
- if (mode->Flags & V_INTERLACE)
- mode->CrtcVTotal = mode->VTotal |= 1;
-
- /*
- * This code stops cvt -r modes, and only cvt -r modes, from hitting 15y+
- * old CRTs which might, when there is a lot of solar flare activity and
- * when the celestial bodies are unfavourably aligned, implode trying to
- * sync to it. It's called "Protecting the user from doing anything stupid".
- * -- libv
- */
-
- if (xf86ModeIsReduced(mode)) {
- if (!monitor->reducedblanking && !(mode->type & M_T_DRIVER))
- return MODE_NO_REDUCED;
- }
-
- if ((monitor->maxPixClock) && (mode->Clock > monitor->maxPixClock))
- return MODE_CLOCK_HIGH;
-
- return MODE_OK;
-}
-
-/*
- * xf86CheckModeSize
- *
- * An internal routine to check if a mode fits in video memory. This tries to
- * avoid overflows that would otherwise occur when video memory size is greater
- * than 256MB.
- */
-static Bool
-xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y)
-{
- int bpp = scrp->fbFormat.bitsPerPixel,
- pad = scrp->fbFormat.scanlinePad;
- int lineWidth, lastWidth;
-
- if (scrp->depth == 4)
- pad *= 4; /* 4 planes */
-
- /* Sanity check */
- if ((w < 0) || (x < 0) || (y <= 0))
- return FALSE;
-
- lineWidth = (((w * bpp) + pad - 1) / pad) * pad;
- lastWidth = x * bpp;
-
- /*
- * At this point, we need to compare
- *
- * (lineWidth * (y - 1)) + lastWidth
- *
- * against
- *
- * scrp->videoRam * (1024 * 8)
- *
- * These are bit quantities. To avoid overflows, do the comparison in
- * terms of BITMAP_SCANLINE_PAD units. This assumes BITMAP_SCANLINE_PAD
- * is a power of 2. We currently use 32, which limits us to a video
- * memory size of 8GB.
- */
-
- lineWidth = (lineWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD;
- lastWidth = (lastWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD;
-
- if ((lineWidth * (y - 1) + lastWidth) >
- (scrp->videoRam * ((1024 * 8) / BITMAP_SCANLINE_PAD)))
- return FALSE;
-
- return TRUE;
-}
-
-/*
- * xf86InitialCheckModeForDriver
- *
- * This function checks if a mode satisfies a driver's initial requirements:
- * - mode size fits within the available pixel area (memory)
- * - width lies within the range of supported line pitches
- * - mode size fits within virtual size (if fixed)
- * - horizontal timings are in range
- *
- * This function takes the following parameters:
- * scrp ScrnInfoPtr
- * mode mode to check
- * maxPitch (optional) maximum line pitch
- * virtualX (optional) virtual width requested
- * virtualY (optional) virtual height requested
- *
- * In addition, the following fields from the ScrnInfoRec are used:
- * monitor pointer to structure for monitor section
- * fbFormat pixel format for the framebuffer
- * videoRam video memory size (in kB)
- * maxHValue maximum horizontal timing value
- * maxVValue maximum vertical timing value
- */
-
-ModeStatus
-xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode,
- ClockRangePtr clockRanges,
- LookupModeFlags strategy,
- int maxPitch, int virtualX, int virtualY)
-{
- ClockRangePtr cp;
- ModeStatus status;
- Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0;
- int i, needDiv2;
-
- /* Sanity checks */
- if (!scrp || !mode || !clockRanges) {
- ErrorF("xf86InitialCheckModeForDriver: "
- "called with invalid parameters\n");
- return MODE_ERROR;
- }
-
- DebugF("xf86InitialCheckModeForDriver(%p, %p %s, %p, 0x%x, %d, %d, %d)\n",
- scrp, mode, mode->name , clockRanges, strategy, maxPitch, virtualX, virtualY);
-
- /* Some basic mode validity checks */
- if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart ||
- mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal)
- return MODE_H_ILLEGAL;
-
- if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart ||
- mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal)
- return MODE_V_ILLEGAL;
-
- if (!xf86CheckModeSize(scrp, mode->HDisplay, mode->HDisplay,
- mode->VDisplay))
- return MODE_MEM;
-
- if (maxPitch > 0 && mode->HDisplay > maxPitch)
- return MODE_BAD_WIDTH;
-
- if (virtualX > 0 && mode->HDisplay > virtualX)
- return MODE_VIRTUAL_X;
-
- if (virtualY > 0 && mode->VDisplay > virtualY)
- return MODE_VIRTUAL_Y;
-
- if (scrp->maxHValue > 0 && mode->HTotal > scrp->maxHValue)
- return MODE_BAD_HVALUE;
-
- if (scrp->maxVValue > 0 && mode->VTotal > scrp->maxVValue)
- return MODE_BAD_VVALUE;
-
- /*
- * The use of the DisplayModeRec's Crtc* and SynthClock elements below is
- * provisional, in that they are later reused by the driver at mode-set
- * time. Here, they are temporarily enlisted to contain the mode timings
- * as seen by the CRT or panel (rather than the CRTC). The driver's
- * ValidMode() is allowed to modify these so it can deal with such things
- * as mode stretching and/or centering. The driver should >NOT< modify the
- * user-supplied values as these are reported back when mode validation is
- * said and done.
- */
- /*
- * NOTE: We (ab)use the mode->Crtc* values here to store timing
- * information for the calculation of Hsync and Vrefresh. Before
- * these values are calculated the driver is given the opportunity
- * to either set these HSync and VRefresh itself or modify the timing
- * values.
- * The difference to the final calculation is small but imortand:
- * here we pass the flag INTERLACE_HALVE_V regardless if the driver
- * sets it or not. This way our calculation of VRefresh has the same
- * effect as if we do if (flags & V_INTERLACE) refresh *= 2.0
- * This dual use of the mode->Crtc* values will certainly create
- * confusion and is bad software design. However since it's part of
- * the driver API it's hard to change.
- */
-
- if (scrp->ValidMode) {
-
- xf86SetModeCrtc(mode, INTERLACE_HALVE_V);
-
- cp = xf86FindClockRangeForMode(clockRanges, mode);
- if (!cp)
- return MODE_CLOCK_RANGE;
-
- if (cp->ClockMulFactor < 1)
- cp->ClockMulFactor = 1;
- if (cp->ClockDivFactor < 1)
- cp->ClockDivFactor = 1;
-
- /*
- * XXX The effect of clock dividers and multipliers on the monitor's
- * pixel clock needs to be verified.
- */
- if (scrp->progClock) {
- mode->SynthClock = mode->Clock;
- } else {
- i = xf86GetNearestClock(scrp, mode->Clock, allowDiv2,
- cp->ClockDivFactor, cp->ClockMulFactor,
- &needDiv2);
- mode->SynthClock = (scrp->clock[i] * cp->ClockDivFactor) /
- cp->ClockMulFactor;
- if (needDiv2 & V_CLKDIV2)
- mode->SynthClock /= 2;
- }
-
- status = (*scrp->ValidMode)(scrp->scrnIndex, mode, FALSE,
- MODECHECK_INITIAL);
- if (status != MODE_OK)
- return status;
-
- if (mode->HSync <= 0.0)
- mode->HSync = (float)mode->SynthClock / (float)mode->CrtcHTotal;
- if (mode->VRefresh <= 0.0)
- mode->VRefresh = (mode->SynthClock * 1000.0)
- / (mode->CrtcHTotal * mode->CrtcVTotal);
- }
-
- mode->HSync = xf86ModeHSync(mode);
- mode->VRefresh = xf86ModeVRefresh(mode);
-
- /* Assume it is OK */
- return MODE_OK;
-}
-
-/*
- * xf86CheckModeForDriver
- *
- * This function is for checking modes while the server is running (for
- * use mainly by the VidMode extension).
- *
- * This function checks if a mode satisfies a driver's requirements:
- * - width lies within the line pitch
- * - mode size fits within virtual size
- * - horizontal/vertical timings are in range
- *
- * This function takes the following parameters:
- * scrp ScrnInfoPtr
- * mode mode to check
- * flags not (currently) used
- *
- * In addition, the following fields from the ScrnInfoRec are used:
- * maxHValue maximum horizontal timing value
- * maxVValue maximum vertical timing value
- * virtualX virtual width
- * virtualY virtual height
- * clockRanges allowable clock ranges
- */
-
-ModeStatus
-xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags)
-{
- ClockRangePtr cp;
- int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1;
- int extraFlags = 0;
- int clockIndex = -1;
- int MulFactor = 1;
- int DivFactor = 1;
- int ModePrivFlags = 0;
- ModeStatus status = MODE_NOMODE;
-
- /* Some sanity checking */
- if (scrp == NULL || (!scrp->progClock && scrp->numClocks == 0)) {
- ErrorF("xf86CheckModeForDriver: called with invalid scrnInfoRec\n");
- return MODE_ERROR;
- }
- if (mode == NULL) {
- ErrorF("xf86CheckModeForDriver: called with invalid modep\n");
- return MODE_ERROR;
- }
-
- /* Check the mode size */
- if (mode->HDisplay > scrp->virtualX)
- return MODE_VIRTUAL_X;
-
- if (mode->VDisplay > scrp->virtualY)
- return MODE_VIRTUAL_Y;
-
- if (scrp->maxHValue > 0 && mode->HTotal > scrp->maxHValue)
- return MODE_BAD_HVALUE;
-
- if (scrp->maxVValue > 0 && mode->VTotal > scrp->maxVValue)
- return MODE_BAD_VVALUE;
-
- for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) {
- /* DivFactor and MulFactor must be > 0 */
- cp->ClockDivFactor = max(1, cp->ClockDivFactor);
- cp->ClockMulFactor = max(1, cp->ClockMulFactor);
- }
-
- if (scrp->progClock) {
- /* Check clock is in range */
- for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) {
- if (modeInClockRange(cp, mode))
- break;
- }
- if (cp == NULL) {
- return MODE_CLOCK_RANGE;
- }
- /*
- * If programmable clock the required mode has been found
- */
- DivFactor = cp->ClockDivFactor;
- MulFactor = cp->ClockMulFactor;
- ModePrivFlags = cp->PrivFlags;
- } else {
- status = MODE_CLOCK_RANGE;
- /* Check clock is in range */
- for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) {
- if (modeInClockRange(cp, mode)) {
- /*
- * Clock is in range, so if it is not a programmable clock,
- * find a matching clock.
- */
-
- i = xf86GetNearestClock(scrp, mode->Clock, 0,
- cp->ClockDivFactor, cp->ClockMulFactor, &k);
- /*
- * If the clock is too far from the requested clock, this
- * mode is no good.
- */
- if (k & V_CLKDIV2)
- gap = abs((mode->Clock * 2) -
- ((scrp->clock[i] * cp->ClockDivFactor) /
- cp->ClockMulFactor));
- else
- gap = abs(mode->Clock -
- ((scrp->clock[i] * cp->ClockDivFactor) /
- cp->ClockMulFactor));
- if (gap > minimumGap) {
- status = MODE_NOCLOCK;
- continue;
- }
-
- DivFactor = cp->ClockDivFactor;
- MulFactor = cp->ClockMulFactor;
- ModePrivFlags = cp->PrivFlags;
- extraFlags = k;
- clockIndex = i;
- break;
- }
- }
- if (cp == NULL)
- return status;
- }
-
- /* Fill in the mode parameters */
- if (scrp->progClock) {
- mode->ClockIndex = -1;
- mode->SynthClock = (mode->Clock * MulFactor) / DivFactor;
- } else {
- mode->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor;
- mode->ClockIndex = clockIndex;
- mode->SynthClock = scrp->clock[clockIndex];
- if (extraFlags & V_CLKDIV2) {
- mode->Clock /= 2;
- mode->SynthClock /= 2;
- }
- }
- mode->PrivFlags = ModePrivFlags;
-
- return MODE_OK;
-}
-
-static int
-inferVirtualSize(ScrnInfoPtr scrp, DisplayModePtr modes, int *vx, int *vy)
-{
- float aspect = 0.0;
- MonPtr mon = scrp->monitor;
- xf86MonPtr DDC;
- int x = 0, y = 0;
- DisplayModePtr mode;
-
- if (!mon) return 0;
- DDC = mon->DDC;
-
- if (DDC && DDC->ver.revision >= 4) {
- /* For 1.4, we might actually get native pixel format. How novel. */
- if (PREFERRED_TIMING_MODE(DDC->features.msc)) {
- for (mode = modes; mode; mode = mode->next) {
- if (mode->type & (M_T_DRIVER | M_T_PREFERRED)) {
- x = mode->HDisplay;
- y = mode->VDisplay;
- goto found;
- }
- }
- }
- /*
- * Even if we don't, we might get aspect ratio from extra CVT info
- * or from the monitor size fields. TODO.
- */
- }
-
- /*
- * Technically this triggers if either is zero. That wasn't legal
- * before EDID 1.4, but right now we'll get that wrong. TODO.
- */
- if (!aspect) {
- if (!mon->widthmm || !mon->heightmm)
- aspect = 4.0/3.0;
- else
- aspect = (float)mon->widthmm / (float)mon->heightmm;
- }
-
- /* find the largest M_T_DRIVER mode with that aspect ratio */
- for (mode = modes; mode; mode = mode->next) {
- float mode_aspect, metaspect;
- if (!(mode->type & (M_T_DRIVER|M_T_USERDEF)))
- continue;
- mode_aspect = (float)mode->HDisplay / (float)mode->VDisplay;
- metaspect = aspect / mode_aspect;
- /* 5% slop or so, since we only get size in centimeters */
- if (fabs(1.0 - metaspect) < 0.05) {
- if ((mode->HDisplay > x) && (mode->VDisplay > y)) {
- x = mode->HDisplay;
- y = mode->VDisplay;
- }
- }
- }
-
- if (!x || !y) {
- xf86DrvMsg(scrp->scrnIndex, X_WARNING,
- "Unable to estimate virtual size\n");
- return 0;
- }
-
-found:
- *vx = x;
- *vy = y;
-
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "Estimated virtual size for aspect ratio %.4f is %dx%d\n",
- aspect, *vx, *vy);
-
- return 1;
-}
-
-/* Least common multiple */
-static unsigned int
-LCM(unsigned int x, unsigned int y)
-{
- unsigned int m = x, n = y, o;
-
- while ((o = m % n))
- {
- m = n;
- n = o;
- }
-
- return (x / n) * y;
-}
-
-/*
- * Given various screen attributes, determine the minimum scanline width such
- * that each scanline is server and DDX padded and any pixels with imbedded
- * bank boundaries are off-screen. This function returns -1 if such a width
- * cannot exist.
- */
-static int
-scanLineWidth(
- unsigned int xsize, /* pixels */
- unsigned int ysize, /* pixels */
- unsigned int width, /* pixels */
- unsigned long BankSize, /* char's */
- PixmapFormatRec *pBankFormat,
- unsigned int nWidthUnit /* bits */
-)
-{
- unsigned long nBitsPerBank, nBitsPerScanline, nBitsPerScanlinePadUnit;
- unsigned long minBitsPerScanline, maxBitsPerScanline;
-
- /* Sanity checks */
-
- if (!nWidthUnit || !pBankFormat)
- return -1;
-
- nBitsPerBank = BankSize * 8;
- if (nBitsPerBank % pBankFormat->scanlinePad)
- return -1;
-
- if (xsize > width)
- width = xsize;
- nBitsPerScanlinePadUnit = LCM(pBankFormat->scanlinePad, nWidthUnit);
- nBitsPerScanline =
- (((width * pBankFormat->bitsPerPixel) + nBitsPerScanlinePadUnit - 1) /
- nBitsPerScanlinePadUnit) * nBitsPerScanlinePadUnit;
- width = nBitsPerScanline / pBankFormat->bitsPerPixel;
-
- if (!xsize || !(nBitsPerBank % pBankFormat->bitsPerPixel))
- return (int)width;
-
- /*
- * Scanlines will be server-pad aligned at this point. They will also be
- * a multiple of nWidthUnit bits long. Ensure that pixels with imbedded
- * bank boundaries are off-screen.
- *
- * It seems reasonable to limit total frame buffer size to 1/16 of the
- * theoretical maximum address space size. On a machine with 32-bit
- * addresses (to 8-bit quantities) this turns out to be 256MB. Not only
- * does this provide a simple limiting condition for the loops below, but
- * it also prevents unsigned long wraparounds.
- */
- if (!ysize)
- return -1;
-
- minBitsPerScanline = xsize * pBankFormat->bitsPerPixel;
- if (minBitsPerScanline > nBitsPerBank)
- return -1;
-
- if (ysize == 1)
- return (int)width;
-
- maxBitsPerScanline =
- (((unsigned long)(-1) >> 1) - minBitsPerScanline) / (ysize - 1);
- while (nBitsPerScanline <= maxBitsPerScanline)
- {
- unsigned long BankBase, BankUnit;
-
- BankUnit = ((nBitsPerBank + nBitsPerScanline - 1) / nBitsPerBank) *
- nBitsPerBank;
- if (!(BankUnit % nBitsPerScanline))
- return (int)width;
-
- for (BankBase = BankUnit; ; BankBase += nBitsPerBank)
- {
- unsigned long x, y;
-
- y = BankBase / nBitsPerScanline;
- if (y >= ysize)
- return (int)width;
-
- x = BankBase % nBitsPerScanline;
- if (!(x % pBankFormat->bitsPerPixel))
- continue;
-
- if (x < minBitsPerScanline)
- {
- /*
- * Skip ahead certain widths by dividing the excess scanline
- * amongst the y's.
- */
- y *= nBitsPerScanlinePadUnit;
- nBitsPerScanline +=
- ((x + y - 1) / y) * nBitsPerScanlinePadUnit;
- width = nBitsPerScanline / pBankFormat->bitsPerPixel;
- break;
- }
-
- if (BankBase != BankUnit)
- continue;
-
- if (!(nBitsPerScanline % x))
- return (int)width;
-
- BankBase = ((nBitsPerScanline - minBitsPerScanline) /
- (nBitsPerScanline - x)) * BankUnit;
- }
- }
-
- return -1;
-}
-
-/*
- * xf86ValidateModes
- *
- * This function takes a set of mode names, modes and limiting conditions,
- * and selects a set of modes and parameters based on those conditions.
- *
- * This function takes the following parameters:
- * scrp ScrnInfoPtr
- * availModes the list of modes available for the monitor
- * modeNames (optional) list of mode names that the screen is requesting
- * clockRanges a list of clock ranges
- * linePitches (optional) a list of line pitches
- * minPitch (optional) minimum line pitch (in pixels)
- * maxPitch (optional) maximum line pitch (in pixels)
- * pitchInc (mandatory) pitch increment (in bits)
- * minHeight (optional) minimum virtual height (in pixels)
- * maxHeight (optional) maximum virtual height (in pixels)
- * virtualX (optional) virtual width requested (in pixels)
- * virtualY (optional) virtual height requested (in pixels)
- * apertureSize size of video aperture (in bytes)
- * strategy how to decide which mode to use from multiple modes with
- * the same name
- *
- * In addition, the following fields from the ScrnInfoRec are used:
- * clocks a list of discrete clocks
- * numClocks number of discrete clocks
- * progClock clock is programmable
- * monitor pointer to structure for monitor section
- * fbFormat format of the framebuffer
- * videoRam video memory size
- * maxHValue maximum horizontal timing value
- * maxVValue maximum vertical timing value
- * xInc horizontal timing increment (defaults to 8 pixels)
- *
- * The function fills in the following ScrnInfoRec fields:
- * modePool A subset of the modes available to the monitor which
- * are compatible with the driver.
- * modes one mode entry for each of the requested modes, with the
- * status field filled in to indicate if the mode has been
- * accepted or not.
- * virtualX the resulting virtual width
- * virtualY the resulting virtual height
- * displayWidth the resulting line pitch
- *
- * The function's return value is the number of matching modes found, or -1
- * if an unrecoverable error was encountered.
- */
-
-int
-xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
- char **modeNames, ClockRangePtr clockRanges,
- int *linePitches, int minPitch, int maxPitch, int pitchInc,
- int minHeight, int maxHeight, int virtualX, int virtualY,
- int apertureSize, LookupModeFlags strategy)
-{
- DisplayModePtr p, q, r, new, last, *endp;
- int i, numModes = 0;
- ModeStatus status;
- int linePitch = -1, virtX = 0, virtY = 0;
- int newLinePitch, newVirtX, newVirtY;
- int modeSize; /* in pixels */
- Bool validateAllDefaultModes = FALSE;
- Bool userModes = FALSE;
- int saveType;
- PixmapFormatRec *BankFormat;
- ClockRangePtr cp;
- ClockRangePtr storeClockRanges;
- int numTimings = 0;
- range hsync[MAX_HSYNC];
- range vrefresh[MAX_VREFRESH];
- Bool inferred_virtual = FALSE;
-
- DebugF("xf86ValidateModes(%p, %p, %p, %p,\n\t\t %p, %d, %d, %d, %d, %d, %d, %d, %d, 0x%x)\n",
- scrp, availModes, modeNames, clockRanges,
- linePitches, minPitch, maxPitch, pitchInc,
- minHeight, maxHeight, virtualX, virtualY,
- apertureSize, strategy
- );
-
- /* Some sanity checking */
- if (scrp == NULL || scrp->name == NULL || !scrp->monitor ||
- (!scrp->progClock && scrp->numClocks == 0)) {
- ErrorF("xf86ValidateModes: called with invalid scrnInfoRec\n");
- return -1;
- }
- if (linePitches != NULL && linePitches[0] <= 0) {
- ErrorF("xf86ValidateModes: called with invalid linePitches\n");
- return -1;
- }
- if (pitchInc <= 0) {
- ErrorF("xf86ValidateModes: called with invalid pitchInc\n");
- return -1;
- }
- if ((virtualX > 0) != (virtualY > 0)) {
- ErrorF("xf86ValidateModes: called with invalid virtual resolution\n");
- return -1;
- }
-
- /*
- * If requested by the driver, allow missing hsync and/or vrefresh ranges
- * in the monitor section.
- */
- if (strategy & LOOKUP_OPTIONAL_TOLERANCES) {
- strategy &= ~LOOKUP_OPTIONAL_TOLERANCES;
- } else {
- const char *type = "";
- Bool specified = FALSE;
-
- if (scrp->monitor->nHsync <= 0) {
- if (numTimings > 0) {
- scrp->monitor->nHsync = numTimings;
- for (i = 0; i < numTimings; i++) {
- scrp->monitor->hsync[i].lo = hsync[i].lo;
- scrp->monitor->hsync[i].hi = hsync[i].hi;
- }
- } else {
- scrp->monitor->hsync[0].lo = 31.5;
- scrp->monitor->hsync[0].hi = 48.0;
- scrp->monitor->nHsync = 1;
- }
- type = "default ";
- } else {
- specified = TRUE;
- }
- for (i = 0; i < scrp->monitor->nHsync; i++) {
- if (scrp->monitor->hsync[i].lo == scrp->monitor->hsync[i].hi)
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "%s: Using %shsync value of %.2f kHz\n",
- scrp->monitor->id, type,
- scrp->monitor->hsync[i].lo);
- else
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "%s: Using %shsync range of %.2f-%.2f kHz\n",
- scrp->monitor->id, type,
- scrp->monitor->hsync[i].lo,
- scrp->monitor->hsync[i].hi);
- }
-
- type = "";
- if (scrp->monitor->nVrefresh <= 0) {
- if (numTimings > 0) {
- scrp->monitor->nVrefresh = numTimings;
- for (i = 0; i < numTimings; i++) {
- scrp->monitor->vrefresh[i].lo = vrefresh[i].lo;
- scrp->monitor->vrefresh[i].hi = vrefresh[i].hi;
- }
- } else {
- scrp->monitor->vrefresh[0].lo = 50;
- scrp->monitor->vrefresh[0].hi = 70;
- scrp->monitor->nVrefresh = 1;
- }
- type = "default ";
- } else {
- specified = TRUE;
- }
- for (i = 0; i < scrp->monitor->nVrefresh; i++) {
- if (scrp->monitor->vrefresh[i].lo == scrp->monitor->vrefresh[i].hi)
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "%s: Using %svrefresh value of %.2f Hz\n",
- scrp->monitor->id, type,
- scrp->monitor->vrefresh[i].lo);
- else
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "%s: Using %svrefresh range of %.2f-%.2f Hz\n",
- scrp->monitor->id, type,
- scrp->monitor->vrefresh[i].lo,
- scrp->monitor->vrefresh[i].hi);
- }
-
- type = "";
- if (!scrp->monitor->maxPixClock && !specified) {
- type = "default ";
- scrp->monitor->maxPixClock = 65000.0;
- }
- if (scrp->monitor->maxPixClock) {
- xf86DrvMsg(scrp->scrnIndex, X_INFO,
- "%s: Using %smaximum pixel clock of %.2f MHz\n",
- scrp->monitor->id, type,
- (float)scrp->monitor->maxPixClock / 1000.0);
- }
- }
-
- /*
- * Store the clockRanges for later use by the VidMode extension.
- */
- storeClockRanges = scrp->clockRanges;
- while (storeClockRanges != NULL) {
- storeClockRanges = storeClockRanges->next;
- }
- for (cp = clockRanges; cp != NULL; cp = cp->next,
- storeClockRanges = storeClockRanges->next) {
- storeClockRanges = xnfalloc(sizeof(ClockRange));
- if (scrp->clockRanges == NULL)
- scrp->clockRanges = storeClockRanges;
- memcpy(storeClockRanges, cp, sizeof(ClockRange));
- }
-
- /* Determine which pixmap format to pass to scanLineWidth() */
- if (scrp->depth > 4)
- BankFormat = &scrp->fbFormat;
- else
- BankFormat = xf86GetPixFormat(scrp, 1); /* >not< scrp->depth! */
-
- if (scrp->xInc <= 0)
- scrp->xInc = 8; /* Suitable for VGA and others */
-
-#define _VIRTUALX(x) ((((x) + scrp->xInc - 1) / scrp->xInc) * scrp->xInc)
-
- /*
- * Determine maxPitch if it wasn't given explicitly. Note linePitches
- * always takes precedence if is non-NULL. In that case the minPitch and
- * maxPitch values passed are ignored.
- */
- if (linePitches) {
- minPitch = maxPitch = linePitches[0];
- for (i = 1; linePitches[i] > 0; i++) {
- if (linePitches[i] > maxPitch)
- maxPitch = linePitches[i];
- if (linePitches[i] < minPitch)
- minPitch = linePitches[i];
- }
- }
-
- /* Initial check of virtual size against other constraints */
- scrp->virtualFrom = X_PROBED;
- /*
- * Initialise virtX and virtY if the values are fixed.
- */
- if (virtualY > 0) {
- if (maxHeight > 0 && virtualY > maxHeight) {
- xf86DrvMsg(scrp->scrnIndex, X_ERROR,
- "Virtual height (%d) is too large for the hardware "
- "(max %d)\n", virtualY, maxHeight);
- return -1;
- }
-
- if (minHeight > 0 && virtualY < minHeight) {
- xf86DrvMsg(scrp->scrnIndex, X_ERROR,
- "Virtual height (%d) is too small for the hardware "
- "(min %d)\n", virtualY, minHeight);
- return -1;
- }
-
- virtualX = _VIRTUALX(virtualX);
- if (linePitches != NULL) {
- for (i = 0; linePitches[i] != 0; i++) {
- if ((linePitches[i] >= virtualX) &&
- (linePitches[i] ==
- scanLineWidth(virtualX, virtualY, linePitches[i],
- apertureSize, BankFormat, pitchInc))) {
- linePitch = linePitches[i];
- break;
- }
- }
- } else {
- linePitch = scanLineWidth(virtualX, virtualY, minPitch,
- apertureSize, BankFormat, pitchInc);
- }
-
- if ((linePitch < minPitch) || (linePitch > maxPitch)) {
- xf86DrvMsg(scrp->scrnIndex, X_ERROR,
- "Virtual width (%d) is too large for the hardware "
- "(max %d)\n", virtualX, maxPitch);
- return -1;
- }
-
- if (!xf86CheckModeSize(scrp, linePitch, virtualX, virtualY)) {
- xf86DrvMsg(scrp->scrnIndex, X_ERROR,
- "Virtual size (%dx%d) (pitch %d) exceeds video memory\n",
- virtualX, virtualY, linePitch);
- return -1;
- }
-
- virtX = virtualX;
- virtY = virtualY;
- scrp->virtualFrom = X_CONFIG;
- } else if (!modeNames || !*modeNames) {
- /* No virtual size given in the config, try to infer */
- /* XXX this doesn't take m{in,ax}Pitch into account; oh well */
- inferred_virtual = inferVirtualSize(scrp, availModes, &virtX, &virtY);
- if (inferred_virtual)
- linePitch = scanLineWidth(virtX, virtY, minPitch, apertureSize,
- BankFormat, pitchInc);
- }
-
- /* Print clock ranges and scaled clocks */
- xf86ShowClockRanges(scrp, clockRanges);
-
- /*
- * If scrp->modePool hasn't been setup yet, set it up now. This allows the
- * modes that the driver definitely can't use to be weeded out early. Note
- * that a modePool mode's prev field is used to hold a pointer to the
- * member of the scrp->modes list for which a match was considered.
- */
- if (scrp->modePool == NULL) {
- q = NULL;
- for (p = availModes; p != NULL; p = p->next) {
- status = xf86InitialCheckModeForDriver(scrp, p, clockRanges,
- strategy, maxPitch,
- virtX, virtY);
-
- if (status == MODE_OK) {
- status = xf86CheckModeForMonitor(p, scrp->monitor);
- }
-
- if (status == MODE_OK) {
- new = xnfalloc(sizeof(DisplayModeRec));
- *new = *p;
- new->next = NULL;
- if (!q) {
- scrp->modePool = new;
- } else {
- q->next = new;
- }
- new->prev = NULL;
- q = new;
- q->name = xnfstrdup(p->name);
- q->status = MODE_OK;
- } else {
- printModeRejectMessage(scrp->scrnIndex, p, status);
- }
- }
-
- if (scrp->modePool == NULL) {
- xf86DrvMsg(scrp->scrnIndex, X_WARNING, "Mode pool is empty\n");
- return 0;
- }
- } else {
- for (p = scrp->modePool; p != NULL; p = p->next) {
- p->prev = NULL;
- p->status = MODE_OK;
- }
- }
-
- /*
- * Allocate one entry in scrp->modes for each named mode.
- */
- while (scrp->modes)
- xf86DeleteMode(&scrp->modes, scrp->modes);
- endp = &scrp->modes;
- last = NULL;
- if (modeNames != NULL) {
- for (i = 0; modeNames[i] != NULL; i++) {
- userModes = TRUE;
- new = xnfcalloc(1, sizeof(DisplayModeRec));
- new->prev = last;
- new->type = M_T_USERDEF;
- new->name = xnfstrdup(modeNames[i]);
- if (new->prev)
- new->prev->next = new;
- *endp = last = new;
- endp = &new->next;
- }
- }
-
- /* Lookup each mode */
-#ifdef RANDR
- if (!xf86Info.disableRandR
-#ifdef PANORAMIX
- && noPanoramiXExtension
-#endif
- )
- validateAllDefaultModes = TRUE;
-#endif
-
- for (p = scrp->modes; ; p = p->next) {
- Bool repeat;
-
- /*
- * If the supplied mode names don't produce a valid mode, scan through
- * unconsidered modePool members until one survives validation. This
- * is done in decreasing order by mode pixel area.
- */
-
- if (p == NULL) {
- if ((numModes > 0) && !validateAllDefaultModes)
- break;
-
- validateAllDefaultModes = TRUE;
- r = NULL;
- modeSize = 0;
- for (q = scrp->modePool; q != NULL; q = q->next) {
- if ((q->prev == NULL) && (q->status == MODE_OK)) {
- /*
- * Deal with the case where this mode wasn't considered
- * because of a builtin mode of the same name.
- */
- for (p = scrp->modes; p != NULL; p = p->next) {
- if ((p->status != MODE_OK) &&
- !strcmp(p->name, q->name))
- break;
- }
-
- if (p != NULL)
- q->prev = p;
- else {
- /*
- * A quick check to not allow default modes with
- * horizontal timing parameters that CRTs may have
- * problems with.
- */
- if (!scrp->monitor->reducedblanking &&
- (q->type & M_T_DEFAULT) &&
- ((double)q->HTotal / (double)q->HDisplay) < 1.15)
- continue;
-
- if (modeSize < (q->HDisplay * q->VDisplay)) {
- r = q;
- modeSize = q->HDisplay * q->VDisplay;
- }
- }
- }
- }
-
- if (r == NULL)
- break;
-
- p = xnfcalloc(1, sizeof(DisplayModeRec));
- p->prev = last;
- p->name = xnfstrdup(r->name);
- if (!userModes)
- p->type = M_T_USERDEF;
- if (p->prev)
- p->prev->next = p;
- *endp = last = p;
- endp = &p->next;
- }
-
- repeat = FALSE;
- lookupNext:
- if (repeat && ((status = p->status) != MODE_OK))
- printModeRejectMessage(scrp->scrnIndex, p, status);
- saveType = p->type;
- status = xf86LookupMode(scrp, p, clockRanges, strategy);
- if (repeat && status == MODE_NOMODE)
- continue;
- if (status != MODE_OK)
- printModeRejectMessage(scrp->scrnIndex, p, status);
- if (status == MODE_ERROR) {
- ErrorF("xf86ValidateModes: "
- "unexpected result from xf86LookupMode()\n");
- return -1;
- }
- if (status != MODE_OK) {
- if (p->status == MODE_OK)
- p->status = status;
- continue;
- }
- p->type |= saveType;
- repeat = TRUE;
-
- newLinePitch = linePitch;
- newVirtX = virtX;
- newVirtY = virtY;
-
- /*
- * Don't let non-user defined modes increase the virtual size
- */
- if (!(p->type & M_T_USERDEF) && (numModes > 0)) {
- if (p->HDisplay > virtX) {
- p->status = MODE_VIRTUAL_X;
- goto lookupNext;
- }
- if (p->VDisplay > virtY) {
- p->status = MODE_VIRTUAL_Y;
- goto lookupNext;
- }
- }
- /*
- * Adjust virtual width and height if the mode is too large for the
- * current values and if they are not fixed.
- */
- if (virtualX <= 0 && p->HDisplay > newVirtX)
- newVirtX = _VIRTUALX(p->HDisplay);
- if (virtualY <= 0 && p->VDisplay > newVirtY) {
- if (maxHeight > 0 && p->VDisplay > maxHeight) {
- p->status = MODE_VIRTUAL_Y; /* ? */
- goto lookupNext;
- }
- newVirtY = p->VDisplay;
- }
-
- /*
- * If virtual resolution is to be increased, revalidate it.
- */
- if ((virtX != newVirtX) || (virtY != newVirtY)) {
- if (linePitches != NULL) {
- newLinePitch = -1;
- for (i = 0; linePitches[i] != 0; i++) {
- if ((linePitches[i] >= newVirtX) &&
- (linePitches[i] >= linePitch) &&
- (linePitches[i] ==
- scanLineWidth(newVirtX, newVirtY, linePitches[i],
- apertureSize, BankFormat, pitchInc))) {
- newLinePitch = linePitches[i];
- break;
- }
- }
- } else {
- if (linePitch < minPitch)
- linePitch = minPitch;
- newLinePitch = scanLineWidth(newVirtX, newVirtY, linePitch,
- apertureSize, BankFormat,
- pitchInc);
- }
- if ((newLinePitch < minPitch) || (newLinePitch > maxPitch)) {
- p->status = MODE_BAD_WIDTH;
- goto lookupNext;
- }
-
- /*
- * Check that the pixel area required by the new virtual height
- * and line pitch isn't too large.
- */
- if (!xf86CheckModeSize(scrp, newLinePitch, newVirtX, newVirtY)) {
- p->status = MODE_MEM_VIRT;
- goto lookupNext;
- }
- }
-
- if (scrp->ValidMode) {
- /*
- * Give the driver a final say, passing it the proposed virtual
- * geometry.
- */
- scrp->virtualX = newVirtX;
- scrp->virtualY = newVirtY;
- scrp->displayWidth = newLinePitch;
- p->status = (scrp->ValidMode)(scrp->scrnIndex, p, FALSE,
- MODECHECK_FINAL);
-
- if (p->status != MODE_OK) {
- goto lookupNext;
- }
- }
-
- /* Mode has passed all the tests */
- virtX = newVirtX;
- virtY = newVirtY;
- linePitch = newLinePitch;
- p->status = MODE_OK;
- numModes++;
- }
-
- /*
- * If we estimated the virtual size above, we may have filtered away all
- * the modes that maximally match that size; scan again to find out and
- * fix up if so.
- */
- if (inferred_virtual) {
- int vx = 0, vy = 0;
- for (p = scrp->modes; p; p = p->next) {
- if (p->HDisplay > vx && p->VDisplay > vy) {
- vx = p->HDisplay;
- vy = p->VDisplay;
- }
- }
- if (vx < virtX || vy < virtY) {
- const int types[] = {
- M_T_BUILTIN | M_T_PREFERRED,
- M_T_BUILTIN,
- M_T_DRIVER | M_T_PREFERRED,
- M_T_DRIVER,
- 0
- };
- const int ntypes = sizeof(types) / sizeof(int);
- int n;
-
- /*
- * We did not find the estimated virtual size. So now we want to
- * find the largest mode available, but we want to search in the
- * modes in the order of "types" listed above.
- */
- for (n = 0; n < ntypes; n++) {
- int type = types[n];
-
- vx = 0; vy = 0;
- for (p = scrp->modes; p; p = p->next) {
- /* scan through the modes in the sort order above */
- if ((p->type & type) != type)
- continue;
- if (p->HDisplay > vx && p->VDisplay > vy) {
- vx = p->HDisplay;
- vy = p->VDisplay;
- }
- }
- if (vx && vy)
- /* Found one */
- break;
- }
- xf86DrvMsg(scrp->scrnIndex, X_WARNING,
- "Shrinking virtual size estimate from %dx%d to %dx%d\n",
- virtX, virtY, vx, vy);
- virtX = _VIRTUALX(vx);
- virtY = vy;
- for (p = scrp->modes; p; p = p->next) {
- if (numModes > 0) {
- if (p->HDisplay > virtX)
- p->status = MODE_VIRTUAL_X;
- if (p->VDisplay > virtY)
- p->status = MODE_VIRTUAL_Y;
- if (p->status != MODE_OK) {
- numModes--;
- printModeRejectMessage(scrp->scrnIndex, p, p->status);
- }
- }
- }
- if (linePitches != NULL) {
- for (i = 0; linePitches[i] != 0; i++) {
- if ((linePitches[i] >= virtX) &&
- (linePitches[i] ==
- scanLineWidth(virtX, virtY, linePitches[i],
- apertureSize, BankFormat, pitchInc))) {
- linePitch = linePitches[i];
- break;
- }
- }
- } else {
- linePitch = scanLineWidth(virtX, virtY, minPitch,
- apertureSize, BankFormat, pitchInc);
- }
- }
- }
-
- /* Update the ScrnInfoRec parameters */
-
- scrp->virtualX = virtX;
- scrp->virtualY = virtY;
- scrp->displayWidth = linePitch;
-
- if (numModes <= 0)
- return 0;
-
- /* Make the mode list into a circular list by joining up the ends */
- p = scrp->modes;
- while (p->next != NULL)
- p = p->next;
- /* p is now the last mode on the list */
- p->next = scrp->modes;
- scrp->modes->prev = p;
-
- if (minHeight > 0 && virtY < minHeight) {
- xf86DrvMsg(scrp->scrnIndex, X_ERROR,
- "Virtual height (%d) is too small for the hardware "
- "(min %d)\n", virtY, minHeight);
- return -1;
- }
-
- return numModes;
-}
-
-/*
- * xf86DeleteMode
- *
- * This function removes a mode from a list of modes.
- *
- * There are different types of mode lists:
- *
- * - singly linked linear lists, ending in NULL
- * - doubly linked linear lists, starting and ending in NULL
- * - doubly linked circular lists
- *
- */
-
-void
-xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode)
-{
- /* Catch the easy/insane cases */
- if (modeList == NULL || *modeList == NULL || mode == NULL)
- return;
-
- /* If the mode is at the start of the list, move the start of the list */
- if (*modeList == mode)
- *modeList = mode->next;
-
- /* If mode is the only one on the list, set the list to NULL */
- if ((mode == mode->prev) && (mode == mode->next)) {
- *modeList = NULL;
- } else {
- if ((mode->prev != NULL) && (mode->prev->next == mode))
- mode->prev->next = mode->next;
- if ((mode->next != NULL) && (mode->next->prev == mode))
- mode->next->prev = mode->prev;
- }
-
- free(mode->name);
- free(mode);
-}
-
-/*
- * xf86PruneDriverModes
- *
- * Remove modes from the driver's mode list which have been marked as
- * invalid.
- */
-
-void
-xf86PruneDriverModes(ScrnInfoPtr scrp)
-{
- DisplayModePtr first, p, n;
-
- p = scrp->modes;
- if (p == NULL)
- return;
-
- do {
- if (!(first = scrp->modes))
- return;
- n = p->next;
- if (p->status != MODE_OK) {
- xf86DeleteMode(&(scrp->modes), p);
- }
- p = n;
- } while (p != NULL && p != first);
-
- /* modePool is no longer needed, turf it */
- while (scrp->modePool) {
- /*
- * A modePool mode's prev field is used to hold a pointer to the
- * member of the scrp->modes list for which a match was considered.
- * Clear that pointer first, otherwise xf86DeleteMode might get
- * confused
- */
- scrp->modePool->prev = NULL;
- xf86DeleteMode(&scrp->modePool, scrp->modePool);
- }
-}
-
-
-/*
- * xf86SetCrtcForModes
- *
- * Goes through the screen's mode list, and initialises the Crtc
- * parameters for each mode. The initialisation includes adjustments
- * for interlaced and double scan modes.
- */
-void
-xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags)
-{
- DisplayModePtr p;
-
- /*
- * Store adjustFlags for use with the VidMode extension. There is an
- * implicit assumption here that SetCrtcForModes is called once.
- */
- scrp->adjustFlags = adjustFlags;
-
- p = scrp->modes;
- if (p == NULL)
- return;
-
- do {
- xf86SetModeCrtc(p, adjustFlags);
- DebugF("%sMode %s: %d (%d) %d %d (%d) %d %d (%d) %d %d (%d) %d\n",
- (p->type & M_T_DEFAULT) ? "Default " : "",
- p->name, p->CrtcHDisplay, p->CrtcHBlankStart,
- p->CrtcHSyncStart, p->CrtcHSyncEnd, p->CrtcHBlankEnd,
- p->CrtcHTotal, p->CrtcVDisplay, p->CrtcVBlankStart,
- p->CrtcVSyncStart, p->CrtcVSyncEnd, p->CrtcVBlankEnd,
- p->CrtcVTotal);
- p = p->next;
- } while (p != NULL && p != scrp->modes);
-}
-
-void
-xf86PrintModes(ScrnInfoPtr scrp)
-{
- DisplayModePtr p;
- float hsync, refresh = 0;
- char *desc, *desc2, *prefix, *uprefix;
-
- if (scrp == NULL)
- return;
-
- xf86DrvMsg(scrp->scrnIndex, scrp->virtualFrom, "Virtual size is %dx%d "
- "(pitch %d)\n", scrp->virtualX, scrp->virtualY,
- scrp->displayWidth);
-
- p = scrp->modes;
- if (p == NULL)
- return;
-
- do {
- desc = desc2 = "";
- hsync = xf86ModeHSync(p);
- refresh = xf86ModeVRefresh(p);
- if (p->Flags & V_INTERLACE) {
- desc = " (I)";
- }
- if (p->Flags & V_DBLSCAN) {
- desc = " (D)";
- }
- if (p->VScan > 1) {
- desc2 = " (VScan)";
- }
- if (p->type & M_T_BUILTIN)
- prefix = "Built-in mode";
- else if (p->type & M_T_DEFAULT)
- prefix = "Default mode";
- else if (p->type & M_T_DRIVER)
- prefix = "Driver mode";
- else
- prefix = "Mode";
- if (p->type & M_T_USERDEF)
- uprefix = "*";
- else
- uprefix = " ";
- if (hsync == 0 || refresh == 0) {
- if (p->name)
- xf86DrvMsg(scrp->scrnIndex, X_CONFIG,
- "%s%s \"%s\"\n", uprefix, prefix, p->name);
- else
- xf86DrvMsg(scrp->scrnIndex, X_PROBED,
- "%s%s %dx%d (unnamed)\n",
- uprefix, prefix, p->HDisplay, p->VDisplay);
- } else if (p->Clock == p->SynthClock) {
- xf86DrvMsg(scrp->scrnIndex, X_CONFIG,
- "%s%s \"%s\": %.1f MHz, %.1f kHz, %.1f Hz%s%s\n",
- uprefix, prefix, p->name, p->Clock / 1000.0,
- hsync, refresh, desc, desc2);
- } else {
- xf86DrvMsg(scrp->scrnIndex, X_CONFIG,
- "%s%s \"%s\": %.1f MHz (scaled from %.1f MHz), "
- "%.1f kHz, %.1f Hz%s%s\n",
- uprefix, prefix, p->name, p->Clock / 1000.0,
- p->SynthClock / 1000.0, hsync, refresh, desc, desc2);
- }
- if (hsync != 0 && refresh != 0)
- xf86PrintModeline(scrp->scrnIndex,p);
- p = p->next;
- } while (p != NULL && p != scrp->modes);
-}
+/* + * Copyright (c) 1997-2003 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +/* + * LCM() and scanLineWidth() are: + * + * Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of Marc Aurele La France not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Marc Aurele La France makes no representations + * about the suitability of this software for any purpose. It is provided + * "as-is" without express or implied warranty. + * + * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO + * EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * Copyright 1990,91,92,93 by Thomas Roell, Germany. + * Copyright 1991,92,93 by SGCS (Snitily Graphics Consulting Services), USA. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation, and that the name of Thomas Roell nor + * SGCS be used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * Thomas Roell nor SGCS makes no representations about the suitability + * of this software for any purpose. It is provided "as is" without + * express or implied warranty. + * + * THOMAS ROELL AND SGCS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR SGCS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Authors: Dirk Hohndel <hohndel@XFree86.Org> + * David Dawes <dawes@XFree86.Org> + * Marc La France <tsi@XFree86.Org> + * ... and others + * + * This file includes helper functions for mode related things. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <X11/X.h> +#include "xf86Modes.h" +#include "os.h" +#include "servermd.h" +#include "globals.h" +#include "xf86.h" +#include "xf86Priv.h" +#include "edid.h" + +static void +printModeRejectMessage(int index, DisplayModePtr p, int status) +{ + const char *type; + + if (p->type & M_T_BUILTIN) + type = "built-in "; + else if (p->type & M_T_DEFAULT) + type = "default "; + else if (p->type & M_T_DRIVER) + type = "driver "; + else + type = ""; + + xf86DrvMsg(index, X_INFO, "Not using %smode \"%s\" (%s)\n", type, p->name, + xf86ModeStatusToString(status)); +} + +/* + * xf86GetNearestClock -- + * Find closest clock to given frequency (in kHz). This assumes the + * number of clocks is greater than zero. + */ +int +xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2, + int DivFactor, int MulFactor, int *divider) +{ + int nearestClock = 0, nearestDiv = 1; + int minimumGap = abs(freq - scrp->clock[0]); + int i, j, k, gap; + + if (allowDiv2) + k = 2; + else + k = 1; + + /* Must set this here in case the best match is scrp->clock[0] */ + if (divider != NULL) + *divider = 0; + + for (i = 0; i < scrp->numClocks; i++) { + for (j = 1; j <= k; j++) { + gap = abs((freq * j) - ((scrp->clock[i] * DivFactor) / MulFactor)); + if ((gap < minimumGap) || + ((gap == minimumGap) && (j < nearestDiv))) { + minimumGap = gap; + nearestClock = i; + nearestDiv = j; + if (divider != NULL) + *divider = (j - 1) * V_CLKDIV2; + } + } + } + return nearestClock; +} + +/* + * xf86ModeStatusToString + * + * Convert a ModeStatus value to a printable message + */ + +const char * +xf86ModeStatusToString(ModeStatus status) +{ + switch (status) { + case MODE_OK: + return "Mode OK"; + case MODE_HSYNC: + return "hsync out of range"; + case MODE_VSYNC: + return "vrefresh out of range"; + case MODE_H_ILLEGAL: + return "illegal horizontal timings"; + case MODE_V_ILLEGAL: + return "illegal vertical timings"; + case MODE_BAD_WIDTH: + return "width requires unsupported line pitch"; + case MODE_NOMODE: + return "no mode of this name"; + case MODE_NO_INTERLACE: + return "interlace mode not supported"; + case MODE_NO_DBLESCAN: + return "doublescan mode not supported"; + case MODE_NO_VSCAN: + return "multiscan mode not supported"; + case MODE_MEM: + return "insufficient memory for mode"; + case MODE_VIRTUAL_X: + return "width too large for virtual size"; + case MODE_VIRTUAL_Y: + return "height too large for virtual size"; + case MODE_MEM_VIRT: + return "insufficient memory given virtual size"; + case MODE_NOCLOCK: + return "no clock available for mode"; + case MODE_CLOCK_HIGH: + return "mode clock too high"; + case MODE_CLOCK_LOW: + return "mode clock too low"; + case MODE_CLOCK_RANGE: + return "bad mode clock/interlace/doublescan"; + case MODE_BAD_HVALUE: + return "horizontal timing out of range"; + case MODE_BAD_VVALUE: + return "vertical timing out of range"; + case MODE_BAD_VSCAN: + return "VScan value out of range"; + case MODE_HSYNC_NARROW: + return "horizontal sync too narrow"; + case MODE_HSYNC_WIDE: + return "horizontal sync too wide"; + case MODE_HBLANK_NARROW: + return "horizontal blanking too narrow"; + case MODE_HBLANK_WIDE: + return "horizontal blanking too wide"; + case MODE_VSYNC_NARROW: + return "vertical sync too narrow"; + case MODE_VSYNC_WIDE: + return "vertical sync too wide"; + case MODE_VBLANK_NARROW: + return "vertical blanking too narrow"; + case MODE_VBLANK_WIDE: + return "vertical blanking too wide"; + case MODE_PANEL: + return "exceeds panel dimensions"; + case MODE_INTERLACE_WIDTH: + return "width too large for interlaced mode"; + case MODE_ONE_WIDTH: + return "all modes must have the same width"; + case MODE_ONE_HEIGHT: + return "all modes must have the same height"; + case MODE_ONE_SIZE: + return "all modes must have the same resolution"; + case MODE_NO_REDUCED: + return "monitor doesn't support reduced blanking"; + case MODE_BANDWIDTH: + return "mode requires too much memory bandwidth"; + case MODE_BAD: + return "unknown reason"; + case MODE_ERROR: + return "internal error"; + default: + return "unknown"; + } +} + +/* + * xf86ShowClockRanges() -- Print the clock ranges allowed + * and the clock values scaled by ClockMulFactor and ClockDivFactor + */ +void +xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges) +{ + ClockRangePtr cp; + int MulFactor = 1; + int DivFactor = 1; + int i, j; + int scaledClock; + + for (cp = clockRanges; cp != NULL; cp = cp->next) { + DivFactor = max(1, cp->ClockDivFactor); + MulFactor = max(1, cp->ClockMulFactor); + if (scrp->progClock) { + if (cp->minClock) { + if (cp->maxClock) { + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "Clock range: %6.2f to %6.2f MHz\n", + (double)cp->minClock / 1000.0, + (double)cp->maxClock / 1000.0); + } else { + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "Minimum clock: %6.2f MHz\n", + (double)cp->minClock / 1000.0); + } + } else { + if (cp->maxClock) { + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "Maximum clock: %6.2f MHz\n", + (double)cp->maxClock / 1000.0); + } + } + } else if (DivFactor > 1 || MulFactor > 1) { + j = 0; + for (i = 0; i < scrp->numClocks; i++) { + scaledClock = (scrp->clock[i] * DivFactor) / MulFactor; + if (scaledClock >= cp->minClock && scaledClock <= cp->maxClock) { + if ((j % 8) == 0) { + if (j > 0) + xf86ErrorF("\n"); + xf86DrvMsg(scrp->scrnIndex, X_INFO, "scaled clocks:"); + } + xf86ErrorF(" %6.2f", (double)scaledClock / 1000.0); + j++; + } + } + xf86ErrorF("\n"); + } + } +} + +static Bool +modeInClockRange(ClockRangePtr cp, DisplayModePtr p) +{ + return ((p->Clock >= cp->minClock) && + (p->Clock <= cp->maxClock) && + (cp->interlaceAllowed || !(p->Flags & V_INTERLACE)) && + (cp->doubleScanAllowed || + ((p->VScan <= 1) && !(p->Flags & V_DBLSCAN)))); +} + +/* + * xf86FindClockRangeForMode() [... like the name says ...] + */ +static ClockRangePtr +xf86FindClockRangeForMode(ClockRangePtr clockRanges, DisplayModePtr p) +{ + ClockRangePtr cp; + + for (cp = clockRanges; ; cp = cp->next) + if (!cp || modeInClockRange(cp, p)) + return cp; +} + + +/* + * xf86HandleBuiltinMode() - handles built-in modes + */ +static ModeStatus +xf86HandleBuiltinMode(ScrnInfoPtr scrp, + DisplayModePtr p, + DisplayModePtr modep, + ClockRangePtr clockRanges, + Bool allowDiv2) +{ + ClockRangePtr cp; + int extraFlags = 0; + int MulFactor = 1; + int DivFactor = 1; + int clockIndex; + + /* Reject previously rejected modes */ + if (p->status != MODE_OK) + return p->status; + + /* Reject previously considered modes */ + if (p->prev) + return MODE_NOMODE; + + if ((p->type & M_T_CLOCK_C) == M_T_CLOCK_C) { + /* Check clock is in range */ + cp = xf86FindClockRangeForMode(clockRanges, p); + if (cp == NULL){ + modep->type = p->type; + p->status = MODE_CLOCK_RANGE; + return MODE_CLOCK_RANGE; + } + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + if (!scrp->progClock) { + clockIndex = xf86GetNearestClock(scrp, p->Clock, allowDiv2, + cp->ClockDivFactor, + cp->ClockMulFactor, &extraFlags); + modep->Clock = (scrp->clock[clockIndex] * DivFactor) + / MulFactor; + modep->ClockIndex = clockIndex; + modep->SynthClock = scrp->clock[clockIndex]; + if (extraFlags & V_CLKDIV2) { + modep->Clock /= 2; + modep->SynthClock /= 2; + } + } else { + modep->Clock = p->Clock; + modep->ClockIndex = -1; + modep->SynthClock = (modep->Clock * MulFactor) + / DivFactor; + } + modep->PrivFlags = cp->PrivFlags; + } else { + if(!scrp->progClock) { + modep->Clock = p->Clock; + modep->ClockIndex = p->ClockIndex; + modep->SynthClock = p->SynthClock; + } else { + modep->Clock = p->Clock; + modep->ClockIndex = -1; + modep->SynthClock = p->SynthClock; + } + modep->PrivFlags = p->PrivFlags; + } + modep->type = p->type; + modep->HDisplay = p->HDisplay; + modep->HSyncStart = p->HSyncStart; + modep->HSyncEnd = p->HSyncEnd; + modep->HTotal = p->HTotal; + modep->HSkew = p->HSkew; + modep->VDisplay = p->VDisplay; + modep->VSyncStart = p->VSyncStart; + modep->VSyncEnd = p->VSyncEnd; + modep->VTotal = p->VTotal; + modep->VScan = p->VScan; + modep->Flags = p->Flags | extraFlags; + modep->CrtcHDisplay = p->CrtcHDisplay; + modep->CrtcHBlankStart = p->CrtcHBlankStart; + modep->CrtcHSyncStart = p->CrtcHSyncStart; + modep->CrtcHSyncEnd = p->CrtcHSyncEnd; + modep->CrtcHBlankEnd = p->CrtcHBlankEnd; + modep->CrtcHTotal = p->CrtcHTotal; + modep->CrtcHSkew = p->CrtcHSkew; + modep->CrtcVDisplay = p->CrtcVDisplay; + modep->CrtcVBlankStart = p->CrtcVBlankStart; + modep->CrtcVSyncStart = p->CrtcVSyncStart; + modep->CrtcVSyncEnd = p->CrtcVSyncEnd; + modep->CrtcVBlankEnd = p->CrtcVBlankEnd; + modep->CrtcVTotal = p->CrtcVTotal; + modep->CrtcHAdjusted = p->CrtcHAdjusted; + modep->CrtcVAdjusted = p->CrtcVAdjusted; + modep->HSync = p->HSync; + modep->VRefresh = p->VRefresh; + modep->Private = p->Private; + modep->PrivSize = p->PrivSize; + + p->prev = modep; + + return MODE_OK; +} + +/* + * xf86LookupMode + * + * This function returns a mode from the given list which matches the + * given name. When multiple modes with the same name are available, + * the method of picking the matching mode is determined by the + * strategy selected. + * + * This function takes the following parameters: + * scrp ScrnInfoPtr + * modep pointer to the returned mode, which must have the name + * field filled in. + * clockRanges a list of clock ranges. This is optional when all the + * modes are built-in modes. + * strategy how to decide which mode to use from multiple modes with + * the same name + * + * In addition, the following fields from the ScrnInfoRec are used: + * modePool the list of monitor modes compatible with the driver + * clocks a list of discrete clocks + * numClocks number of discrete clocks + * progClock clock is programmable + * + * If a mode was found, its values are filled in to the area pointed to + * by modep, If a mode was not found the return value indicates the + * reason. + */ + +ModeStatus +xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, + ClockRangePtr clockRanges, LookupModeFlags strategy) +{ + DisplayModePtr p, bestMode = NULL; + ClockRangePtr cp; + int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1; + double refresh, bestRefresh = 0.0; + Bool found = FALSE; + int extraFlags = 0; + int clockIndex = -1; + int MulFactor = 1; + int DivFactor = 1; + int ModePrivFlags = 0; + ModeStatus status = MODE_NOMODE; + Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0; + int n; + const int types[] = { + M_T_BUILTIN | M_T_PREFERRED, + M_T_BUILTIN, + M_T_USERDEF | M_T_PREFERRED, + M_T_USERDEF, + M_T_DRIVER | M_T_PREFERRED, + M_T_DRIVER, + 0 + }; + const int ntypes = sizeof(types) / sizeof(int); + + strategy &= ~(LOOKUP_CLKDIV2 | LOOKUP_OPTIONAL_TOLERANCES); + + /* Some sanity checking */ + if (scrp == NULL || scrp->modePool == NULL || + (!scrp->progClock && scrp->numClocks == 0)) { + ErrorF("xf86LookupMode: called with invalid scrnInfoRec\n"); + return MODE_ERROR; + } + if (modep == NULL || modep->name == NULL) { + ErrorF("xf86LookupMode: called with invalid modep\n"); + return MODE_ERROR; + } + for (cp = clockRanges; cp != NULL; cp = cp->next) { + /* DivFactor and MulFactor must be > 0 */ + cp->ClockDivFactor = max(1, cp->ClockDivFactor); + cp->ClockMulFactor = max(1, cp->ClockMulFactor); + } + + /* Scan the mode pool for matching names */ + for (n = 0; n < ntypes; n++) { + int type = types[n]; + for (p = scrp->modePool; p != NULL; p = p->next) { + + /* scan through the modes in the sort order above */ + if ((p->type & type) != type) + continue; + + if (strcmp(p->name, modep->name) == 0) { + + /* Skip over previously rejected modes */ + if (p->status != MODE_OK) { + if (!found) + status = p->status; + continue; + } + + /* Skip over previously considered modes */ + if (p->prev) + continue; + + if (p->type & M_T_BUILTIN) { + return xf86HandleBuiltinMode(scrp, p,modep, clockRanges, + allowDiv2); + } + + /* Check clock is in range */ + cp = xf86FindClockRangeForMode(clockRanges, p); + if (cp == NULL) { + /* + * XXX Could do more here to provide a more detailed + * reason for not finding a mode. + */ + p->status = MODE_CLOCK_RANGE; + if (!found) + status = MODE_CLOCK_RANGE; + continue; + } + + /* + * If programmable clock and strategy is not + * LOOKUP_BEST_REFRESH, the required mode has been found, + * otherwise record the refresh and continue looking. + */ + if (scrp->progClock) { + found = TRUE; + if (strategy != LOOKUP_BEST_REFRESH) { + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + break; + } + refresh = xf86ModeVRefresh(p); + if (p->Flags & V_INTERLACE) + refresh /= INTERLACE_REFRESH_WEIGHT; + if (refresh > bestRefresh) { + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + bestRefresh = refresh; + } + continue; + } + + /* + * Clock is in range, so if it is not a programmable clock, find + * a matching clock. + */ + + i = xf86GetNearestClock(scrp, p->Clock, allowDiv2, + cp->ClockDivFactor, cp->ClockMulFactor, &k); + /* + * If the clock is too far from the requested clock, this + * mode is no good. + */ + if (k & V_CLKDIV2) + gap = abs((p->Clock * 2) - + ((scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor)); + else + gap = abs(p->Clock - + ((scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor)); + if (gap > minimumGap) { + p->status = MODE_NOCLOCK; + if (!found) + status = MODE_NOCLOCK; + continue; + } + found = TRUE; + + if (strategy == LOOKUP_BEST_REFRESH) { + refresh = xf86ModeVRefresh(p); + if (p->Flags & V_INTERLACE) + refresh /= INTERLACE_REFRESH_WEIGHT; + if (refresh > bestRefresh) { + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + extraFlags = k; + clockIndex = i; + bestRefresh = refresh; + } + continue; + } + if (strategy == LOOKUP_CLOSEST_CLOCK) { + if (gap < minimumGap) { + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + extraFlags = k; + clockIndex = i; + minimumGap = gap; + } + continue; + } + /* + * If strategy is neither LOOKUP_BEST_REFRESH or + * LOOKUP_CLOSEST_CLOCK the required mode has been found. + */ + bestMode = p; + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + extraFlags = k; + clockIndex = i; + break; + } + } + if (found) break; + } + if (!found || bestMode == NULL) + return status; + + /* Fill in the mode parameters */ + if (scrp->progClock) { + modep->Clock = bestMode->Clock; + modep->ClockIndex = -1; + modep->SynthClock = (modep->Clock * MulFactor) / DivFactor; + } else { + modep->Clock = (scrp->clock[clockIndex] * DivFactor) / + MulFactor; + modep->ClockIndex = clockIndex; + modep->SynthClock = scrp->clock[clockIndex]; + if (extraFlags & V_CLKDIV2) { + modep->Clock /= 2; + modep->SynthClock /= 2; + } + } + modep->type = bestMode->type; + modep->PrivFlags = ModePrivFlags; + modep->HDisplay = bestMode->HDisplay; + modep->HSyncStart = bestMode->HSyncStart; + modep->HSyncEnd = bestMode->HSyncEnd; + modep->HTotal = bestMode->HTotal; + modep->HSkew = bestMode->HSkew; + modep->VDisplay = bestMode->VDisplay; + modep->VSyncStart = bestMode->VSyncStart; + modep->VSyncEnd = bestMode->VSyncEnd; + modep->VTotal = bestMode->VTotal; + modep->VScan = bestMode->VScan; + modep->Flags = bestMode->Flags | extraFlags; + modep->CrtcHDisplay = bestMode->CrtcHDisplay; + modep->CrtcHBlankStart = bestMode->CrtcHBlankStart; + modep->CrtcHSyncStart = bestMode->CrtcHSyncStart; + modep->CrtcHSyncEnd = bestMode->CrtcHSyncEnd; + modep->CrtcHBlankEnd = bestMode->CrtcHBlankEnd; + modep->CrtcHTotal = bestMode->CrtcHTotal; + modep->CrtcHSkew = bestMode->CrtcHSkew; + modep->CrtcVDisplay = bestMode->CrtcVDisplay; + modep->CrtcVBlankStart = bestMode->CrtcVBlankStart; + modep->CrtcVSyncStart = bestMode->CrtcVSyncStart; + modep->CrtcVSyncEnd = bestMode->CrtcVSyncEnd; + modep->CrtcVBlankEnd = bestMode->CrtcVBlankEnd; + modep->CrtcVTotal = bestMode->CrtcVTotal; + modep->CrtcHAdjusted = bestMode->CrtcHAdjusted; + modep->CrtcVAdjusted = bestMode->CrtcVAdjusted; + modep->HSync = bestMode->HSync; + modep->VRefresh = bestMode->VRefresh; + modep->Private = bestMode->Private; + modep->PrivSize = bestMode->PrivSize; + + bestMode->prev = modep; + + return MODE_OK; +} + +/* + * xf86CheckModeForMonitor + * + * This function takes a mode and monitor description, and determines + * if the mode is valid for the monitor. + */ +ModeStatus +xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor) +{ + int i; + + /* Sanity checks */ + if (mode == NULL || monitor == NULL) { + ErrorF("xf86CheckModeForMonitor: called with invalid parameters\n"); + return MODE_ERROR; + } + + DebugF("xf86CheckModeForMonitor(%p %s, %p %s)\n", + mode, mode->name, monitor, monitor->id); + + /* Some basic mode validity checks */ + if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart || + mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal) + return MODE_H_ILLEGAL; + + if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart || + mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal) + return MODE_V_ILLEGAL; + + if (monitor->nHsync > 0) { + /* Check hsync against the allowed ranges */ + float hsync = xf86ModeHSync(mode); + for (i = 0; i < monitor->nHsync; i++) + if ((hsync > monitor->hsync[i].lo * (1.0 - SYNC_TOLERANCE)) && + (hsync < monitor->hsync[i].hi * (1.0 + SYNC_TOLERANCE))) + break; + + /* Now see whether we ran out of sync ranges without finding a match */ + if (i == monitor->nHsync) + return MODE_HSYNC; + } + + if (monitor->nVrefresh > 0) { + /* Check vrefresh against the allowed ranges */ + float vrefrsh = xf86ModeVRefresh(mode); + for (i = 0; i < monitor->nVrefresh; i++) + if ((vrefrsh > monitor->vrefresh[i].lo * (1.0 - SYNC_TOLERANCE)) && + (vrefrsh < monitor->vrefresh[i].hi * (1.0 + SYNC_TOLERANCE))) + break; + + /* Now see whether we ran out of refresh ranges without finding a match */ + if (i == monitor->nVrefresh) + return MODE_VSYNC; + } + + /* Force interlaced modes to have an odd VTotal */ + if (mode->Flags & V_INTERLACE) + mode->CrtcVTotal = mode->VTotal |= 1; + + /* + * This code stops cvt -r modes, and only cvt -r modes, from hitting 15y+ + * old CRTs which might, when there is a lot of solar flare activity and + * when the celestial bodies are unfavourably aligned, implode trying to + * sync to it. It's called "Protecting the user from doing anything stupid". + * -- libv + */ + + if (xf86ModeIsReduced(mode)) { + if (!monitor->reducedblanking && !(mode->type & M_T_DRIVER)) + return MODE_NO_REDUCED; + } + + if ((monitor->maxPixClock) && (mode->Clock > monitor->maxPixClock)) + return MODE_CLOCK_HIGH; + + return MODE_OK; +} + +/* + * xf86CheckModeSize + * + * An internal routine to check if a mode fits in video memory. This tries to + * avoid overflows that would otherwise occur when video memory size is greater + * than 256MB. + */ +static Bool +xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y) +{ + int bpp = scrp->fbFormat.bitsPerPixel, + pad = scrp->fbFormat.scanlinePad; + int lineWidth, lastWidth; + + if (scrp->depth == 4) + pad *= 4; /* 4 planes */ + + /* Sanity check */ + if ((w < 0) || (x < 0) || (y <= 0)) + return FALSE; + + lineWidth = (((w * bpp) + pad - 1) / pad) * pad; + lastWidth = x * bpp; + + /* + * At this point, we need to compare + * + * (lineWidth * (y - 1)) + lastWidth + * + * against + * + * scrp->videoRam * (1024 * 8) + * + * These are bit quantities. To avoid overflows, do the comparison in + * terms of BITMAP_SCANLINE_PAD units. This assumes BITMAP_SCANLINE_PAD + * is a power of 2. We currently use 32, which limits us to a video + * memory size of 8GB. + */ + + lineWidth = (lineWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD; + lastWidth = (lastWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD; + + if ((lineWidth * (y - 1) + lastWidth) > + (scrp->videoRam * ((1024 * 8) / BITMAP_SCANLINE_PAD))) + return FALSE; + + return TRUE; +} + +/* + * xf86InitialCheckModeForDriver + * + * This function checks if a mode satisfies a driver's initial requirements: + * - mode size fits within the available pixel area (memory) + * - width lies within the range of supported line pitches + * - mode size fits within virtual size (if fixed) + * - horizontal timings are in range + * + * This function takes the following parameters: + * scrp ScrnInfoPtr + * mode mode to check + * maxPitch (optional) maximum line pitch + * virtualX (optional) virtual width requested + * virtualY (optional) virtual height requested + * + * In addition, the following fields from the ScrnInfoRec are used: + * monitor pointer to structure for monitor section + * fbFormat pixel format for the framebuffer + * videoRam video memory size (in kB) + * maxHValue maximum horizontal timing value + * maxVValue maximum vertical timing value + */ + +ModeStatus +xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, + ClockRangePtr clockRanges, + LookupModeFlags strategy, + int maxPitch, int virtualX, int virtualY) +{ + ClockRangePtr cp; + ModeStatus status; + Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0; + int i, needDiv2; + + /* Sanity checks */ + if (!scrp || !mode || !clockRanges) { + ErrorF("xf86InitialCheckModeForDriver: " + "called with invalid parameters\n"); + return MODE_ERROR; + } + + DebugF("xf86InitialCheckModeForDriver(%p, %p %s, %p, 0x%x, %d, %d, %d)\n", + scrp, mode, mode->name , clockRanges, strategy, maxPitch, virtualX, virtualY); + + /* Some basic mode validity checks */ + if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart || + mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal) + return MODE_H_ILLEGAL; + + if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart || + mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal) + return MODE_V_ILLEGAL; + + if (!xf86CheckModeSize(scrp, mode->HDisplay, mode->HDisplay, + mode->VDisplay)) + return MODE_MEM; + + if (maxPitch > 0 && mode->HDisplay > maxPitch) + return MODE_BAD_WIDTH; + + if (virtualX > 0 && mode->HDisplay > virtualX) + return MODE_VIRTUAL_X; + + if (virtualY > 0 && mode->VDisplay > virtualY) + return MODE_VIRTUAL_Y; + + if (scrp->maxHValue > 0 && mode->HTotal > scrp->maxHValue) + return MODE_BAD_HVALUE; + + if (scrp->maxVValue > 0 && mode->VTotal > scrp->maxVValue) + return MODE_BAD_VVALUE; + + /* + * The use of the DisplayModeRec's Crtc* and SynthClock elements below is + * provisional, in that they are later reused by the driver at mode-set + * time. Here, they are temporarily enlisted to contain the mode timings + * as seen by the CRT or panel (rather than the CRTC). The driver's + * ValidMode() is allowed to modify these so it can deal with such things + * as mode stretching and/or centering. The driver should >NOT< modify the + * user-supplied values as these are reported back when mode validation is + * said and done. + */ + /* + * NOTE: We (ab)use the mode->Crtc* values here to store timing + * information for the calculation of Hsync and Vrefresh. Before + * these values are calculated the driver is given the opportunity + * to either set these HSync and VRefresh itself or modify the timing + * values. + * The difference to the final calculation is small but imortand: + * here we pass the flag INTERLACE_HALVE_V regardless if the driver + * sets it or not. This way our calculation of VRefresh has the same + * effect as if we do if (flags & V_INTERLACE) refresh *= 2.0 + * This dual use of the mode->Crtc* values will certainly create + * confusion and is bad software design. However since it's part of + * the driver API it's hard to change. + */ + + if (scrp->ValidMode) { + + xf86SetModeCrtc(mode, INTERLACE_HALVE_V); + + cp = xf86FindClockRangeForMode(clockRanges, mode); + if (!cp) + return MODE_CLOCK_RANGE; + + if (cp->ClockMulFactor < 1) + cp->ClockMulFactor = 1; + if (cp->ClockDivFactor < 1) + cp->ClockDivFactor = 1; + + /* + * XXX The effect of clock dividers and multipliers on the monitor's + * pixel clock needs to be verified. + */ + if (scrp->progClock) { + mode->SynthClock = mode->Clock; + } else { + i = xf86GetNearestClock(scrp, mode->Clock, allowDiv2, + cp->ClockDivFactor, cp->ClockMulFactor, + &needDiv2); + mode->SynthClock = (scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor; + if (needDiv2 & V_CLKDIV2) + mode->SynthClock /= 2; + } + + status = (*scrp->ValidMode)(scrp->scrnIndex, mode, FALSE, + MODECHECK_INITIAL); + if (status != MODE_OK) + return status; + + if (mode->HSync <= 0.0) + mode->HSync = (float)mode->SynthClock / (float)mode->CrtcHTotal; + if (mode->VRefresh <= 0.0) + mode->VRefresh = (mode->SynthClock * 1000.0) + / (mode->CrtcHTotal * mode->CrtcVTotal); + } + + mode->HSync = xf86ModeHSync(mode); + mode->VRefresh = xf86ModeVRefresh(mode); + + /* Assume it is OK */ + return MODE_OK; +} + +/* + * xf86CheckModeForDriver + * + * This function is for checking modes while the server is running (for + * use mainly by the VidMode extension). + * + * This function checks if a mode satisfies a driver's requirements: + * - width lies within the line pitch + * - mode size fits within virtual size + * - horizontal/vertical timings are in range + * + * This function takes the following parameters: + * scrp ScrnInfoPtr + * mode mode to check + * flags not (currently) used + * + * In addition, the following fields from the ScrnInfoRec are used: + * maxHValue maximum horizontal timing value + * maxVValue maximum vertical timing value + * virtualX virtual width + * virtualY virtual height + * clockRanges allowable clock ranges + */ + +ModeStatus +xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags) +{ + ClockRangePtr cp; + int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1; + int extraFlags = 0; + int clockIndex = -1; + int MulFactor = 1; + int DivFactor = 1; + int ModePrivFlags = 0; + ModeStatus status = MODE_NOMODE; + + /* Some sanity checking */ + if (scrp == NULL || (!scrp->progClock && scrp->numClocks == 0)) { + ErrorF("xf86CheckModeForDriver: called with invalid scrnInfoRec\n"); + return MODE_ERROR; + } + if (mode == NULL) { + ErrorF("xf86CheckModeForDriver: called with invalid modep\n"); + return MODE_ERROR; + } + + /* Check the mode size */ + if (mode->HDisplay > scrp->virtualX) + return MODE_VIRTUAL_X; + + if (mode->VDisplay > scrp->virtualY) + return MODE_VIRTUAL_Y; + + if (scrp->maxHValue > 0 && mode->HTotal > scrp->maxHValue) + return MODE_BAD_HVALUE; + + if (scrp->maxVValue > 0 && mode->VTotal > scrp->maxVValue) + return MODE_BAD_VVALUE; + + for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { + /* DivFactor and MulFactor must be > 0 */ + cp->ClockDivFactor = max(1, cp->ClockDivFactor); + cp->ClockMulFactor = max(1, cp->ClockMulFactor); + } + + if (scrp->progClock) { + /* Check clock is in range */ + for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { + if (modeInClockRange(cp, mode)) + break; + } + if (cp == NULL) { + return MODE_CLOCK_RANGE; + } + /* + * If programmable clock the required mode has been found + */ + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + } else { + status = MODE_CLOCK_RANGE; + /* Check clock is in range */ + for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { + if (modeInClockRange(cp, mode)) { + /* + * Clock is in range, so if it is not a programmable clock, + * find a matching clock. + */ + + i = xf86GetNearestClock(scrp, mode->Clock, 0, + cp->ClockDivFactor, cp->ClockMulFactor, &k); + /* + * If the clock is too far from the requested clock, this + * mode is no good. + */ + if (k & V_CLKDIV2) + gap = abs((mode->Clock * 2) - + ((scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor)); + else + gap = abs(mode->Clock - + ((scrp->clock[i] * cp->ClockDivFactor) / + cp->ClockMulFactor)); + if (gap > minimumGap) { + status = MODE_NOCLOCK; + continue; + } + + DivFactor = cp->ClockDivFactor; + MulFactor = cp->ClockMulFactor; + ModePrivFlags = cp->PrivFlags; + extraFlags = k; + clockIndex = i; + break; + } + } + if (cp == NULL) + return status; + } + + /* Fill in the mode parameters */ + if (scrp->progClock) { + mode->ClockIndex = -1; + mode->SynthClock = (mode->Clock * MulFactor) / DivFactor; + } else { + mode->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor; + mode->ClockIndex = clockIndex; + mode->SynthClock = scrp->clock[clockIndex]; + if (extraFlags & V_CLKDIV2) { + mode->Clock /= 2; + mode->SynthClock /= 2; + } + } + mode->PrivFlags = ModePrivFlags; + + return MODE_OK; +} + +static int +inferVirtualSize(ScrnInfoPtr scrp, DisplayModePtr modes, int *vx, int *vy) +{ + float aspect = 0.0; + MonPtr mon = scrp->monitor; + xf86MonPtr DDC; + int x = 0, y = 0; + DisplayModePtr mode; + + if (!mon) return 0; + DDC = mon->DDC; + + if (DDC && DDC->ver.revision >= 4) { + /* For 1.4, we might actually get native pixel format. How novel. */ + if (PREFERRED_TIMING_MODE(DDC->features.msc)) { + for (mode = modes; mode; mode = mode->next) { + if (mode->type & (M_T_DRIVER | M_T_PREFERRED)) { + x = mode->HDisplay; + y = mode->VDisplay; + goto found; + } + } + } + /* + * Even if we don't, we might get aspect ratio from extra CVT info + * or from the monitor size fields. TODO. + */ + } + + /* + * Technically this triggers if either is zero. That wasn't legal + * before EDID 1.4, but right now we'll get that wrong. TODO. + */ + if (!aspect) { + if (!mon->widthmm || !mon->heightmm) + aspect = 4.0/3.0; + else + aspect = (float)mon->widthmm / (float)mon->heightmm; + } + + /* find the largest M_T_DRIVER mode with that aspect ratio */ + for (mode = modes; mode; mode = mode->next) { + float mode_aspect, metaspect; + if (!(mode->type & (M_T_DRIVER|M_T_USERDEF))) + continue; + mode_aspect = (float)mode->HDisplay / (float)mode->VDisplay; + metaspect = aspect / mode_aspect; + /* 5% slop or so, since we only get size in centimeters */ + if (fabs(1.0 - metaspect) < 0.05) { + if ((mode->HDisplay > x) && (mode->VDisplay > y)) { + x = mode->HDisplay; + y = mode->VDisplay; + } + } + } + + if (!x || !y) { + xf86DrvMsg(scrp->scrnIndex, X_WARNING, + "Unable to estimate virtual size\n"); + return 0; + } + +found: + *vx = x; + *vy = y; + + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "Estimated virtual size for aspect ratio %.4f is %dx%d\n", + aspect, *vx, *vy); + + return 1; +} + +/* Least common multiple */ +static unsigned int +LCM(unsigned int x, unsigned int y) +{ + unsigned int m = x, n = y, o; + + while ((o = m % n)) + { + m = n; + n = o; + } + + return (x / n) * y; +} + +/* + * Given various screen attributes, determine the minimum scanline width such + * that each scanline is server and DDX padded and any pixels with imbedded + * bank boundaries are off-screen. This function returns -1 if such a width + * cannot exist. + */ +static int +scanLineWidth( + unsigned int xsize, /* pixels */ + unsigned int ysize, /* pixels */ + unsigned int width, /* pixels */ + unsigned long BankSize, /* char's */ + PixmapFormatRec *pBankFormat, + unsigned int nWidthUnit /* bits */ +) +{ + unsigned long nBitsPerBank, nBitsPerScanline, nBitsPerScanlinePadUnit; + unsigned long minBitsPerScanline, maxBitsPerScanline; + + /* Sanity checks */ + + if (!nWidthUnit || !pBankFormat) + return -1; + + nBitsPerBank = BankSize * 8; + if (nBitsPerBank % pBankFormat->scanlinePad) + return -1; + + if (xsize > width) + width = xsize; + nBitsPerScanlinePadUnit = LCM(pBankFormat->scanlinePad, nWidthUnit); + nBitsPerScanline = + (((width * pBankFormat->bitsPerPixel) + nBitsPerScanlinePadUnit - 1) / + nBitsPerScanlinePadUnit) * nBitsPerScanlinePadUnit; + width = nBitsPerScanline / pBankFormat->bitsPerPixel; + + if (!xsize || !(nBitsPerBank % pBankFormat->bitsPerPixel)) + return (int)width; + + /* + * Scanlines will be server-pad aligned at this point. They will also be + * a multiple of nWidthUnit bits long. Ensure that pixels with imbedded + * bank boundaries are off-screen. + * + * It seems reasonable to limit total frame buffer size to 1/16 of the + * theoretical maximum address space size. On a machine with 32-bit + * addresses (to 8-bit quantities) this turns out to be 256MB. Not only + * does this provide a simple limiting condition for the loops below, but + * it also prevents unsigned long wraparounds. + */ + if (!ysize) + return -1; + + minBitsPerScanline = xsize * pBankFormat->bitsPerPixel; + if (minBitsPerScanline > nBitsPerBank) + return -1; + + if (ysize == 1) + return (int)width; + + maxBitsPerScanline = + (((unsigned long)(-1) >> 1) - minBitsPerScanline) / (ysize - 1); + while (nBitsPerScanline <= maxBitsPerScanline) + { + unsigned long BankBase, BankUnit; + + BankUnit = ((nBitsPerBank + nBitsPerScanline - 1) / nBitsPerBank) * + nBitsPerBank; + if (!(BankUnit % nBitsPerScanline)) + return (int)width; + + for (BankBase = BankUnit; ; BankBase += nBitsPerBank) + { + unsigned long x, y; + + y = BankBase / nBitsPerScanline; + if (y >= ysize) + return (int)width; + + x = BankBase % nBitsPerScanline; + if (!(x % pBankFormat->bitsPerPixel)) + continue; + + if (x < minBitsPerScanline) + { + /* + * Skip ahead certain widths by dividing the excess scanline + * amongst the y's. + */ + y *= nBitsPerScanlinePadUnit; + nBitsPerScanline += + ((x + y - 1) / y) * nBitsPerScanlinePadUnit; + width = nBitsPerScanline / pBankFormat->bitsPerPixel; + break; + } + + if (BankBase != BankUnit) + continue; + + if (!(nBitsPerScanline % x)) + return (int)width; + + BankBase = ((nBitsPerScanline - minBitsPerScanline) / + (nBitsPerScanline - x)) * BankUnit; + } + } + + return -1; +} + +/* + * xf86ValidateModes + * + * This function takes a set of mode names, modes and limiting conditions, + * and selects a set of modes and parameters based on those conditions. + * + * This function takes the following parameters: + * scrp ScrnInfoPtr + * availModes the list of modes available for the monitor + * modeNames (optional) list of mode names that the screen is requesting + * clockRanges a list of clock ranges + * linePitches (optional) a list of line pitches + * minPitch (optional) minimum line pitch (in pixels) + * maxPitch (optional) maximum line pitch (in pixels) + * pitchInc (mandatory) pitch increment (in bits) + * minHeight (optional) minimum virtual height (in pixels) + * maxHeight (optional) maximum virtual height (in pixels) + * virtualX (optional) virtual width requested (in pixels) + * virtualY (optional) virtual height requested (in pixels) + * apertureSize size of video aperture (in bytes) + * strategy how to decide which mode to use from multiple modes with + * the same name + * + * In addition, the following fields from the ScrnInfoRec are used: + * clocks a list of discrete clocks + * numClocks number of discrete clocks + * progClock clock is programmable + * monitor pointer to structure for monitor section + * fbFormat format of the framebuffer + * videoRam video memory size + * maxHValue maximum horizontal timing value + * maxVValue maximum vertical timing value + * xInc horizontal timing increment (defaults to 8 pixels) + * + * The function fills in the following ScrnInfoRec fields: + * modePool A subset of the modes available to the monitor which + * are compatible with the driver. + * modes one mode entry for each of the requested modes, with the + * status field filled in to indicate if the mode has been + * accepted or not. + * virtualX the resulting virtual width + * virtualY the resulting virtual height + * displayWidth the resulting line pitch + * + * The function's return value is the number of matching modes found, or -1 + * if an unrecoverable error was encountered. + */ + +int +xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, + char **modeNames, ClockRangePtr clockRanges, + int *linePitches, int minPitch, int maxPitch, int pitchInc, + int minHeight, int maxHeight, int virtualX, int virtualY, + int apertureSize, LookupModeFlags strategy) +{ + DisplayModePtr p, q, r, new, last, *endp; + int i, numModes = 0; + ModeStatus status; + int linePitch = -1, virtX = 0, virtY = 0; + int newLinePitch, newVirtX, newVirtY; + int modeSize; /* in pixels */ + Bool validateAllDefaultModes = FALSE; + Bool userModes = FALSE; + int saveType; + PixmapFormatRec *BankFormat; + ClockRangePtr cp; + ClockRangePtr storeClockRanges; + int numTimings = 0; + range hsync[MAX_HSYNC]; + range vrefresh[MAX_VREFRESH]; + Bool inferred_virtual = FALSE; + + DebugF("xf86ValidateModes(%p, %p, %p, %p,\n\t\t %p, %d, %d, %d, %d, %d, %d, %d, %d, 0x%x)\n", + scrp, availModes, modeNames, clockRanges, + linePitches, minPitch, maxPitch, pitchInc, + minHeight, maxHeight, virtualX, virtualY, + apertureSize, strategy + ); + + /* Some sanity checking */ + if (scrp == NULL || scrp->name == NULL || !scrp->monitor || + (!scrp->progClock && scrp->numClocks == 0)) { + ErrorF("xf86ValidateModes: called with invalid scrnInfoRec\n"); + return -1; + } + if (linePitches != NULL && linePitches[0] <= 0) { + ErrorF("xf86ValidateModes: called with invalid linePitches\n"); + return -1; + } + if (pitchInc <= 0) { + ErrorF("xf86ValidateModes: called with invalid pitchInc\n"); + return -1; + } + if ((virtualX > 0) != (virtualY > 0)) { + ErrorF("xf86ValidateModes: called with invalid virtual resolution\n"); + return -1; + } + + /* + * If requested by the driver, allow missing hsync and/or vrefresh ranges + * in the monitor section. + */ + if (strategy & LOOKUP_OPTIONAL_TOLERANCES) { + strategy &= ~LOOKUP_OPTIONAL_TOLERANCES; + } else { + const char *type = ""; + Bool specified = FALSE; + + if (scrp->monitor->nHsync <= 0) { + if (numTimings > 0) { + scrp->monitor->nHsync = numTimings; + for (i = 0; i < numTimings; i++) { + scrp->monitor->hsync[i].lo = hsync[i].lo; + scrp->monitor->hsync[i].hi = hsync[i].hi; + } + } else { + scrp->monitor->hsync[0].lo = 31.5; + scrp->monitor->hsync[0].hi = 48.0; + scrp->monitor->nHsync = 1; + } + type = "default "; + } else { + specified = TRUE; + } + for (i = 0; i < scrp->monitor->nHsync; i++) { + if (scrp->monitor->hsync[i].lo == scrp->monitor->hsync[i].hi) + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %shsync value of %.2f kHz\n", + scrp->monitor->id, type, + scrp->monitor->hsync[i].lo); + else + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %shsync range of %.2f-%.2f kHz\n", + scrp->monitor->id, type, + scrp->monitor->hsync[i].lo, + scrp->monitor->hsync[i].hi); + } + + type = ""; + if (scrp->monitor->nVrefresh <= 0) { + if (numTimings > 0) { + scrp->monitor->nVrefresh = numTimings; + for (i = 0; i < numTimings; i++) { + scrp->monitor->vrefresh[i].lo = vrefresh[i].lo; + scrp->monitor->vrefresh[i].hi = vrefresh[i].hi; + } + } else { + scrp->monitor->vrefresh[0].lo = 50; + scrp->monitor->vrefresh[0].hi = 70; + scrp->monitor->nVrefresh = 1; + } + type = "default "; + } else { + specified = TRUE; + } + for (i = 0; i < scrp->monitor->nVrefresh; i++) { + if (scrp->monitor->vrefresh[i].lo == scrp->monitor->vrefresh[i].hi) + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %svrefresh value of %.2f Hz\n", + scrp->monitor->id, type, + scrp->monitor->vrefresh[i].lo); + else + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %svrefresh range of %.2f-%.2f Hz\n", + scrp->monitor->id, type, + scrp->monitor->vrefresh[i].lo, + scrp->monitor->vrefresh[i].hi); + } + + type = ""; + if (!scrp->monitor->maxPixClock && !specified) { + type = "default "; + scrp->monitor->maxPixClock = 65000.0; + } + if (scrp->monitor->maxPixClock) { + xf86DrvMsg(scrp->scrnIndex, X_INFO, + "%s: Using %smaximum pixel clock of %.2f MHz\n", + scrp->monitor->id, type, + (float)scrp->monitor->maxPixClock / 1000.0); + } + } + + /* + * Store the clockRanges for later use by the VidMode extension. + */ + storeClockRanges = scrp->clockRanges; + while (storeClockRanges != NULL) { + storeClockRanges = storeClockRanges->next; + } + for (cp = clockRanges; cp != NULL; cp = cp->next, + storeClockRanges = storeClockRanges->next) { + storeClockRanges = xnfalloc(sizeof(ClockRange)); + if (scrp->clockRanges == NULL) + scrp->clockRanges = storeClockRanges; + memcpy(storeClockRanges, cp, sizeof(ClockRange)); + } + + /* Determine which pixmap format to pass to scanLineWidth() */ + if (scrp->depth > 4) + BankFormat = &scrp->fbFormat; + else + BankFormat = xf86GetPixFormat(scrp, 1); /* >not< scrp->depth! */ + + if (scrp->xInc <= 0) + scrp->xInc = 8; /* Suitable for VGA and others */ + +#define _VIRTUALX(x) ((((x) + scrp->xInc - 1) / scrp->xInc) * scrp->xInc) + + /* + * Determine maxPitch if it wasn't given explicitly. Note linePitches + * always takes precedence if is non-NULL. In that case the minPitch and + * maxPitch values passed are ignored. + */ + if (linePitches) { + minPitch = maxPitch = linePitches[0]; + for (i = 1; linePitches[i] > 0; i++) { + if (linePitches[i] > maxPitch) + maxPitch = linePitches[i]; + if (linePitches[i] < minPitch) + minPitch = linePitches[i]; + } + } + + /* Initial check of virtual size against other constraints */ + scrp->virtualFrom = X_PROBED; + /* + * Initialise virtX and virtY if the values are fixed. + */ + if (virtualY > 0) { + if (maxHeight > 0 && virtualY > maxHeight) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual height (%d) is too large for the hardware " + "(max %d)\n", virtualY, maxHeight); + return -1; + } + + if (minHeight > 0 && virtualY < minHeight) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual height (%d) is too small for the hardware " + "(min %d)\n", virtualY, minHeight); + return -1; + } + + virtualX = _VIRTUALX(virtualX); + if (linePitches != NULL) { + for (i = 0; linePitches[i] != 0; i++) { + if ((linePitches[i] >= virtualX) && + (linePitches[i] == + scanLineWidth(virtualX, virtualY, linePitches[i], + apertureSize, BankFormat, pitchInc))) { + linePitch = linePitches[i]; + break; + } + } + } else { + linePitch = scanLineWidth(virtualX, virtualY, minPitch, + apertureSize, BankFormat, pitchInc); + } + + if ((linePitch < minPitch) || (linePitch > maxPitch)) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual width (%d) is too large for the hardware " + "(max %d)\n", virtualX, maxPitch); + return -1; + } + + if (!xf86CheckModeSize(scrp, linePitch, virtualX, virtualY)) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual size (%dx%d) (pitch %d) exceeds video memory\n", + virtualX, virtualY, linePitch); + return -1; + } + + virtX = virtualX; + virtY = virtualY; + scrp->virtualFrom = X_CONFIG; + } else if (!modeNames || !*modeNames) { + /* No virtual size given in the config, try to infer */ + /* XXX this doesn't take m{in,ax}Pitch into account; oh well */ + inferred_virtual = inferVirtualSize(scrp, availModes, &virtX, &virtY); + if (inferred_virtual) + linePitch = scanLineWidth(virtX, virtY, minPitch, apertureSize, + BankFormat, pitchInc); + } + + /* Print clock ranges and scaled clocks */ + xf86ShowClockRanges(scrp, clockRanges); + + /* + * If scrp->modePool hasn't been setup yet, set it up now. This allows the + * modes that the driver definitely can't use to be weeded out early. Note + * that a modePool mode's prev field is used to hold a pointer to the + * member of the scrp->modes list for which a match was considered. + */ + if (scrp->modePool == NULL) { + q = NULL; + for (p = availModes; p != NULL; p = p->next) { + status = xf86InitialCheckModeForDriver(scrp, p, clockRanges, + strategy, maxPitch, + virtX, virtY); + + if (status == MODE_OK) { + status = xf86CheckModeForMonitor(p, scrp->monitor); + } + + if (status == MODE_OK) { + new = xnfalloc(sizeof(DisplayModeRec)); + *new = *p; + new->next = NULL; + if (!q) { + scrp->modePool = new; + } else { + q->next = new; + } + new->prev = NULL; + q = new; + q->name = xnfstrdup(p->name); + q->status = MODE_OK; + } else { + printModeRejectMessage(scrp->scrnIndex, p, status); + } + } + + if (scrp->modePool == NULL) { + xf86DrvMsg(scrp->scrnIndex, X_WARNING, "Mode pool is empty\n"); + return 0; + } + } else { + for (p = scrp->modePool; p != NULL; p = p->next) { + p->prev = NULL; + p->status = MODE_OK; + } + } + + /* + * Allocate one entry in scrp->modes for each named mode. + */ + while (scrp->modes) + xf86DeleteMode(&scrp->modes, scrp->modes); + endp = &scrp->modes; + last = NULL; + if (modeNames != NULL) { + for (i = 0; modeNames[i] != NULL; i++) { + userModes = TRUE; + new = xnfcalloc(1, sizeof(DisplayModeRec)); + new->prev = last; + new->type = M_T_USERDEF; + new->name = xnfstrdup(modeNames[i]); + if (new->prev) + new->prev->next = new; + *endp = last = new; + endp = &new->next; + } + } + + /* Lookup each mode */ +#ifdef RANDR + if (!xf86Info.disableRandR +#ifdef PANORAMIX + && noPanoramiXExtension +#endif + ) + validateAllDefaultModes = TRUE; +#endif + + for (p = scrp->modes; ; p = p->next) { + Bool repeat; + + /* + * If the supplied mode names don't produce a valid mode, scan through + * unconsidered modePool members until one survives validation. This + * is done in decreasing order by mode pixel area. + */ + + if (p == NULL) { + if ((numModes > 0) && !validateAllDefaultModes) + break; + + validateAllDefaultModes = TRUE; + r = NULL; + modeSize = 0; + for (q = scrp->modePool; q != NULL; q = q->next) { + if ((q->prev == NULL) && (q->status == MODE_OK)) { + /* + * Deal with the case where this mode wasn't considered + * because of a builtin mode of the same name. + */ + for (p = scrp->modes; p != NULL; p = p->next) { + if ((p->status != MODE_OK) && + !strcmp(p->name, q->name)) + break; + } + + if (p != NULL) + q->prev = p; + else { + /* + * A quick check to not allow default modes with + * horizontal timing parameters that CRTs may have + * problems with. + */ + if (!scrp->monitor->reducedblanking && + (q->type & M_T_DEFAULT) && + ((double)q->HTotal / (double)q->HDisplay) < 1.15) + continue; + + if (modeSize < (q->HDisplay * q->VDisplay)) { + r = q; + modeSize = q->HDisplay * q->VDisplay; + } + } + } + } + + if (r == NULL) + break; + + p = xnfcalloc(1, sizeof(DisplayModeRec)); + p->prev = last; + p->name = xnfstrdup(r->name); + if (!userModes) + p->type = M_T_USERDEF; + if (p->prev) + p->prev->next = p; + *endp = last = p; + endp = &p->next; + } + + repeat = FALSE; + lookupNext: + if (repeat && ((status = p->status) != MODE_OK)) + printModeRejectMessage(scrp->scrnIndex, p, status); + saveType = p->type; + status = xf86LookupMode(scrp, p, clockRanges, strategy); + if (repeat && status == MODE_NOMODE) + continue; + if (status != MODE_OK) + printModeRejectMessage(scrp->scrnIndex, p, status); + if (status == MODE_ERROR) { + ErrorF("xf86ValidateModes: " + "unexpected result from xf86LookupMode()\n"); + return -1; + } + if (status != MODE_OK) { + if (p->status == MODE_OK) + p->status = status; + continue; + } + p->type |= saveType; + repeat = TRUE; + + newLinePitch = linePitch; + newVirtX = virtX; + newVirtY = virtY; + + /* + * Don't let non-user defined modes increase the virtual size + */ + if (!(p->type & M_T_USERDEF) && (numModes > 0)) { + if (p->HDisplay > virtX) { + p->status = MODE_VIRTUAL_X; + goto lookupNext; + } + if (p->VDisplay > virtY) { + p->status = MODE_VIRTUAL_Y; + goto lookupNext; + } + } + /* + * Adjust virtual width and height if the mode is too large for the + * current values and if they are not fixed. + */ + if (virtualX <= 0 && p->HDisplay > newVirtX) + newVirtX = _VIRTUALX(p->HDisplay); + if (virtualY <= 0 && p->VDisplay > newVirtY) { + if (maxHeight > 0 && p->VDisplay > maxHeight) { + p->status = MODE_VIRTUAL_Y; /* ? */ + goto lookupNext; + } + newVirtY = p->VDisplay; + } + + /* + * If virtual resolution is to be increased, revalidate it. + */ + if ((virtX != newVirtX) || (virtY != newVirtY)) { + if (linePitches != NULL) { + newLinePitch = -1; + for (i = 0; linePitches[i] != 0; i++) { + if ((linePitches[i] >= newVirtX) && + (linePitches[i] >= linePitch) && + (linePitches[i] == + scanLineWidth(newVirtX, newVirtY, linePitches[i], + apertureSize, BankFormat, pitchInc))) { + newLinePitch = linePitches[i]; + break; + } + } + } else { + if (linePitch < minPitch) + linePitch = minPitch; + newLinePitch = scanLineWidth(newVirtX, newVirtY, linePitch, + apertureSize, BankFormat, + pitchInc); + } + if ((newLinePitch < minPitch) || (newLinePitch > maxPitch)) { + p->status = MODE_BAD_WIDTH; + goto lookupNext; + } + + /* + * Check that the pixel area required by the new virtual height + * and line pitch isn't too large. + */ + if (!xf86CheckModeSize(scrp, newLinePitch, newVirtX, newVirtY)) { + p->status = MODE_MEM_VIRT; + goto lookupNext; + } + } + + if (scrp->ValidMode) { + /* + * Give the driver a final say, passing it the proposed virtual + * geometry. + */ + scrp->virtualX = newVirtX; + scrp->virtualY = newVirtY; + scrp->displayWidth = newLinePitch; + p->status = (scrp->ValidMode)(scrp->scrnIndex, p, FALSE, + MODECHECK_FINAL); + + if (p->status != MODE_OK) { + goto lookupNext; + } + } + + /* Mode has passed all the tests */ + virtX = newVirtX; + virtY = newVirtY; + linePitch = newLinePitch; + p->status = MODE_OK; + numModes++; + } + + /* + * If we estimated the virtual size above, we may have filtered away all + * the modes that maximally match that size; scan again to find out and + * fix up if so. + */ + if (inferred_virtual) { + int vx = 0, vy = 0; + for (p = scrp->modes; p; p = p->next) { + if (p->HDisplay > vx && p->VDisplay > vy) { + vx = p->HDisplay; + vy = p->VDisplay; + } + } + if (vx < virtX || vy < virtY) { + const int types[] = { + M_T_BUILTIN | M_T_PREFERRED, + M_T_BUILTIN, + M_T_DRIVER | M_T_PREFERRED, + M_T_DRIVER, + 0 + }; + const int ntypes = sizeof(types) / sizeof(int); + int n; + + /* + * We did not find the estimated virtual size. So now we want to + * find the largest mode available, but we want to search in the + * modes in the order of "types" listed above. + */ + for (n = 0; n < ntypes; n++) { + int type = types[n]; + + vx = 0; vy = 0; + for (p = scrp->modes; p; p = p->next) { + /* scan through the modes in the sort order above */ + if ((p->type & type) != type) + continue; + if (p->HDisplay > vx && p->VDisplay > vy) { + vx = p->HDisplay; + vy = p->VDisplay; + } + } + if (vx && vy) + /* Found one */ + break; + } + xf86DrvMsg(scrp->scrnIndex, X_WARNING, + "Shrinking virtual size estimate from %dx%d to %dx%d\n", + virtX, virtY, vx, vy); + virtX = _VIRTUALX(vx); + virtY = vy; + for (p = scrp->modes; p; p = p->next) { + if (numModes > 0) { + if (p->HDisplay > virtX) + p->status = MODE_VIRTUAL_X; + if (p->VDisplay > virtY) + p->status = MODE_VIRTUAL_Y; + if (p->status != MODE_OK) { + numModes--; + printModeRejectMessage(scrp->scrnIndex, p, p->status); + } + } + } + if (linePitches != NULL) { + for (i = 0; linePitches[i] != 0; i++) { + if ((linePitches[i] >= virtX) && + (linePitches[i] == + scanLineWidth(virtX, virtY, linePitches[i], + apertureSize, BankFormat, pitchInc))) { + linePitch = linePitches[i]; + break; + } + } + } else { + linePitch = scanLineWidth(virtX, virtY, minPitch, + apertureSize, BankFormat, pitchInc); + } + } + } + + /* Update the ScrnInfoRec parameters */ + + scrp->virtualX = virtX; + scrp->virtualY = virtY; + scrp->displayWidth = linePitch; + + if (numModes <= 0) + return 0; + + /* Make the mode list into a circular list by joining up the ends */ + p = scrp->modes; + while (p->next != NULL) + p = p->next; + /* p is now the last mode on the list */ + p->next = scrp->modes; + scrp->modes->prev = p; + + if (minHeight > 0 && virtY < minHeight) { + xf86DrvMsg(scrp->scrnIndex, X_ERROR, + "Virtual height (%d) is too small for the hardware " + "(min %d)\n", virtY, minHeight); + return -1; + } + + return numModes; +} + +/* + * xf86DeleteMode + * + * This function removes a mode from a list of modes. + * + * There are different types of mode lists: + * + * - singly linked linear lists, ending in NULL + * - doubly linked linear lists, starting and ending in NULL + * - doubly linked circular lists + * + */ + +void +xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode) +{ + /* Catch the easy/insane cases */ + if (modeList == NULL || *modeList == NULL || mode == NULL) + return; + + /* If the mode is at the start of the list, move the start of the list */ + if (*modeList == mode) + *modeList = mode->next; + + /* If mode is the only one on the list, set the list to NULL */ + if ((mode == mode->prev) && (mode == mode->next)) { + *modeList = NULL; + } else { + if ((mode->prev != NULL) && (mode->prev->next == mode)) + mode->prev->next = mode->next; + if ((mode->next != NULL) && (mode->next->prev == mode)) + mode->next->prev = mode->prev; + } + + free(mode->name); + free(mode); +} + +/* + * xf86PruneDriverModes + * + * Remove modes from the driver's mode list which have been marked as + * invalid. + */ + +void +xf86PruneDriverModes(ScrnInfoPtr scrp) +{ + DisplayModePtr first, p, n; + + p = scrp->modes; + if (p == NULL) + return; + + do { + if (!(first = scrp->modes)) + return; + n = p->next; + if (p->status != MODE_OK) { + xf86DeleteMode(&(scrp->modes), p); + } + p = n; + } while (p != NULL && p != first); + + /* modePool is no longer needed, turf it */ + while (scrp->modePool) { + /* + * A modePool mode's prev field is used to hold a pointer to the + * member of the scrp->modes list for which a match was considered. + * Clear that pointer first, otherwise xf86DeleteMode might get + * confused + */ + scrp->modePool->prev = NULL; + xf86DeleteMode(&scrp->modePool, scrp->modePool); + } +} + + +/* + * xf86SetCrtcForModes + * + * Goes through the screen's mode list, and initialises the Crtc + * parameters for each mode. The initialisation includes adjustments + * for interlaced and double scan modes. + */ +void +xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags) +{ + DisplayModePtr p; + + /* + * Store adjustFlags for use with the VidMode extension. There is an + * implicit assumption here that SetCrtcForModes is called once. + */ + scrp->adjustFlags = adjustFlags; + + p = scrp->modes; + if (p == NULL) + return; + + do { + xf86SetModeCrtc(p, adjustFlags); + DebugF("%sMode %s: %d (%d) %d %d (%d) %d %d (%d) %d %d (%d) %d\n", + (p->type & M_T_DEFAULT) ? "Default " : "", + p->name, p->CrtcHDisplay, p->CrtcHBlankStart, + p->CrtcHSyncStart, p->CrtcHSyncEnd, p->CrtcHBlankEnd, + p->CrtcHTotal, p->CrtcVDisplay, p->CrtcVBlankStart, + p->CrtcVSyncStart, p->CrtcVSyncEnd, p->CrtcVBlankEnd, + p->CrtcVTotal); + p = p->next; + } while (p != NULL && p != scrp->modes); +} + +void +xf86PrintModes(ScrnInfoPtr scrp) +{ + DisplayModePtr p; + float hsync, refresh = 0; + const char *desc, *desc2, *prefix, *uprefix; + + if (scrp == NULL) + return; + + xf86DrvMsg(scrp->scrnIndex, scrp->virtualFrom, "Virtual size is %dx%d " + "(pitch %d)\n", scrp->virtualX, scrp->virtualY, + scrp->displayWidth); + + p = scrp->modes; + if (p == NULL) + return; + + do { + desc = desc2 = ""; + hsync = xf86ModeHSync(p); + refresh = xf86ModeVRefresh(p); + if (p->Flags & V_INTERLACE) { + desc = " (I)"; + } + if (p->Flags & V_DBLSCAN) { + desc = " (D)"; + } + if (p->VScan > 1) { + desc2 = " (VScan)"; + } + if (p->type & M_T_BUILTIN) + prefix = "Built-in mode"; + else if (p->type & M_T_DEFAULT) + prefix = "Default mode"; + else if (p->type & M_T_DRIVER) + prefix = "Driver mode"; + else + prefix = "Mode"; + if (p->type & M_T_USERDEF) + uprefix = "*"; + else + uprefix = " "; + if (hsync == 0 || refresh == 0) { + if (p->name) + xf86DrvMsg(scrp->scrnIndex, X_CONFIG, + "%s%s \"%s\"\n", uprefix, prefix, p->name); + else + xf86DrvMsg(scrp->scrnIndex, X_PROBED, + "%s%s %dx%d (unnamed)\n", + uprefix, prefix, p->HDisplay, p->VDisplay); + } else if (p->Clock == p->SynthClock) { + xf86DrvMsg(scrp->scrnIndex, X_CONFIG, + "%s%s \"%s\": %.1f MHz, %.1f kHz, %.1f Hz%s%s\n", + uprefix, prefix, p->name, p->Clock / 1000.0, + hsync, refresh, desc, desc2); + } else { + xf86DrvMsg(scrp->scrnIndex, X_CONFIG, + "%s%s \"%s\": %.1f MHz (scaled from %.1f MHz), " + "%.1f kHz, %.1f Hz%s%s\n", + uprefix, prefix, p->name, p->Clock / 1000.0, + p->SynthClock / 1000.0, hsync, refresh, desc, desc2); + } + if (hsync != 0 && refresh != 0) + xf86PrintModeline(scrp->scrnIndex,p); + p = p->next; + } while (p != NULL && p != scrp->modes); +} diff --git a/xorg-server/hw/xfree86/common/xf86Opt.h b/xorg-server/hw/xfree86/common/xf86Opt.h index 88392dc6d..b0fdaa6b6 100644 --- a/xorg-server/hw/xfree86/common/xf86Opt.h +++ b/xorg-server/hw/xfree86/common/xf86Opt.h @@ -72,7 +72,7 @@ typedef struct { extern _X_EXPORT int xf86SetIntOption(XF86OptionPtr optlist, const char *name, int deflt); extern _X_EXPORT double xf86SetRealOption(XF86OptionPtr optlist, const char *name, double deflt); -extern _X_EXPORT char *xf86SetStrOption(XF86OptionPtr optlist, const char *name, char *deflt); +extern _X_EXPORT char *xf86SetStrOption(XF86OptionPtr optlist, const char *name, const char *deflt); extern _X_EXPORT int xf86SetBoolOption(XF86OptionPtr list, const char *name, int deflt ); extern _X_EXPORT double xf86SetPercentOption(XF86OptionPtr list, const char *name, double deflt ); extern _X_EXPORT int xf86CheckIntOption(XF86OptionPtr optlist, const char *name, int deflt); @@ -91,7 +91,7 @@ extern _X_EXPORT char *xf86OptionName(XF86OptionPtr opt); extern _X_EXPORT char *xf86OptionValue(XF86OptionPtr opt); extern _X_EXPORT void xf86OptionListReport(XF86OptionPtr parm); extern _X_EXPORT XF86OptionPtr xf86FindOption(XF86OptionPtr options, const char *name); -extern _X_EXPORT char *xf86FindOptionValue(XF86OptionPtr options, const char *name); +extern _X_EXPORT const char *xf86FindOptionValue(XF86OptionPtr options, const char *name); extern _X_EXPORT void xf86MarkOptionUsed(XF86OptionPtr option); extern _X_EXPORT void xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name); extern _X_EXPORT Bool xf86CheckIfOptionUsed(XF86OptionPtr option); diff --git a/xorg-server/hw/xfree86/common/xf86Option.c b/xorg-server/hw/xfree86/common/xf86Option.c index 9c528782f..dc0a01899 100644 --- a/xorg-server/hw/xfree86/common/xf86Option.c +++ b/xorg-server/hw/xfree86/common/xf86Option.c @@ -187,7 +187,7 @@ LookupRealOption(XF86OptionPtr optlist, const char *name, double deflt, static char * -LookupStrOption(XF86OptionPtr optlist, const char *name, char *deflt, Bool markUsed) +LookupStrOption(XF86OptionPtr optlist, const char *name, const char *deflt, Bool markUsed) { OptionInfoRec o; @@ -243,7 +243,7 @@ xf86SetRealOption(XF86OptionPtr optlist, const char *name, double deflt) char * -xf86SetStrOption(XF86OptionPtr optlist, const char *name, char *deflt) +xf86SetStrOption(XF86OptionPtr optlist, const char *name, const char *deflt) { return LookupStrOption(optlist, name, deflt, TRUE); } @@ -306,7 +306,7 @@ XF86OptionPtr xf86ReplaceIntOption(XF86OptionPtr optlist, const char *name, const int val) { char tmp[16]; - sprintf(tmp,"%i",val); + snprintf(tmp,sizeof(tmp),"%i",val); return xf86AddNewOption(optlist,name,tmp); } @@ -314,7 +314,7 @@ XF86OptionPtr xf86ReplaceRealOption(XF86OptionPtr optlist, const char *name, const double val) { char tmp[32]; - snprintf(tmp,32,"%f",val); + snprintf(tmp,sizeof(tmp),"%f",val); return xf86AddNewOption(optlist,name,tmp); } @@ -328,7 +328,7 @@ XF86OptionPtr xf86ReplacePercentOption(XF86OptionPtr optlist, const char *name, const double val) { char tmp[16]; - sprintf(tmp, "%lf%%", val); + snprintf(tmp, sizeof(tmp), "%lf%%", val); return xf86AddNewOption(optlist,name,tmp); } @@ -416,7 +416,7 @@ xf86FindOption(XF86OptionPtr options, const char *name) } -char * +const char * xf86FindOptionValue(XF86OptionPtr options, const char *name) { return xf86findOptionValue(options, name); diff --git a/xorg-server/hw/xfree86/common/xf86PM.c b/xorg-server/hw/xfree86/common/xf86PM.c index 16b6bdc4a..47e0297d6 100644 --- a/xorg-server/hw/xfree86/common/xf86PM.c +++ b/xorg-server/hw/xfree86/common/xf86PM.c @@ -41,7 +41,7 @@ pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event) = NULL; static Bool suspended = FALSE; static int -eventName(pmEvent event, char **str) +eventName(pmEvent event, const char **str) { switch(event) { case XF86_APM_SYS_STANDBY: *str="System Standby Request"; return 0; @@ -179,7 +179,7 @@ xf86HandlePMEvents(int fd, pointer data) if ((n = xf86PMGetEventFromOs(fd,events,MAX_NO_EVENTS))) { do { for (i = 0; i < n; i++) { - char *str = NULL; + const char *str = NULL; int verb = eventName(events[i],&str); xf86MsgVerb(X_INFO,verb,"PM Event received: %s\n",str); diff --git a/xorg-server/hw/xfree86/common/xf86Priv.h b/xorg-server/hw/xfree86/common/xf86Priv.h index 1fe3d7e0d..8c698591e 100644 --- a/xorg-server/hw/xfree86/common/xf86Priv.h +++ b/xorg-server/hw/xfree86/common/xf86Priv.h @@ -69,7 +69,7 @@ extern _X_EXPORT Pix24Flags xf86Pix24; extern _X_EXPORT rgb xf86Weight; extern _X_EXPORT Bool xf86FlipPixels; extern _X_EXPORT Gamma xf86Gamma; -extern _X_EXPORT char *xf86ServerName; +extern _X_EXPORT const char *xf86ServerName; /* Other parameters */ diff --git a/xorg-server/hw/xfree86/common/xf86ShowOpts.c b/xorg-server/hw/xfree86/common/xf86ShowOpts.c deleted file mode 100644 index a8059168d..000000000 --- a/xorg-server/hw/xfree86/common/xf86ShowOpts.c +++ /dev/null @@ -1,130 +0,0 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86ShopwOpts.c,v 3.80 2003/10/08 14:58:27 dawes Exp $ */ -/* - * Copyright 2000-2002 by Alan Hourihane, Flint Mountain, North Wales. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Alan Hourihane not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Alan Hourihane makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Author: Marcus Schaefer, ms@suse.de - * - */ - -#include <ctype.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <X11/X.h> -#include <X11/Xmd.h> -#include "os.h" -#ifdef XFree86LOADER -#include "loaderProcs.h" -#endif -#include "xf86.h" -#include "xf86Config.h" -#include "xf86_OSlib.h" -#include "xf86Priv.h" -/* #include "xf86PciData.h" */ -#define IN_XSERVER -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" -#include "xf86DDC.h" -#if defined(__sparc__) && !defined(__OpenBSD__) -#include "xf86Bus.h" -#include "xf86Sbus.h" -#endif -#include "globals.h" - -static const char* -optionTypeToSting(OptionValueType type) -{ - switch (type) { - case OPTV_NONE: - return ""; - case OPTV_INTEGER: - return "<int>"; - case OPTV_STRING: - return "<str>"; - case OPTV_ANYSTR: - return "<str>"; - case OPTV_REAL: - return "<real>"; - case OPTV_BOOLEAN: - return "<bool>"; - case OPTV_FREQ: - return "<freq>"; - case OPTV_PERCENT: - return "<percent>"; - default: - return "<undef>"; - } -} - -void DoShowOptions (void) { - int i = 0; - char **vlist = 0; - char *pSymbol = 0; - XF86ModuleData *initData = 0; - if (! (vlist = xf86DriverlistFromCompile())) { - ErrorF("Missing output drivers\n"); - goto bail; - } - xf86LoadModules (vlist,0); - free(vlist); - for (i = 0; i < xf86NumDrivers; i++) { - if (xf86DriverList[i]->AvailableOptions) { - OptionInfoPtr pOption = (OptionInfoPtr)(*xf86DriverList[i]->AvailableOptions)(0,0); - if (! pOption) { - ErrorF ("(EE) Couldn't read option table for %s driver\n", - xf86DriverList[i]->driverName - ); - continue; - } - XNFasprintf(&pSymbol, "%sModuleData", - xf86DriverList[i]->driverName); - initData = LoaderSymbol (pSymbol); - if (initData) { - XF86ModuleVersionInfo *vers = initData->vers; - OptionInfoPtr p; - ErrorF ("Driver[%d]:%s[%s] {\n", - i,xf86DriverList[i]->driverName,vers->vendor - ); - for (p = pOption; p->name != NULL; p++) { - const char *opttype = optionTypeToSting(p->type); - /* XXX: Why overallocate by 2 bytes? - * Otherwise, this would be strdup() - */ - char *optname = malloc(strlen(p->name) + 2 + 1); - if (!optname) { - continue; - } - sprintf(optname, "%s", p->name); - ErrorF ("\t%s:%s\n", optname,opttype); - } - ErrorF ("}\n"); - } - } - } - bail: - OsCleanup (TRUE); - AbortDDX (EXIT_ERR_DRIVERS); - fflush (stderr); - exit (0); -} diff --git a/xorg-server/hw/xfree86/common/xf86Xinput.c b/xorg-server/hw/xfree86/common/xf86Xinput.c index 7feb48c1e..b9753f01d 100644 --- a/xorg-server/hw/xfree86/common/xf86Xinput.c +++ b/xorg-server/hw/xfree86/common/xf86Xinput.c @@ -460,10 +460,9 @@ HostOS(void) if (*host_os == '\0') { if (uname(&name) >= 0) - strcpy(host_os, name.sysname); + strlcpy(host_os, name.sysname, sizeof(host_os)); else { - strncpy(host_os, "unknown", sizeof(host_os)); - host_os[sizeof(host_os)-1] = '\0'; + strlcpy(host_os, "unknown", sizeof(host_os)); } } return host_os; diff --git a/xorg-server/hw/xfree86/common/xf86pciBus.c b/xorg-server/hw/xfree86/common/xf86pciBus.c index 87dc02512..b95b25359 100644 --- a/xorg-server/hw/xfree86/common/xf86pciBus.c +++ b/xorg-server/hw/xfree86/common/xf86pciBus.c @@ -82,16 +82,6 @@ static struct pci_slot_match xf86IsolateDevice = { PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0 }; -void -xf86FormatPciBusNumber(int busnum, char *buffer) -{ - /* 'buffer' should be at least 8 characters long */ - if (busnum < 256) - sprintf(buffer, "%d", busnum); - else - sprintf(buffer, "%d@%d", busnum & 0x00ff, busnum >> 8); -} - /* * xf86Bus.c interface */ @@ -1072,7 +1062,7 @@ videoPtrToDriverList(struct pci_device *dev, int i; /* Add more entries here if we ever return more than 4 drivers for any device */ - char *driverList[5] = { NULL, NULL, NULL, NULL, NULL }; + const char *driverList[5] = { NULL, NULL, NULL, NULL, NULL }; switch (dev->vendor_id) { @@ -1219,9 +1209,8 @@ matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip /* A tiny bit of sanity checking. We should probably do better */ if (strncmp(&(direntry->d_name[len-4]), ".ids", 4) == 0) { /* We need the full path name to open the file */ - strncpy(path_name, PCI_TXT_IDS_PATH, 256); - strncat(path_name, "/", 1); - strncat(path_name, direntry->d_name, (256 - strlen(path_name) - 1)); + snprintf(path_name, sizeof(path_name), "%s/%s", + PCI_TXT_IDS_PATH, direntry->d_name); fp = fopen(path_name, "r"); if (fp == NULL) { xf86Msg(X_ERROR, "Could not open %s for reading. Exiting.\n", path_name); @@ -1235,8 +1224,7 @@ matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip #endif /* __GLIBC __ */ xchomp(line); if (isdigit(line[0])) { - strncpy(vendor_str, line, 4); - vendor_str[4] = '\0'; + strlcpy(vendor_str, line, sizeof(vendor_str)); vendor = (int)strtol(vendor_str, NULL, 16); if ((strlen(&line[4])) == 0) { chip_str[0] = '\0'; @@ -1248,8 +1236,7 @@ matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip chip = -1; } else { /* Ok, it's a real ID */ - strncpy(chip_str, &line[4], 4); - chip_str[4] = '\0'; + strlcpy(chip_str, &line[4], sizeof(chip_str)); chip = (int)strtol(chip_str, NULL, 16); } } @@ -1349,7 +1336,12 @@ xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo, pVideo = (struct pci_device *) busData; - xf86FormatPciBusNumber(pVideo->bus, busnum); + if (pVideo->bus < 256) + snprintf(busnum, sizeof(busnum), "%d", pVideo->bus); + else + snprintf(busnum, sizeof(busnum), "%d@%d", + pVideo->bus & 0x00ff, pVideo->bus >> 8); + XNFasprintf(&GDev->busID, "PCI:%s:%d:%d", busnum, pVideo->dev, pVideo->func); diff --git a/xorg-server/hw/xfree86/common/xf86sbusBus.c b/xorg-server/hw/xfree86/common/xf86sbusBus.c index 181c6ab00..b7bb913fe 100644 --- a/xorg-server/hw/xfree86/common/xf86sbusBus.c +++ b/xorg-server/hw/xfree86/common/xf86sbusBus.c @@ -88,7 +88,7 @@ xf86SbusProbe(void) xf86SbusInfo = malloc(sizeof(psdp)); *xf86SbusInfo = NULL; for (i = 0; i < 32; i++) { - sprintf(fbDevName, "/dev/fb%d", i); + snprintf(fbDevName, sizeof(fbDevName), "/dev/fb%d", i); CheckSbusDevice(fbDevName, i); } if (sparcPromInit() >= 0) { diff --git a/xorg-server/hw/xfree86/ddc/xf86DDC.h b/xorg-server/hw/xfree86/ddc/xf86DDC.h index af3ba06a5..16a8641c6 100644 --- a/xorg-server/hw/xfree86/ddc/xf86DDC.h +++ b/xorg-server/hw/xfree86/ddc/xf86DDC.h @@ -100,11 +100,6 @@ typedef enum { DDC_QUIRK_DVI_SINGLE_LINK = 1 << 8, } ddc_quirk_t; -DisplayModePtr xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC); - -extern Bool -xf86MonitorIsHDMI(xf86MonPtr mon); - typedef void (* handle_detailed_fn)(struct detailed_monitor_section *,void *); void xf86ForEachDetailedBlock(xf86MonPtr mon, diff --git a/xorg-server/hw/xfree86/doc/ddxDesign.xml b/xorg-server/hw/xfree86/doc/ddxDesign.xml index c406cd744..ca5efc9be 100644 --- a/xorg-server/hw/xfree86/doc/ddxDesign.xml +++ b/xorg-server/hw/xfree86/doc/ddxDesign.xml @@ -34,7 +34,7 @@ <pubdate>&xserver.reldate;</pubdate> <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo> - <releaseinfo>Xorg server version &xserver.version;</releaseinfo> + <releaseinfo>X Server Version &xserver.version;</releaseinfo> </articleinfo> @@ -3187,7 +3187,7 @@ would not need to use these directly. <blockquote><para> <programlisting> - char *xf86FindOptionValue(XF86OptionPtr options, const char *name); + const char *xf86FindOptionValue(XF86OptionPtr options, const char *name); </programlisting> <blockquote><para> Takes a list of options and an option name, and returns the value diff --git a/xorg-server/hw/xfree86/fbdevhw/fbdevhw.c b/xorg-server/hw/xfree86/fbdevhw/fbdevhw.c index 30a2a9133..d7b4d3c20 100644 --- a/xorg-server/hw/xfree86/fbdevhw/fbdevhw.c +++ b/xorg-server/hw/xfree86/fbdevhw/fbdevhw.c @@ -265,20 +265,20 @@ fbdev_open_pci(struct pci_device * pPci, char **namep) int fd, i; for (i = 0; i < 8; i++) { - sprintf(filename, + snprintf(filename, sizeof(filename), "/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics/fb%d", pPci->domain, pPci->bus, pPci->dev, pPci->func, i); fd = open(filename, O_RDONLY, 0); if (fd < 0) { - sprintf(filename, + snprintf(filename, sizeof(filename), "/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics:fb%d", pPci->domain, pPci->bus, pPci->dev, pPci->func, i); fd = open(filename, O_RDONLY, 0); } if (fd >= 0) { close(fd); - sprintf(filename, "/dev/fb%d", i); + snprintf(filename, sizeof(filename), "/dev/fb%d", i); fd = open(filename, O_RDWR, 0); if (fd != -1) { diff --git a/xorg-server/hw/xfree86/i2c/msp3430.c b/xorg-server/hw/xfree86/i2c/msp3430.c index b58c3f09c..df8adc435 100644 --- a/xorg-server/hw/xfree86/i2c/msp3430.c +++ b/xorg-server/hw/xfree86/i2c/msp3430.c @@ -1,726 +1,727 @@ -#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <string.h>
-#include <unistd.h>
-
-#include "xf86.h"
-#include "xf86i2c.h"
-#include "msp3430.h"
-#include "i2c_def.h"
-
-#define CONTROL 0x00
-#define WR_DEM 0x10
-#define RD_DEM 0x11
-#define WR_DSP 0x12
-#define RD_DSP 0x13
-
-
-void InitMSP34xxG(MSP3430Ptr m);
-void InitMSP34x5D(MSP3430Ptr m);
-void CheckModeMSP34x5D(MSP3430Ptr m);
-char *MSP_getProductName (CARD16 product_id);
-void mpause(int milliseconds);
-
-#define __MSPDEBUG__ 0
-
-#if __MSPDEBUG__ > 3
-
-void MSPBeep(MSP3430Ptr m, CARD8 freq);
-#define __MSPBEEP MSPBeep(m,0x14);
-
-#else
-
-#define __MSPBEEP
-#endif
-
-static void SetMSP3430Control(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegValueHigh, CARD8 RegValueLow)
-{
- I2CByte data[3];
-
- data[0]=RegAddress;
- data[1]=RegValueHigh;
- data[2]=RegValueLow;
-
- I2C_WriteRead(&(m->d),data,3,NULL,0);
-}
-
-static void SetMSP3430Data(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegSubAddressHigh, CARD8 RegSubAddressLow,
- CARD8 RegValueHigh, CARD8 RegValueLow)
-{
- I2CByte data[5];
-#ifdef MSP_DEBUG
- if(!m->registers_present[RegSubAddressLow]){
- xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_ERROR, "Attempt to access non-existent register in MSP34xxX: 0x%02x 0x%02x 0x%02x <- 0x%02x 0x%02x\n",
- RegAddress, RegSubAddressHigh, RegSubAddressLow, RegValueHigh, RegValueLow);
- }
-#endif
-
- data[0] = RegAddress;
- data[1] = RegSubAddressHigh;
- data[2] = RegSubAddressLow;
- data[3] = RegValueHigh;
- data[4] = RegValueLow;
-
- I2C_WriteRead(&(m->d),data,5,NULL,0);
-}
-
-static void GetMSP3430Data(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegSubAddressHigh, CARD8 RegSubAddressLow,
- CARD8 *RegValueHigh, CARD8 *RegValueLow)
-{
- I2CByte send[3];
- I2CByte receive[2];
-
- send[0] = RegAddress;
- send[1] = RegSubAddressHigh;
- send[2] = RegSubAddressLow;
-
- I2C_WriteRead(&(m->d), send, 3, receive, 2);
-
- *RegValueHigh = receive[0];
- *RegValueLow = receive[1];
-}
-
-#if __MSPDEBUG__ > 2
-static void MSP3430DumpStatus(MSP3430Ptr m)
-{
-CARD8 status_hi, status_lo;
-CARD8 subaddr, data[2];
-
-GetMSP3430Data(m, RD_DEM, 0x02, 0x00, &status_hi, &status_lo);
-xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP34xx: SAP(8)=%d mono/NICAM(7)=%d stereo=%d %s O_1=%d O_0=%d 2nd car=%d 1st car=%d\n",
- status_hi & 1, (status_lo>>7) & 1, (status_lo>>6)&1,
- (status_lo>>5)? ( (status_hi>>1)&1? "bad NICAM reception" : "NICAM" ) :
- ((status_hi>>1)&1 ? "bogus" : "ANALOG FM/AM") ,
- (status_lo>>4)&1, (status_lo>>3)&1,!( (status_lo>>2)&1), !((status_lo>>1)&1));
-
-GetMSP3430Data(m, RD_DEM, 0x00, 0x7E, &status_hi, &status_lo);
-xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP34xx: standard result=0x%02x%02x\n",
- status_hi, status_lo);
-subaddr=0x0;
-I2C_WriteRead(&(m->d), &subaddr, 1, data, 2);
-xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP34xx: control=0x%02x%02x\n",
- data[1], data[0]);
-}
-#endif
-
-/* wrapper */
-void InitMSP3430(MSP3430Ptr m)
-{
- #if __MSPDEBUG__ > 1
- xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"InitMSP3430(m->connector=%d, m->standard=%d, m->chip_family=%d)\n",
- m->connector, m->standard, m->chip_family);
- #endif
- switch (m->chip_family) {
- case MSPFAMILY_34x0G:
- InitMSP34xxG(m);
- break;
- case MSPFAMILY_34x5G:
- InitMSP34xxG(m);
- break;
- case MSPFAMILY_34x5D:
- InitMSP34x5D(m);
- break;
- }
-}
-
-/*-----------------------------------------------------------------
-| common functions for all MSP34xx chips
-|----------------------------------------------------------------*/
-
-MSP3430Ptr DetectMSP3430(I2CBusPtr b, I2CSlaveAddr addr)
-{
- MSP3430Ptr m;
- I2CByte a;
- CARD8 hardware_version, major_revision, product_code, rom_version;
- Bool supported;
-
- m = calloc(1,sizeof(MSP3430Rec));
- if(m == NULL)return NULL;
- m->d.DevName = strdup("MSP34xx");
- m->d.SlaveAddr = addr;
- m->d.pI2CBus = b;
- m->d.NextDev = NULL;
- m->d.StartTimeout = b->StartTimeout;
- m->d.BitTimeout = b->BitTimeout;
- m->d.AcknTimeout = b->AcknTimeout;
- m->d.ByteTimeout = b->ByteTimeout;
-
- if(!I2C_WriteRead(&(m->d), NULL, 0, &a, 1))
- {
- free(m->d.DevName);
- free(m);
- return NULL;
- }
-
-
- m->standard=MSP3430_NTSC;
- m->connector=MSP3430_CONNECTOR_1;
- m->mode=MSPMODE_STEREO_A; /*stereo or chanel A if avail. */
- m->c_format=MSPFORMAT_UNKNOWN;
- m->c_standard=MSPSTANDARD_UNKNOWN;
- m->c_matrix=m->c_fmmatrix=m->c_source=0;
- m->volume=0;
- m->recheck=FALSE;
-
- GetMSP3430Data(m, RD_DSP, 0x00, 0x1E, &hardware_version, &major_revision);
- GetMSP3430Data(m, RD_DSP, 0x00, 0x1F, &product_code, &rom_version);
- m->hardware_version=hardware_version;
- m->major_revision=major_revision;
- m->product_code=product_code;
- m->rom_version=rom_version;
-
- m->chip_id=((major_revision << 8) | product_code);
-
- supported=FALSE;
- switch (major_revision) {
- case 4: /* 34xxD */
- switch (product_code) {
- case 0x05: /* 3405D */
- case 0x0A: /* 3410D */
- case 0x0F: /* 3415D */
- m->chip_family=MSPFAMILY_34x5D;
- m->recheck=TRUE;
- supported=TRUE;
- break;
- default:
- m->chip_family=MSPFAMILY_34x0D;
- }
- break;
- case 7: /* 34xxG */
- switch(product_code){
- case 0x00:
- case 0x0A:
- case 0x1E:
- case 0x28:
- case 0x32:
- m->chip_family=MSPFAMILY_34x0G;
- supported=TRUE;
- break;
- case 0x0f:
- case 0x19:
- case 0x2d:
- case 0x37:
- case 0x41:
- m->chip_family=MSPFAMILY_34x5G;
- supported=TRUE;
- #ifdef MSP_DEBUG
- memset(m->registers_present, 0, 256);
- #define A(num) m->registers_present[(num)]=1;
- #define B(num1, num2) memset(&(m->registers_present[num1]), 1, num2-num1);
- A(0x20)
- A(0x30)
- A(0x40)
- A(0x00)
- B(0x01, 0x08)
- B(0x0B, 0x0E)
- A(0x10)
- B(0x12,0x14)
- A(0x16)
- A(0x29)
- #undef B
- #undef A
- #endif
- break;
- default:
- m->chip_family=MSPFAMILY_UNKNOWN;
- }
- break;
- default:
- m->chip_family=MSPFAMILY_UNKNOWN;
- }
-
- xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "Found %s%s, rom version 0x%02x, chip_id=0x%04x\n",
- MSP_getProductName(m->chip_id), supported?"":" (unsupported)", rom_version, m->chip_id);
-
- if (!supported) {
- free(m->d.DevName);
- free(m);
- return NULL;
- }
- if(!I2CDevInit(&(m->d)))
- {
- free(m->d.DevName);
- free(m);
- return NULL;
- }
-
- return m;
-}
-
-void ResetMSP3430(MSP3430Ptr m)
-{
- /* Reset the MSP3430 */
- SetMSP3430Control(m, 0x00, 0x80, 0x00);
- /* Set it back to normal operation */
- SetMSP3430Control(m, 0x00, 0x00, 0x00);
-
- m->c_format=MSPFORMAT_UNKNOWN;
- m->c_standard=MSPSTANDARD_UNKNOWN;
- m->c_matrix=m->c_fmmatrix=m->c_source=0;
- m->volume=0;
-}
-
-void MSP3430SetVolume (MSP3430Ptr m, CARD8 value)
-{
- CARD8 result;
-#if 0
- CARD8 old_volume;
- GetMSP3430Data(m, RD_DSP, 0x00, 0x00, &old_volume, &result);
- xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP3430 result 0x%02x\n", result);
-#endif
- /* save an extra Get call */
- result=0;
-
- SetMSP3430Data(m, WR_DSP, 0x00, 0x00, value, result);
-
- SetMSP3430Data(m, WR_DSP, 0x00, 0x07, value, 0);
- m->volume=value;
-
-#if __MSPDEBUG__ > 2
- MSP3430DumpStatus(m);
- __MSPBEEP
- GetMSP3430Data(m, RD_DSP, 0x00, 0x00, &old_volume, &result);
- xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP3430 volume 0x%02x\n",value);
-#endif
-}
-
-
-void MSP3430SetSAP (MSP3430Ptr m, int mode)
-{
- xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "Put actual code to change SAP here\n");
-
- SetMSP3430Data(m, WR_DSP, 0x00, 0x08, mode & 0xff, 0x20);
-}
-
-
-#if 0
-void MSP3430SetSource(MSP3430Ptr m, CARD8 value)
-{
- /* Write to DSP, register 0x0008, (loudspeaker channel source/matrix) */
- /* This sets the source to the TV tuner, for stereo operation */
- SetMSP3430Data(m, WR_DSP, 0x00, 0x08, value, 0x20);
-}
-#endif
-
-
-char *MSP_getProductName (CARD16 product_id)
-{
- switch (product_id) {
- case 0x0400: return "MSP3400D";
- case 0x040a: return "MSP3410D";
- case 0x0405: return "MSP3405D";
- case 0x040f: return "MSP3415D";
- case 0x0700: return "MSP3400G";
- case 0x070a: return "MSP3410G";
- case 0x071e: return "MSP3430G";
- case 0x0728: return "MSP3440G";
- case 0x0732: return "MSP3450G";
- case 0x070f: return "MSP3415G";
- case 0x0719: return "MSP3425G";
- case 0x072d: return "MSP3445G";
- case 0x0737: return "MSP3455G";
- case 0x0741: return "MSP3465G";
- }
- return "MSP - unknown type";
-}
-
-#if __MSPDEBUG__ > 2
-/*puts beep in MSP output
- freq = 0x01 - 16Hz ... 0x40 - 1kHz ... 0xff - 4kHz
-*/
-void MSPBeep(MSP3430Ptr m, CARD8 freq) {
- SetMSP3430Data (m, WR_DSP, 0x00, freq, 0x7f, 0x40);
- mpause(100);
- SetMSP3430Data (m, WR_DSP, 0x00, 0x14, 0x00, 0x00);
-}
-#endif
-
-void mpause(int milliseconds) {
- int i,m;
- m=milliseconds/20;
- for (i=0;i<m;i++) usleep(20000);
-}
-
-/*-----------------------------------------------------------------
-| specific functions for all MSP34xxG chips
-|----------------------------------------------------------------*/
-
-void InitMSP34xxG(MSP3430Ptr m)
-{
-
- #if __MSPDEBUG__ > 1
- xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"InitMSP34xxG(m->connector=%d, m->standard=%d, m->chip_family=%d)\n",
- m->connector, m->standard, m->chip_family);
- #endif
- /* Reset MSP3430 */
- SetMSP3430Control(m, 0x00, 0x80, 0x00);
- /* Set it back to normal operation */
- SetMSP3430Control(m, 0x00, 0x00, 0x00);
-
- /*set MODUS register */
- /* bits: 0 - automatic sound detection */
- /* 1 - enable STATUS change */
- /* 12 - detect 6.5 Mhz carrier as D/K1, D/K2 or D/K NICAM (does not seem to work ) */
- /* 13 - detect 4.5 Mhz carrier as BTSC */
- if ( (m->standard & 0xff) == MSP3430_PAL )
- {
- SetMSP3430Data(m, WR_DEM, 0x00, 0x30, 0x30, 0x03|0x08); /* make O_ pins tristate */
- /* PAL standard */
- SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x01); /* possibly wrong */
- } else {
- SetMSP3430Data(m, WR_DEM, 0x00, 0x30, 0x20, 0x03|0x08);
- /* standard selection is M-BTSC-Stereo */
- SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x20);
- }
-
- switch(m->connector){
- case MSP3430_CONNECTOR_1:
- SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x03, 0x20);
- break;
- case MSP3430_CONNECTOR_2:
- /* this has not been checked yet.. could be bogus */
- /* SCART Input Prescale: 0 dB gain */
- SetMSP3430Data(m, WR_DSP, 0x00, 0x0d, 0x19, 0x00);
- SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x02, 0x20);
- break;
- case MSP3430_CONNECTOR_3:
- default:
- /* SCART Input Prescale: 0 dB gain */
- SetMSP3430Data(m, WR_DSP, 0x00, 0x0d, 0x19, 0x00);
-
- SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x02, 0x20);
- break;
- }
-
- switch(m->standard){
- case MSP3430_PAL:
- SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03);
- SetMSP3430Data(m, WR_DSP, 0x00, 0x10, 0x00, 0x5a);
- SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x03);
- /* Set volume to FAST_MUTE. */
- SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00);
- break;
- case MSP3430_PAL_DK1:
- SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03);
- SetMSP3430Data(m, WR_DSP, 0x00, 0x10, 0x00, 0x5a);
- SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x04);
- /* Set volume to FAST_MUTE. */
- SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00);
- break;
- case MSP3430_SECAM: /* is this right ? */
- case MSP3430_NTSC:
- /* Write to DSP, register 0x000E, (prescale FM/FM matrix) */
- SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03);
-
- /* Set volume to FAST_MUTE. */
- SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00);
- break;
- }
-
-}
-
-/*-----------------------------------------------------------------
-| specific functions for all MSP34x5D chips
-|----------------------------------------------------------------*/
-
-void InitMSP34x5D(MSP3430Ptr m)
-{
-int count;
-CARD8 high,low;
-CARD16 result,standard;
-CARD16 peak;
-
-
-if (m->c_format==MSPFORMAT_UNKNOWN) ResetMSP3430(m);
-else {
- /*mute volume*/
- SetMSP3430Data (m, WR_DSP, 0x00, 0x00, 0x00, 0x00);
-}
-
-
-
- switch(m->connector){
- case MSP3430_CONNECTOR_2:
- case MSP3430_CONNECTOR_3:
- if (m->c_format!=MSPFORMAT_SCART) {
- /* SCART Input Prescale: 0 dB gain */
- SetMSP3430Data (m, WR_DSP, 0x00, 0x0d, 0x19, 0x00);
- /* this has not been checked yet.. could be bogus */
- m->c_format=MSPFORMAT_SCART; /*stereo*/
- }
- break;
- case MSP3430_CONNECTOR_1:
- default:
-
- switch ( m->standard & 0x00ff ) {
- case MSP3430_PAL:
- switch( m->standard ) {
- case MSP3430_PAL_DK1:
- standard=MSPSTANDARD_FM_DK1;
- break;
-/* case MSP3430_PAL_DK2:
- standard=MSPSTANDARD_FM_DK2;
- break;
- case MSP3430_PAL_BG:
- may be FM stereo (Germany) or FM NICAM (Scandinavia,spain)
- standard=MSPSTANDARD_AUTO;
- break;
-*/
- default:
- standard=MSPSTANDARD_AUTO;
- }
- break;
- case MSP3430_SECAM:
- standard=MSPSTANDARD_AUTO;
- case MSP3430_NTSC:
- /* Only MSP34x5 supported format - Korean NTSC-M*/
- standard=MSPSTANDARD_FM_M;
- default:
- standard=MSPSTANDARD_AUTO;
- }
-
- /*no NICAM support in MSP3410D - force to autodetect*/
- if ((m->chip_id==0x405) && (standard>=MSPSTANDARD_NICAM_BG))
- standard=MSPSTANDARD_AUTO;
-
- if (m->c_standard != standard) {
-
- SetMSP3430Data (m, WR_DEM, 0x00, 0x20, standard>>8, standard & 0xFF);
- if (standard==MSPSTANDARD_AUTO) {
- count = 50; /* time shouldn't exceed 1s, just in case */
- do {
- usleep(20000);
- GetMSP3430Data (m, RD_DEM, 0x00, 0x7e, &high, &low);
- result = ( high << 8 ) | low;
- --count;
- } while( result > 0x07ff && count > 0 );
-
- if ((result > MSPSTANDARD_AUTO))
- standard=result;
- else standard=MSPSTANDARD_UNKNOWN;
-#if __MSPDEBUG__ > 1
- xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"Detected audio standard: %d\n",result);
-#endif
- /* result = MSPSTANDARD_NICAM_L can be one of:
- SECAM_L - MSPSTANDARD_NICAM_L
- D/K1 - MSPSTANDARD_FM_DK1
- D/K2 - MSPSTANDARD_FM_DK2
- D/K-NICAM - MSPSTANDARD_NICAM_DK*/
- if( standard == MSPSTANDARD_NICAM_L ) {
- if ((m->standard & 0x00ff)==MSP3430_PAL) {
- /* force PAL D/K */
- standard=MSPSTANDARD_FM_DK1;
- SetMSP3430Data (m, WR_DEM, 0x00, 0x20, standard>>8, standard & 0xFF);
-#if __MSPDEBUG__ > 1
- xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO, "Detected 6.5MHz carrier - forced to D/K1 !!!\n" );
-#endif
- }
- }
- }
- m->c_standard=standard;
- } /*end - standard changed*/
- else {
- if (standard<MSPSTANDARD_NICAM_BG) {
- /* get old value of ident. mode register*/
- GetMSP3430Data (m, RD_DSP, 0x00, 0x15, &high, &low);
- /* reset Ident-Filter */
- SetMSP3430Data (m, WR_DSP, 0x00, 0x14, 0x00, 0x3F);
- /* put back old value to ident. mode register*/
- SetMSP3430Data (m, WR_DSP, 0x00, 0x14, 0x00, low);
- }
- }
-
- if (standard<=MSPSTANDARD_AUTO) {
- m->c_format=MSPFORMAT_1xFM;
- }
- else if (standard<MSPSTANDARD_NICAM_BG) {
- /* set FM prescale */
- SetMSP3430Data (m, WR_DSP, 0x00, 0x0e, 0x30, 0);
- /* set FM deemphasis*/
- SetMSP3430Data (m, WR_DSP, 0x00, 0x0f, ((standard==MSPSTANDARD_FM_M)?0:1), 0);
-
- /* check if FM2 carrier is present */
- /*turn off FM DC Notch*/
- SetMSP3430Data (m, WR_DSP, 0x00, 0x17, 0x00, 0x3f);
- /*matrix source for Quasi-Peak Detector - stereo: ch2->L ch1->R*/
- SetMSP3430Data (m, WR_DSP, 0x00, 0x0c, 0x00, 0x20);
-
- mpause(250);
- GetMSP3430Data (m, RD_DSP, 0x00, 0x1A, &high, &low);
- peak = (high << 8) | low;
-#if __MSPDEBUG__ > 1
- xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"Second carrier Quasi-Peak detection: %d\n",peak);
-#endif
- /*turn on FM DC Notch*/
- SetMSP3430Data (m, WR_DSP, 0x00, 0x17, 0x00, 0x00);
-
- if (peak<5) {
- /* if second carrier not detected - only mono from first carrier*/
- m->c_format=MSPFORMAT_1xFM;
- }
- else {
- m->c_format=MSPFORMAT_2xFM;
- /*start of FM identification process - FM_WAIT
- wait at least 0.5s - used 1s - gives beter resolution*/
- mpause(1000);
- }
- }
- else {
- if (standard==MSPSTANDARD_NICAM_L) {
- m->c_format=MSPFORMAT_NICAM_AM;
- /* set AM prescale */
- SetMSP3430Data (m, WR_DSP, 0x00, 0x0e, 0x7C, 0);
- }
- else {
- m->c_format=MSPFORMAT_NICAM_FM;
- /* set FM prescale */
- SetMSP3430Data (m, WR_DSP, 0x00, 0x0e, 0x30, 0);
- }
- /* set FM deemphasis*/
- SetMSP3430Data (m, WR_DSP, 0x00, 0x0f, 0x00, 0);
- /* set NICAM prescale to 0dB */
- SetMSP3430Data (m, WR_DSP, 0x00, 0x10, 0x20, 0);
- }
-
- break;
- } /*end - case conector*/
-
- CheckModeMSP34x5D(m);
-
- /* Set volume to FAST_MUTE. */
- /*SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00);*/
- /*set volume*/
- MSP3430SetVolume(m,m->volume);
-
- __MSPBEEP
-
-
-} /* EnableMSP34x5D ()... */
-
-
-
-
-void CheckModeMSP34x5D(MSP3430Ptr m) {
- const char stereo_on=25;
- const char stereo_off=20;
- const char dual_on=-stereo_on;
- const char dual_off=-stereo_off;
- char detect;
- CARD8 matrix, fmmatrix, source, high, low;
-
- fmmatrix=0; /*no matrix*/
- source=0; /*FM*/
- switch (m->c_format) {
- case MSPFORMAT_NICAM_FM:
- case MSPFORMAT_NICAM_AM:
- case MSPFORMAT_SCART:
- source=( (m->c_format == MSPFORMAT_SCART)?2:1 );
- switch (m->mode) {
- case MSPMODE_MONO:
- matrix=0x30; /*MONO*/
- break;
- case MSPMODE_A:
- matrix=0x00; /*A*/
- break;
- case MSPMODE_B:
- matrix=0x10; /*B*/
- break;
- default:
- matrix=0x20; /*STEREO*/
- break;
- }
- break;
- default:
- case MSPFORMAT_1xFM:
- matrix=0x00; /*A*/
- break;
- case MSPFORMAT_2xFM:
- switch (m->mode) {
- case MSPMODE_MONO:
- matrix=0x30; /*MONO*/
- break;
- case MSPMODE_STEREO:
- matrix=0x20; /*STEREO*/
- fmmatrix=((m->c_standard==MSPSTANDARD_FM_M)?2:1);
- break;
- case MSPMODE_AB:
- matrix=0x20; /*STEREO*/
- break;
- case MSPMODE_A:
- matrix=0x00; /*A*/
- break;
- case MSPMODE_B:
- matrix=0x10; /*B*/
- break;
- default:
- /*FM_IDENT_CHECK*/
- GetMSP3430Data (m, RD_DSP, 0x00, 0x18, &high, &low);
- detect=(char)high;
-#if __MSPDEBUG__ > 1
- xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"Stereo Detection Register: %d\n",detect);
-#endif
- if (detect>=((m->c_mode==MSPMODE_STEREO)?stereo_off:stereo_on)) {
- m->c_mode=MSPMODE_STEREO;
- matrix=0x20; /*STEREO*/
- fmmatrix=((m->c_standard==MSPSTANDARD_FM_M)?2:1);
- }
- else if (detect<=((m->c_mode==MSPMODE_AB)?dual_off:dual_on)) {
- m->c_mode=MSPMODE_AB;
- switch (m->mode) {
- case MSPMODE_STEREO_AB: matrix=0x20; break;
- case MSPMODE_STEREO_B: matrix=0x10; break;
- default:
- case MSPMODE_A: matrix=0x00; break;
- }
- }
- else {
- m->c_mode=MSPMODE_MONO;
- matrix=0x30; /*MONO*/
- }
- break;
- } /* end - case mode*/
- break;
- }
-
- if (m->c_fmmatrix != fmmatrix) {
- GetMSP3430Data (m, RD_DSP, 0x00, 0x0e, &high, &low);
- SetMSP3430Data (m, WR_DSP, 0x00, 0x0e, high, fmmatrix);
- m->c_fmmatrix = fmmatrix;
- }
-
- if ((m->c_matrix != matrix) || (m->c_source != source)) {
- /*set chanel source and matrix for loudspeaker*/
- SetMSP3430Data (m, WR_DSP, 0x00, 0x08, source, matrix);
-
- m->c_matrix = matrix;
- m->c_source = source;
- }
-
- if ( ((m->c_format) & 0xF0) == MSPFORMAT_NICAM)
- SetMSP3430Data (m, WR_DEM, 0x00, 0x21, 0, 1);
-
-#if __MSPDEBUG__ > 0
- char *msg;
- switch (matrix) {
- case 0x30: /*MONO*/
- msg="MONO";
- break;
- case 0x00: /*LEFT*/
- msg="MONO/CHANNEL_1";
- break;
- case 0x10: /*RIGHT*/
- msg="MONO/CHANNEL_2";
- break;
- case 0x20: /*LEFT*/
- msg="STEREO";
- break;
- default:
- msg="unknown";
- break;
- }
- xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"Audio mode set to: %s\n",msg);
-#endif
-}
-
+#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <string.h> +#include <unistd.h> + +#include "xf86.h" +#include "xf86i2c.h" +#include "msp3430.h" +#include "i2c_def.h" + +#define CONTROL 0x00 +#define WR_DEM 0x10 +#define RD_DEM 0x11 +#define WR_DSP 0x12 +#define RD_DSP 0x13 + + +void InitMSP34xxG(MSP3430Ptr m); +void InitMSP34x5D(MSP3430Ptr m); +void CheckModeMSP34x5D(MSP3430Ptr m); +static const char *MSP_getProductName (CARD16 product_id); +void mpause(int milliseconds); + +#define __MSPDEBUG__ 0 + +#if __MSPDEBUG__ > 3 + +void MSPBeep(MSP3430Ptr m, CARD8 freq); +#define __MSPBEEP MSPBeep(m,0x14); + +#else + +#define __MSPBEEP +#endif + +static void SetMSP3430Control(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegValueHigh, CARD8 RegValueLow) +{ + I2CByte data[3]; + + data[0]=RegAddress; + data[1]=RegValueHigh; + data[2]=RegValueLow; + + I2C_WriteRead(&(m->d),data,3,NULL,0); +} + +static void SetMSP3430Data(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegSubAddressHigh, CARD8 RegSubAddressLow, + CARD8 RegValueHigh, CARD8 RegValueLow) +{ + I2CByte data[5]; +#ifdef MSP_DEBUG + if(!m->registers_present[RegSubAddressLow]){ + xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_ERROR, "Attempt to access non-existent register in MSP34xxX: 0x%02x 0x%02x 0x%02x <- 0x%02x 0x%02x\n", + RegAddress, RegSubAddressHigh, RegSubAddressLow, RegValueHigh, RegValueLow); + } +#endif + + data[0] = RegAddress; + data[1] = RegSubAddressHigh; + data[2] = RegSubAddressLow; + data[3] = RegValueHigh; + data[4] = RegValueLow; + + I2C_WriteRead(&(m->d),data,5,NULL,0); +} + +static void GetMSP3430Data(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegSubAddressHigh, CARD8 RegSubAddressLow, + CARD8 *RegValueHigh, CARD8 *RegValueLow) +{ + I2CByte send[3]; + I2CByte receive[2]; + + send[0] = RegAddress; + send[1] = RegSubAddressHigh; + send[2] = RegSubAddressLow; + + I2C_WriteRead(&(m->d), send, 3, receive, 2); + + *RegValueHigh = receive[0]; + *RegValueLow = receive[1]; +} + +#if __MSPDEBUG__ > 2 +static void MSP3430DumpStatus(MSP3430Ptr m) +{ +CARD8 status_hi, status_lo; +CARD8 subaddr, data[2]; + +GetMSP3430Data(m, RD_DEM, 0x02, 0x00, &status_hi, &status_lo); +xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP34xx: SAP(8)=%d mono/NICAM(7)=%d stereo=%d %s O_1=%d O_0=%d 2nd car=%d 1st car=%d\n", + status_hi & 1, (status_lo>>7) & 1, (status_lo>>6)&1, + (status_lo>>5)? ( (status_hi>>1)&1? "bad NICAM reception" : "NICAM" ) : + ((status_hi>>1)&1 ? "bogus" : "ANALOG FM/AM") , + (status_lo>>4)&1, (status_lo>>3)&1,!( (status_lo>>2)&1), !((status_lo>>1)&1)); + +GetMSP3430Data(m, RD_DEM, 0x00, 0x7E, &status_hi, &status_lo); +xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP34xx: standard result=0x%02x%02x\n", + status_hi, status_lo); +subaddr=0x0; +I2C_WriteRead(&(m->d), &subaddr, 1, data, 2); +xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP34xx: control=0x%02x%02x\n", + data[1], data[0]); +} +#endif + +/* wrapper */ +void InitMSP3430(MSP3430Ptr m) +{ + #if __MSPDEBUG__ > 1 + xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"InitMSP3430(m->connector=%d, m->standard=%d, m->chip_family=%d)\n", + m->connector, m->standard, m->chip_family); + #endif + switch (m->chip_family) { + case MSPFAMILY_34x0G: + InitMSP34xxG(m); + break; + case MSPFAMILY_34x5G: + InitMSP34xxG(m); + break; + case MSPFAMILY_34x5D: + InitMSP34x5D(m); + break; + } +} + +/*----------------------------------------------------------------- +| common functions for all MSP34xx chips +|----------------------------------------------------------------*/ + +MSP3430Ptr DetectMSP3430(I2CBusPtr b, I2CSlaveAddr addr) +{ + MSP3430Ptr m; + I2CByte a; + CARD8 hardware_version, major_revision, product_code, rom_version; + Bool supported; + + m = calloc(1,sizeof(MSP3430Rec)); + if(m == NULL)return NULL; + m->d.DevName = strdup("MSP34xx"); + m->d.SlaveAddr = addr; + m->d.pI2CBus = b; + m->d.NextDev = NULL; + m->d.StartTimeout = b->StartTimeout; + m->d.BitTimeout = b->BitTimeout; + m->d.AcknTimeout = b->AcknTimeout; + m->d.ByteTimeout = b->ByteTimeout; + + if(!I2C_WriteRead(&(m->d), NULL, 0, &a, 1)) + { + free(m->d.DevName); + free(m); + return NULL; + } + + + m->standard=MSP3430_NTSC; + m->connector=MSP3430_CONNECTOR_1; + m->mode=MSPMODE_STEREO_A; /*stereo or chanel A if avail. */ + m->c_format=MSPFORMAT_UNKNOWN; + m->c_standard=MSPSTANDARD_UNKNOWN; + m->c_matrix=m->c_fmmatrix=m->c_source=0; + m->volume=0; + m->recheck=FALSE; + + GetMSP3430Data(m, RD_DSP, 0x00, 0x1E, &hardware_version, &major_revision); + GetMSP3430Data(m, RD_DSP, 0x00, 0x1F, &product_code, &rom_version); + m->hardware_version=hardware_version; + m->major_revision=major_revision; + m->product_code=product_code; + m->rom_version=rom_version; + + m->chip_id=((major_revision << 8) | product_code); + + supported=FALSE; + switch (major_revision) { + case 4: /* 34xxD */ + switch (product_code) { + case 0x05: /* 3405D */ + case 0x0A: /* 3410D */ + case 0x0F: /* 3415D */ + m->chip_family=MSPFAMILY_34x5D; + m->recheck=TRUE; + supported=TRUE; + break; + default: + m->chip_family=MSPFAMILY_34x0D; + } + break; + case 7: /* 34xxG */ + switch(product_code){ + case 0x00: + case 0x0A: + case 0x1E: + case 0x28: + case 0x32: + m->chip_family=MSPFAMILY_34x0G; + supported=TRUE; + break; + case 0x0f: + case 0x19: + case 0x2d: + case 0x37: + case 0x41: + m->chip_family=MSPFAMILY_34x5G; + supported=TRUE; + #ifdef MSP_DEBUG + memset(m->registers_present, 0, 256); + #define A(num) m->registers_present[(num)]=1; + #define B(num1, num2) memset(&(m->registers_present[num1]), 1, num2-num1); + A(0x20) + A(0x30) + A(0x40) + A(0x00) + B(0x01, 0x08) + B(0x0B, 0x0E) + A(0x10) + B(0x12,0x14) + A(0x16) + A(0x29) + #undef B + #undef A + #endif + break; + default: + m->chip_family=MSPFAMILY_UNKNOWN; + } + break; + default: + m->chip_family=MSPFAMILY_UNKNOWN; + } + + xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "Found %s%s, rom version 0x%02x, chip_id=0x%04x\n", + MSP_getProductName(m->chip_id), supported?"":" (unsupported)", rom_version, m->chip_id); + + if (!supported) { + free(m->d.DevName); + free(m); + return NULL; + } + if(!I2CDevInit(&(m->d))) + { + free(m->d.DevName); + free(m); + return NULL; + } + + return m; +} + +void ResetMSP3430(MSP3430Ptr m) +{ + /* Reset the MSP3430 */ + SetMSP3430Control(m, 0x00, 0x80, 0x00); + /* Set it back to normal operation */ + SetMSP3430Control(m, 0x00, 0x00, 0x00); + + m->c_format=MSPFORMAT_UNKNOWN; + m->c_standard=MSPSTANDARD_UNKNOWN; + m->c_matrix=m->c_fmmatrix=m->c_source=0; + m->volume=0; +} + +void MSP3430SetVolume (MSP3430Ptr m, CARD8 value) +{ + CARD8 result; +#if 0 + CARD8 old_volume; + GetMSP3430Data(m, RD_DSP, 0x00, 0x00, &old_volume, &result); + xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP3430 result 0x%02x\n", result); +#endif + /* save an extra Get call */ + result=0; + + SetMSP3430Data(m, WR_DSP, 0x00, 0x00, value, result); + + SetMSP3430Data(m, WR_DSP, 0x00, 0x07, value, 0); + m->volume=value; + +#if __MSPDEBUG__ > 2 + MSP3430DumpStatus(m); + __MSPBEEP + GetMSP3430Data(m, RD_DSP, 0x00, 0x00, &old_volume, &result); + xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP3430 volume 0x%02x\n",value); +#endif +} + + +void MSP3430SetSAP (MSP3430Ptr m, int mode) +{ + xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "Put actual code to change SAP here\n"); + + SetMSP3430Data(m, WR_DSP, 0x00, 0x08, mode & 0xff, 0x20); +} + + +#if 0 +void MSP3430SetSource(MSP3430Ptr m, CARD8 value) +{ + /* Write to DSP, register 0x0008, (loudspeaker channel source/matrix) */ + /* This sets the source to the TV tuner, for stereo operation */ + SetMSP3430Data(m, WR_DSP, 0x00, 0x08, value, 0x20); +} +#endif + + +static const char * +MSP_getProductName (CARD16 product_id) +{ + switch (product_id) { + case 0x0400: return "MSP3400D"; + case 0x040a: return "MSP3410D"; + case 0x0405: return "MSP3405D"; + case 0x040f: return "MSP3415D"; + case 0x0700: return "MSP3400G"; + case 0x070a: return "MSP3410G"; + case 0x071e: return "MSP3430G"; + case 0x0728: return "MSP3440G"; + case 0x0732: return "MSP3450G"; + case 0x070f: return "MSP3415G"; + case 0x0719: return "MSP3425G"; + case 0x072d: return "MSP3445G"; + case 0x0737: return "MSP3455G"; + case 0x0741: return "MSP3465G"; + } + return "MSP - unknown type"; +} + +#if __MSPDEBUG__ > 2 +/*puts beep in MSP output + freq = 0x01 - 16Hz ... 0x40 - 1kHz ... 0xff - 4kHz +*/ +void MSPBeep(MSP3430Ptr m, CARD8 freq) { + SetMSP3430Data (m, WR_DSP, 0x00, freq, 0x7f, 0x40); + mpause(100); + SetMSP3430Data (m, WR_DSP, 0x00, 0x14, 0x00, 0x00); +} +#endif + +void mpause(int milliseconds) { + int i,m; + m=milliseconds/20; + for (i=0;i<m;i++) usleep(20000); +} + +/*----------------------------------------------------------------- +| specific functions for all MSP34xxG chips +|----------------------------------------------------------------*/ + +void InitMSP34xxG(MSP3430Ptr m) +{ + + #if __MSPDEBUG__ > 1 + xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"InitMSP34xxG(m->connector=%d, m->standard=%d, m->chip_family=%d)\n", + m->connector, m->standard, m->chip_family); + #endif + /* Reset MSP3430 */ + SetMSP3430Control(m, 0x00, 0x80, 0x00); + /* Set it back to normal operation */ + SetMSP3430Control(m, 0x00, 0x00, 0x00); + + /*set MODUS register */ + /* bits: 0 - automatic sound detection */ + /* 1 - enable STATUS change */ + /* 12 - detect 6.5 Mhz carrier as D/K1, D/K2 or D/K NICAM (does not seem to work ) */ + /* 13 - detect 4.5 Mhz carrier as BTSC */ + if ( (m->standard & 0xff) == MSP3430_PAL ) + { + SetMSP3430Data(m, WR_DEM, 0x00, 0x30, 0x30, 0x03|0x08); /* make O_ pins tristate */ + /* PAL standard */ + SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x01); /* possibly wrong */ + } else { + SetMSP3430Data(m, WR_DEM, 0x00, 0x30, 0x20, 0x03|0x08); + /* standard selection is M-BTSC-Stereo */ + SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x20); + } + + switch(m->connector){ + case MSP3430_CONNECTOR_1: + SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x03, 0x20); + break; + case MSP3430_CONNECTOR_2: + /* this has not been checked yet.. could be bogus */ + /* SCART Input Prescale: 0 dB gain */ + SetMSP3430Data(m, WR_DSP, 0x00, 0x0d, 0x19, 0x00); + SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x02, 0x20); + break; + case MSP3430_CONNECTOR_3: + default: + /* SCART Input Prescale: 0 dB gain */ + SetMSP3430Data(m, WR_DSP, 0x00, 0x0d, 0x19, 0x00); + + SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x02, 0x20); + break; + } + + switch(m->standard){ + case MSP3430_PAL: + SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03); + SetMSP3430Data(m, WR_DSP, 0x00, 0x10, 0x00, 0x5a); + SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x03); + /* Set volume to FAST_MUTE. */ + SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00); + break; + case MSP3430_PAL_DK1: + SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03); + SetMSP3430Data(m, WR_DSP, 0x00, 0x10, 0x00, 0x5a); + SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x04); + /* Set volume to FAST_MUTE. */ + SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00); + break; + case MSP3430_SECAM: /* is this right ? */ + case MSP3430_NTSC: + /* Write to DSP, register 0x000E, (prescale FM/FM matrix) */ + SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03); + + /* Set volume to FAST_MUTE. */ + SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00); + break; + } + +} + +/*----------------------------------------------------------------- +| specific functions for all MSP34x5D chips +|----------------------------------------------------------------*/ + +void InitMSP34x5D(MSP3430Ptr m) +{ +int count; +CARD8 high,low; +CARD16 result,standard; +CARD16 peak; + + +if (m->c_format==MSPFORMAT_UNKNOWN) ResetMSP3430(m); +else { + /*mute volume*/ + SetMSP3430Data (m, WR_DSP, 0x00, 0x00, 0x00, 0x00); +} + + + + switch(m->connector){ + case MSP3430_CONNECTOR_2: + case MSP3430_CONNECTOR_3: + if (m->c_format!=MSPFORMAT_SCART) { + /* SCART Input Prescale: 0 dB gain */ + SetMSP3430Data (m, WR_DSP, 0x00, 0x0d, 0x19, 0x00); + /* this has not been checked yet.. could be bogus */ + m->c_format=MSPFORMAT_SCART; /*stereo*/ + } + break; + case MSP3430_CONNECTOR_1: + default: + + switch ( m->standard & 0x00ff ) { + case MSP3430_PAL: + switch( m->standard ) { + case MSP3430_PAL_DK1: + standard=MSPSTANDARD_FM_DK1; + break; +/* case MSP3430_PAL_DK2: + standard=MSPSTANDARD_FM_DK2; + break; + case MSP3430_PAL_BG: + may be FM stereo (Germany) or FM NICAM (Scandinavia,spain) + standard=MSPSTANDARD_AUTO; + break; +*/ + default: + standard=MSPSTANDARD_AUTO; + } + break; + case MSP3430_SECAM: + standard=MSPSTANDARD_AUTO; + case MSP3430_NTSC: + /* Only MSP34x5 supported format - Korean NTSC-M*/ + standard=MSPSTANDARD_FM_M; + default: + standard=MSPSTANDARD_AUTO; + } + + /*no NICAM support in MSP3410D - force to autodetect*/ + if ((m->chip_id==0x405) && (standard>=MSPSTANDARD_NICAM_BG)) + standard=MSPSTANDARD_AUTO; + + if (m->c_standard != standard) { + + SetMSP3430Data (m, WR_DEM, 0x00, 0x20, standard>>8, standard & 0xFF); + if (standard==MSPSTANDARD_AUTO) { + count = 50; /* time shouldn't exceed 1s, just in case */ + do { + usleep(20000); + GetMSP3430Data (m, RD_DEM, 0x00, 0x7e, &high, &low); + result = ( high << 8 ) | low; + --count; + } while( result > 0x07ff && count > 0 ); + + if ((result > MSPSTANDARD_AUTO)) + standard=result; + else standard=MSPSTANDARD_UNKNOWN; +#if __MSPDEBUG__ > 1 + xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"Detected audio standard: %d\n",result); +#endif + /* result = MSPSTANDARD_NICAM_L can be one of: + SECAM_L - MSPSTANDARD_NICAM_L + D/K1 - MSPSTANDARD_FM_DK1 + D/K2 - MSPSTANDARD_FM_DK2 + D/K-NICAM - MSPSTANDARD_NICAM_DK*/ + if( standard == MSPSTANDARD_NICAM_L ) { + if ((m->standard & 0x00ff)==MSP3430_PAL) { + /* force PAL D/K */ + standard=MSPSTANDARD_FM_DK1; + SetMSP3430Data (m, WR_DEM, 0x00, 0x20, standard>>8, standard & 0xFF); +#if __MSPDEBUG__ > 1 + xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO, "Detected 6.5MHz carrier - forced to D/K1 !!!\n" ); +#endif + } + } + } + m->c_standard=standard; + } /*end - standard changed*/ + else { + if (standard<MSPSTANDARD_NICAM_BG) { + /* get old value of ident. mode register*/ + GetMSP3430Data (m, RD_DSP, 0x00, 0x15, &high, &low); + /* reset Ident-Filter */ + SetMSP3430Data (m, WR_DSP, 0x00, 0x14, 0x00, 0x3F); + /* put back old value to ident. mode register*/ + SetMSP3430Data (m, WR_DSP, 0x00, 0x14, 0x00, low); + } + } + + if (standard<=MSPSTANDARD_AUTO) { + m->c_format=MSPFORMAT_1xFM; + } + else if (standard<MSPSTANDARD_NICAM_BG) { + /* set FM prescale */ + SetMSP3430Data (m, WR_DSP, 0x00, 0x0e, 0x30, 0); + /* set FM deemphasis*/ + SetMSP3430Data (m, WR_DSP, 0x00, 0x0f, ((standard==MSPSTANDARD_FM_M)?0:1), 0); + + /* check if FM2 carrier is present */ + /*turn off FM DC Notch*/ + SetMSP3430Data (m, WR_DSP, 0x00, 0x17, 0x00, 0x3f); + /*matrix source for Quasi-Peak Detector - stereo: ch2->L ch1->R*/ + SetMSP3430Data (m, WR_DSP, 0x00, 0x0c, 0x00, 0x20); + + mpause(250); + GetMSP3430Data (m, RD_DSP, 0x00, 0x1A, &high, &low); + peak = (high << 8) | low; +#if __MSPDEBUG__ > 1 + xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"Second carrier Quasi-Peak detection: %d\n",peak); +#endif + /*turn on FM DC Notch*/ + SetMSP3430Data (m, WR_DSP, 0x00, 0x17, 0x00, 0x00); + + if (peak<5) { + /* if second carrier not detected - only mono from first carrier*/ + m->c_format=MSPFORMAT_1xFM; + } + else { + m->c_format=MSPFORMAT_2xFM; + /*start of FM identification process - FM_WAIT + wait at least 0.5s - used 1s - gives beter resolution*/ + mpause(1000); + } + } + else { + if (standard==MSPSTANDARD_NICAM_L) { + m->c_format=MSPFORMAT_NICAM_AM; + /* set AM prescale */ + SetMSP3430Data (m, WR_DSP, 0x00, 0x0e, 0x7C, 0); + } + else { + m->c_format=MSPFORMAT_NICAM_FM; + /* set FM prescale */ + SetMSP3430Data (m, WR_DSP, 0x00, 0x0e, 0x30, 0); + } + /* set FM deemphasis*/ + SetMSP3430Data (m, WR_DSP, 0x00, 0x0f, 0x00, 0); + /* set NICAM prescale to 0dB */ + SetMSP3430Data (m, WR_DSP, 0x00, 0x10, 0x20, 0); + } + + break; + } /*end - case conector*/ + + CheckModeMSP34x5D(m); + + /* Set volume to FAST_MUTE. */ + /*SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00);*/ + /*set volume*/ + MSP3430SetVolume(m,m->volume); + + __MSPBEEP + + +} /* EnableMSP34x5D ()... */ + + + + +void CheckModeMSP34x5D(MSP3430Ptr m) { + const char stereo_on=25; + const char stereo_off=20; + const char dual_on=-stereo_on; + const char dual_off=-stereo_off; + char detect; + CARD8 matrix, fmmatrix, source, high, low; + + fmmatrix=0; /*no matrix*/ + source=0; /*FM*/ + switch (m->c_format) { + case MSPFORMAT_NICAM_FM: + case MSPFORMAT_NICAM_AM: + case MSPFORMAT_SCART: + source=( (m->c_format == MSPFORMAT_SCART)?2:1 ); + switch (m->mode) { + case MSPMODE_MONO: + matrix=0x30; /*MONO*/ + break; + case MSPMODE_A: + matrix=0x00; /*A*/ + break; + case MSPMODE_B: + matrix=0x10; /*B*/ + break; + default: + matrix=0x20; /*STEREO*/ + break; + } + break; + default: + case MSPFORMAT_1xFM: + matrix=0x00; /*A*/ + break; + case MSPFORMAT_2xFM: + switch (m->mode) { + case MSPMODE_MONO: + matrix=0x30; /*MONO*/ + break; + case MSPMODE_STEREO: + matrix=0x20; /*STEREO*/ + fmmatrix=((m->c_standard==MSPSTANDARD_FM_M)?2:1); + break; + case MSPMODE_AB: + matrix=0x20; /*STEREO*/ + break; + case MSPMODE_A: + matrix=0x00; /*A*/ + break; + case MSPMODE_B: + matrix=0x10; /*B*/ + break; + default: + /*FM_IDENT_CHECK*/ + GetMSP3430Data (m, RD_DSP, 0x00, 0x18, &high, &low); + detect=(char)high; +#if __MSPDEBUG__ > 1 + xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"Stereo Detection Register: %d\n",detect); +#endif + if (detect>=((m->c_mode==MSPMODE_STEREO)?stereo_off:stereo_on)) { + m->c_mode=MSPMODE_STEREO; + matrix=0x20; /*STEREO*/ + fmmatrix=((m->c_standard==MSPSTANDARD_FM_M)?2:1); + } + else if (detect<=((m->c_mode==MSPMODE_AB)?dual_off:dual_on)) { + m->c_mode=MSPMODE_AB; + switch (m->mode) { + case MSPMODE_STEREO_AB: matrix=0x20; break; + case MSPMODE_STEREO_B: matrix=0x10; break; + default: + case MSPMODE_A: matrix=0x00; break; + } + } + else { + m->c_mode=MSPMODE_MONO; + matrix=0x30; /*MONO*/ + } + break; + } /* end - case mode*/ + break; + } + + if (m->c_fmmatrix != fmmatrix) { + GetMSP3430Data (m, RD_DSP, 0x00, 0x0e, &high, &low); + SetMSP3430Data (m, WR_DSP, 0x00, 0x0e, high, fmmatrix); + m->c_fmmatrix = fmmatrix; + } + + if ((m->c_matrix != matrix) || (m->c_source != source)) { + /*set chanel source and matrix for loudspeaker*/ + SetMSP3430Data (m, WR_DSP, 0x00, 0x08, source, matrix); + + m->c_matrix = matrix; + m->c_source = source; + } + + if ( ((m->c_format) & 0xF0) == MSPFORMAT_NICAM) + SetMSP3430Data (m, WR_DEM, 0x00, 0x21, 0, 1); + +#if __MSPDEBUG__ > 0 + char *msg; + switch (matrix) { + case 0x30: /*MONO*/ + msg="MONO"; + break; + case 0x00: /*LEFT*/ + msg="MONO/CHANNEL_1"; + break; + case 0x10: /*RIGHT*/ + msg="MONO/CHANNEL_2"; + break; + case 0x20: /*LEFT*/ + msg="STEREO"; + break; + default: + msg="unknown"; + break; + } + xf86DrvMsg(m->d.pI2CBus->scrnIndex,X_INFO,"Audio mode set to: %s\n",msg); +#endif +} + diff --git a/xorg-server/hw/xfree86/loader/loadmod.c b/xorg-server/hw/xfree86/loader/loadmod.c index a21f43d63..c697d74ed 100644 --- a/xorg-server/hw/xfree86/loader/loadmod.c +++ b/xorg-server/hw/xfree86/loader/loadmod.c @@ -437,14 +437,11 @@ FindModule(const char *module, const char *dirname, const char **subdirlist, PatternPtr patterns) { char buf[PATH_MAX + 1]; - char *dirpath = NULL; char *name = NULL; - int dirlen; const char **subdirs = NULL; const char **s; - dirpath = (char *)dirname; - if (strlen(dirpath) > PATH_MAX) + if (strlen(dirname) > PATH_MAX) return NULL; subdirs = InitSubdirs(subdirlist); @@ -452,17 +449,15 @@ FindModule(const char *module, const char *dirname, const char **subdirlist, return NULL; for (s = subdirs; *s; s++) { - if ((dirlen = strlen(dirpath) + strlen(*s)) > PATH_MAX) + if ((strlen(dirname) + strlen(*s)) > PATH_MAX) continue; - strcpy(buf, dirpath); + strcpy(buf, dirname); strcat(buf, *s); if ((name = FindModuleInSubdir(buf, module))) break; } FreeSubdirs(subdirs); - if (dirpath != dirname) - free(dirpath); return name; } diff --git a/xorg-server/hw/xfree86/modes/xf86Crtc.c b/xorg-server/hw/xfree86/modes/xf86Crtc.c index 953215196..da9db3460 100644 --- a/xorg-server/hw/xfree86/modes/xf86Crtc.c +++ b/xorg-server/hw/xfree86/modes/xf86Crtc.c @@ -481,7 +481,7 @@ static void xf86OutputSetMonitor (xf86OutputPtr output) { char *option_name; - char *monitor; + const char *monitor; if (!output->name) return; @@ -561,7 +561,7 @@ xf86OutputIgnored (xf86OutputPtr output) return xf86ReturnOptValBool (output->options, OPTION_IGNORE, FALSE); } -static char *direction[4] = { +static const char *direction[4] = { "normal", "left", "inverted", @@ -3063,13 +3063,13 @@ xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus) return mon; } -static char *_xf86ConnectorNames[] = { +static const char *_xf86ConnectorNames[] = { "None", "VGA", "DVI-I", "DVI-D", "DVI-A", "Composite", "S-Video", "Component", "LFP", "Proprietary", "HDMI", "DisplayPort", }; -char * +const char * xf86ConnectorGetName(xf86ConnectorType connector) { return _xf86ConnectorNames[connector]; diff --git a/xorg-server/hw/xfree86/modes/xf86Crtc.h b/xorg-server/hw/xfree86/modes/xf86Crtc.h index 716499f8d..8d4a08938 100644 --- a/xorg-server/hw/xfree86/modes/xf86Crtc.h +++ b/xorg-server/hw/xfree86/modes/xf86Crtc.h @@ -900,7 +900,7 @@ xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen); /* * Get a standard string name for a connector type */ -extern _X_EXPORT char * +extern _X_EXPORT const char * xf86ConnectorGetName(xf86ConnectorType connector); /* diff --git a/xorg-server/hw/xfree86/modes/xf86EdidModes.c b/xorg-server/hw/xfree86/modes/xf86EdidModes.c index 86065f869..0100d2a59 100644 --- a/xorg-server/hw/xfree86/modes/xf86EdidModes.c +++ b/xorg-server/hw/xfree86/modes/xf86EdidModes.c @@ -230,7 +230,7 @@ static Bool quirk_dvi_single_link(int scrnIndex, xf86MonPtr DDC) typedef struct { Bool (*detect) (int scrnIndex, xf86MonPtr DDC); ddc_quirk_t quirk; - char *description; + const char *description; } ddc_quirk_map_t; static const ddc_quirk_map_t ddc_quirks[] = { diff --git a/xorg-server/hw/xfree86/modes/xf86Modes.c b/xorg-server/hw/xfree86/modes/xf86Modes.c index dcd3a2805..49cc14992 100644 --- a/xorg-server/hw/xfree86/modes/xf86Modes.c +++ b/xorg-server/hw/xfree86/modes/xf86Modes.c @@ -272,7 +272,7 @@ xf86ModesEqual(const DisplayModeRec *pMode1, const DisplayModeRec *pMode2) } static void -add(char **p, char *new) +add(char **p, const char *new) { *p = xnfrealloc(*p, strlen(*p) + strlen(new) + 2); strcat(*p, " "); @@ -599,7 +599,7 @@ xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr *modeList, if (mode->status != MODE_OK) { if (verbose) { - char *type = ""; + const char *type = ""; if (mode->type & M_T_BUILTIN) type = "built-in "; else if (mode->type & M_T_DEFAULT) diff --git a/xorg-server/hw/xfree86/os-support/bsd/bsd_init.c b/xorg-server/hw/xfree86/os-support/bsd/bsd_init.c index b58d6a790..7079d62b4 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/bsd_init.c +++ b/xorg-server/hw/xfree86/os-support/bsd/bsd_init.c @@ -446,7 +446,7 @@ xf86OpenSyscons() } close(fd); - sprintf(vtname, "/dev/ttyv%01x", xf86Info.vtno - 1); + snprintf(vtname, sizeof(vtname), "/dev/ttyv%01x", xf86Info.vtno - 1); if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0) { FatalError("xf86OpenSyscons: Cannot open %s (%s)", @@ -550,13 +550,13 @@ xf86OpenPcvt() } close(fd); - sprintf(vtname, "%s%01x", vtprefix, xf86Info.vtno - 1); + snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, xf86Info.vtno - 1); if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { ErrorF("xf86OpenPcvt: Cannot open %s (%s)", vtname, strerror(errno)); xf86Info.vtno = initialVT; - sprintf(vtname, "%s%01x", vtprefix, xf86Info.vtno - 1); + snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, xf86Info.vtno - 1); if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { FatalError("xf86OpenPcvt: Cannot open %s (%s)", vtname, strerror(errno)); @@ -602,9 +602,9 @@ xf86OpenWScons() /* XXX Is this ok? */ for (i = 0; i < 8; i++) { #if defined(__NetBSD__) - sprintf(ttyname, "/dev/ttyE%d", i); + snprintf(ttyname, sizeof(ttyname), "/dev/ttyE%d", i); #elif defined(__OpenBSD__) - sprintf(ttyname, "/dev/ttyC%x", i); + snprintf(ttyname, sizeof(ttyname), "/dev/ttyC%x", i); #endif if ((fd = open(ttyname, 2)) != -1) break; diff --git a/xorg-server/hw/xfree86/os-support/bus/Sbus.c b/xorg-server/hw/xfree86/os-support/bus/Sbus.c index 7c4888126..c02d2cd55 100644 --- a/xorg-server/hw/xfree86/os-support/bus/Sbus.c +++ b/xorg-server/hw/xfree86/os-support/bus/Sbus.c @@ -1,688 +1,688 @@ -/*
- * SBUS and OpenPROM access functions.
- *
- * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#ifdef sun
-#include <sys/utsname.h>
-#endif
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-
-#include "xf86sbusBus.h"
-#include "xf86Sbus.h"
-
-int promRootNode;
-
-static int promFd = -1;
-static int promCurrentNode;
-static int promOpenCount = 0;
-static int promP1275 = -1;
-#define MAX_PROP 128
-#define MAX_VAL (4096-128-4)
-static struct openpromio *promOpio;
-
-sbusDevicePtr *xf86SbusInfo = NULL;
-
-struct sbus_devtable sbusDeviceTable[] = {
- { SBUS_DEVICE_BW2, FBTYPE_SUN2BW, "bwtwo", "sunbw2", "Sun Monochrome (bwtwo)" },
- { SBUS_DEVICE_CG2, FBTYPE_SUN2COLOR, "cgtwo", NULL, "Sun Color2 (cgtwo)" },
- { SBUS_DEVICE_CG3, FBTYPE_SUN3COLOR, "cgthree", "suncg3", "Sun Color3 (cgthree)" },
- { SBUS_DEVICE_CG4, FBTYPE_SUN4COLOR, "cgfour", NULL, "Sun Color4 (cgfour)" },
- { SBUS_DEVICE_CG6, FBTYPE_SUNFAST_COLOR, "cgsix", "suncg6", "Sun GX" },
- { SBUS_DEVICE_CG8, FBTYPE_MEMCOLOR, "cgeight", NULL, "Sun CG8/RasterOps" },
- { SBUS_DEVICE_CG12, FBTYPE_SUNGP3, "cgtwelve", NULL, "Sun GS (cgtwelve)" },
- { SBUS_DEVICE_CG14, FBTYPE_MDICOLOR, "cgfourteen", "suncg14", "Sun SX" },
- { SBUS_DEVICE_GT, FBTYPE_SUNGT, "gt", NULL, "Sun Graphics Tower" },
- { SBUS_DEVICE_MGX, -1, "mgx", NULL, "Quantum 3D MGXplus" },
- { SBUS_DEVICE_LEO, FBTYPE_SUNLEO, "leo", "sunleo", "Sun ZX or Turbo ZX" },
- { SBUS_DEVICE_TCX, FBTYPE_TCXCOLOR, "tcx", "suntcx", "Sun TCX" },
- { SBUS_DEVICE_FFB, FBTYPE_CREATOR, "ffb", "sunffb", "Sun FFB" },
- { SBUS_DEVICE_FFB, FBTYPE_CREATOR, "afb", "sunffb", "Sun Elite3D" },
- { 0, 0, NULL }
-};
-
-int
-promGetSibling(int node)
-{
- promOpio->oprom_size = sizeof(int);
-
- if (node == -1) return 0;
- *(int *)promOpio->oprom_array = node;
- if (ioctl(promFd, OPROMNEXT, promOpio) < 0)
- return 0;
- promCurrentNode = *(int *)promOpio->oprom_array;
- return *(int *)promOpio->oprom_array;
-}
-
-int
-promGetChild(int node)
-{
- promOpio->oprom_size = sizeof(int);
-
- if (!node || node == -1) return 0;
- *(int *)promOpio->oprom_array = node;
- if (ioctl(promFd, OPROMCHILD, promOpio) < 0)
- return 0;
- promCurrentNode = *(int *)promOpio->oprom_array;
- return *(int *)promOpio->oprom_array;
-}
-
-char *
-promGetProperty(const char *prop, int *lenp)
-{
- promOpio->oprom_size = MAX_VAL;
-
- strcpy(promOpio->oprom_array, prop);
- if (ioctl(promFd, OPROMGETPROP, promOpio) < 0)
- return 0;
- if (lenp) *lenp = promOpio->oprom_size;
- return promOpio->oprom_array;
-}
-
-int
-promGetBool(const char *prop)
-{
- promOpio->oprom_size = 0;
-
- *(int *)promOpio->oprom_array = 0;
- for (;;) {
- promOpio->oprom_size = MAX_PROP;
- if (ioctl(promFd, OPROMNXTPROP, promOpio) < 0)
- return 0;
- if (!promOpio->oprom_size)
- return 0;
- if (!strcmp(promOpio->oprom_array, prop))
- return 1;
- }
-}
-
-#define PROM_NODE_SIBLING 0x01
-#define PROM_NODE_PREF 0x02
-#define PROM_NODE_SBUS 0x04
-#define PROM_NODE_EBUS 0x08
-#define PROM_NODE_PCI 0x10
-
-static int
-promSetNode(sbusPromNodePtr pnode)
-{
- int node;
-
- if (!pnode->node || pnode->node == -1)
- return -1;
- if (pnode->cookie[0] & PROM_NODE_SIBLING)
- node = promGetSibling(pnode->cookie[1]);
- else
- node = promGetChild(pnode->cookie[1]);
- if (pnode->node != node)
- return -1;
- return 0;
-}
-
-static void
-promIsP1275(void)
-{
-#ifdef linux
- FILE *f;
- char buffer[1024];
-
- if (promP1275 != -1)
- return;
- promP1275 = 0;
- f = fopen("/proc/cpuinfo","r");
- if (!f) return;
- while (fgets(buffer, 1024, f) != NULL)
- if (!strncmp (buffer, "type", 4) && strstr (buffer, "sun4u")) {
- promP1275 = 1;
- break;
- }
- fclose(f);
-#elif defined(sun)
- struct utsname buffer;
-
- if ((uname(&buffer) >= 0) && !strcmp(buffer.machine, "sun4u"))
- promP1275 = TRUE;
- else
- promP1275 = FALSE;
-#elif defined(__FreeBSD__)
- promP1275 = TRUE;
-#else
-#error Missing promIsP1275() function for this OS
-#endif
-}
-
-void
-sparcPromClose(void)
-{
- if (promOpenCount > 1) {
- promOpenCount--;
- return;
- }
- if (promFd != -1) {
- close(promFd);
- promFd = -1;
- }
- free(promOpio);
- promOpio = NULL;
- promOpenCount = 0;
-}
-
-int
-sparcPromInit(void)
-{
- if (promOpenCount) {
- promOpenCount++;
- return 0;
- }
- promFd = open("/dev/openprom", O_RDONLY, 0);
- if (promFd == -1)
- return -1;
- promOpio = (struct openpromio *)malloc(4096);
- if (!promOpio) {
- sparcPromClose();
- return -1;
- }
- promRootNode = promGetSibling(0);
- if (!promRootNode) {
- sparcPromClose();
- return -1;
- }
- promIsP1275();
- promOpenCount++;
-
- return 0;
-}
-
-char *
-sparcPromGetProperty(sbusPromNodePtr pnode, const char *prop, int *lenp)
-{
- if (promSetNode(pnode))
- return NULL;
- return promGetProperty(prop, lenp);
-}
-
-int
-sparcPromGetBool(sbusPromNodePtr pnode, const char *prop)
-{
- if (promSetNode(pnode))
- return 0;
- return promGetBool(prop);
-}
-
-static char *
-promWalkGetDriverName(int node, int oldnode)
-{
- int nextnode;
- int len;
- char *prop;
- int devId, i;
-
- prop = promGetProperty("device_type", &len);
- if (prop && (len > 0)) do {
- if (!strcmp(prop, "display")) {
- prop = promGetProperty("name", &len);
- if (!prop || len <= 0)
- break;
- while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',')
- prop++;
- for (i = 0; sbusDeviceTable[i].devId; i++)
- if (!strcmp(prop, sbusDeviceTable[i].promName))
- break;
- devId = sbusDeviceTable[i].devId;
- if (!devId)
- break;
- if (sbusDeviceTable[i].driverName)
- return sbusDeviceTable[i].driverName;
- }
- } while (0);
-
- nextnode = promGetChild(node);
- if (nextnode) {
- char *name;
- name = promWalkGetDriverName(nextnode, node);
- if (name)
- return name;
- }
-
- nextnode = promGetSibling(node);
- if (nextnode)
- return promWalkGetDriverName(nextnode, node);
- return NULL;
-}
-
-char *
-sparcDriverName(void)
-{
- char *name;
-
- if (sparcPromInit() < 0)
- return NULL;
- promGetSibling(0);
- name = promWalkGetDriverName(promRootNode, 0);
- sparcPromClose();
- return name;
-}
-
-static void
-promWalkAssignNodes(int node, int oldnode, int flags, sbusDevicePtr *devicePtrs)
-{
- int nextnode;
- int len, sbus = flags & PROM_NODE_SBUS;
- char *prop;
- int devId, i, j;
- sbusPromNode pNode, pNode2;
-
- prop = promGetProperty("device_type", &len);
- if (prop && (len > 0)) do {
- if (!strcmp(prop, "display")) {
- prop = promGetProperty("name", &len);
- if (!prop || len <= 0)
- break;
- while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',')
- prop++;
- for (i = 0; sbusDeviceTable[i].devId; i++)
- if (!strcmp(prop, sbusDeviceTable[i].promName))
- break;
- devId = sbusDeviceTable[i].devId;
- if (!devId)
- break;
- if (!sbus) {
- if (devId == SBUS_DEVICE_FFB) {
- /*
- * All /SUNW,ffb outside of SBUS tree come before all
- * /SUNW,afb outside of SBUS tree in Linux.
- */
- if (!strcmp(prop, "afb"))
- flags |= PROM_NODE_PREF;
- } else if (devId != SBUS_DEVICE_CG14)
- break;
- }
- for (i = 0; i < 32; i++) {
- if (!devicePtrs[i] || devicePtrs[i]->devId != devId)
- continue;
- if (devicePtrs[i]->node.node) {
- if ((devicePtrs[i]->node.cookie[0] & ~PROM_NODE_SIBLING) <=
- (flags & ~PROM_NODE_SIBLING))
- continue;
- for (j = i + 1, pNode = devicePtrs[i]->node; j < 32; j++) {
- if (!devicePtrs[j] || devicePtrs[j]->devId != devId)
- continue;
- pNode2 = devicePtrs[j]->node;
- devicePtrs[j]->node = pNode;
- pNode = pNode2;
- }
- }
- devicePtrs[i]->node.node = node;
- devicePtrs[i]->node.cookie[0] = flags;
- devicePtrs[i]->node.cookie[1] = oldnode;
- break;
- }
- break;
- }
- } while (0);
-
- prop = promGetProperty("name", &len);
- if (prop && len > 0) {
- if (!strcmp(prop, "sbus") || !strcmp(prop, "sbi"))
- sbus = PROM_NODE_SBUS;
- }
-
- nextnode = promGetChild(node);
- if (nextnode)
- promWalkAssignNodes(nextnode, node, sbus, devicePtrs);
-
- nextnode = promGetSibling(node);
- if (nextnode)
- promWalkAssignNodes(nextnode, node, PROM_NODE_SIBLING | sbus, devicePtrs);
-}
-
-void
-sparcPromAssignNodes(void)
-{
- sbusDevicePtr psdp, *psdpp;
- int n, holes = 0, i, j;
- FILE *f;
- sbusDevicePtr devicePtrs[32];
-
- memset(devicePtrs, 0, sizeof(devicePtrs));
- for (psdpp = xf86SbusInfo, n = 0; (psdp = *psdpp); psdpp++, n++) {
- if (psdp->fbNum != n)
- holes = 1;
- devicePtrs[psdp->fbNum] = psdp;
- }
- if (holes && (f = fopen("/proc/fb", "r")) != NULL) {
- /* We could not open one of fb devices, check /proc/fb to see what
- * were the types of the cards missed. */
- char buffer[64];
- int fbNum, devId;
- static struct {
- int devId;
- char *prefix;
- } procFbPrefixes[] = {
- { SBUS_DEVICE_BW2, "BWtwo" },
- { SBUS_DEVICE_CG14, "CGfourteen" },
- { SBUS_DEVICE_CG6, "CGsix" },
- { SBUS_DEVICE_CG3, "CGthree" },
- { SBUS_DEVICE_FFB, "Creator" },
- { SBUS_DEVICE_FFB, "Elite 3D" },
- { SBUS_DEVICE_LEO, "Leo" },
- { SBUS_DEVICE_TCX, "TCX" },
- { 0, NULL },
- };
-
- while (fscanf(f, "%d %63s\n", &fbNum, buffer) == 2) {
- for (i = 0; procFbPrefixes[i].devId; i++)
- if (! strncmp(procFbPrefixes[i].prefix, buffer,
- strlen(procFbPrefixes[i].prefix)))
- break;
- devId = procFbPrefixes[i].devId;
- if (! devId) continue;
- if (devicePtrs[fbNum]) {
- if (devicePtrs[fbNum]->devId != devId)
- xf86ErrorF("Inconsistent /proc/fb with FBIOGATTR\n");
- } else if (!devicePtrs[fbNum]) {
- devicePtrs[fbNum] = psdp = xnfcalloc(sizeof (sbusDevice), 1);
- psdp->devId = devId;
- psdp->fbNum = fbNum;
- psdp->fd = -2;
- }
- }
- fclose(f);
- }
- promGetSibling(0);
- promWalkAssignNodes(promRootNode, 0, PROM_NODE_PREF, devicePtrs);
- for (i = 0, j = 0; i < 32; i++)
- if (devicePtrs[i] && devicePtrs[i]->fbNum == -1)
- j++;
- xf86SbusInfo = xnfrealloc(xf86SbusInfo, sizeof(psdp) * (n + j + 1));
- for (i = 0, psdpp = xf86SbusInfo; i < 32; i++)
- if (devicePtrs[i]) {
- if (devicePtrs[i]->fbNum == -1) {
- memmove(psdpp + 1, psdpp, sizeof(psdpp) * (n + 1));
- *psdpp = devicePtrs[i];
- } else
- n--;
- }
-}
-
-static char *
-promGetReg(int type)
-{
- char *prop;
- int len;
- static char regstr[40];
-
- regstr[0] = 0;
- prop = promGetProperty("reg", &len);
- if (prop && len >= 4) {
- unsigned int *reg = (unsigned int *)prop;
- if (!promP1275 || (type == PROM_NODE_SBUS) || (type == PROM_NODE_EBUS))
- sprintf (regstr, "@%x,%x", reg[0], reg[1]);
- else if (type == PROM_NODE_PCI) {
- if ((reg[0] >> 8) & 7)
- sprintf (regstr, "@%x,%x", (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7);
- else
- sprintf (regstr, "@%x", (reg[0] >> 11) & 0x1f);
- } else if (len == 4)
- sprintf (regstr, "@%x", reg[0]);
- else {
- unsigned int regs[2];
-
- /* Things get more complicated on UPA. If upa-portid exists,
- then address is @upa-portid,second-int-in-reg, otherwise
- it is @first-int-in-reg/16,second-int-in-reg (well, probably
- upa-portid always exists, but just to be safe). */
- memcpy (regs, reg, sizeof(regs));
- prop = promGetProperty("upa-portid", &len);
- if (prop && len == 4) {
- reg = (unsigned int *)prop;
- sprintf (regstr, "@%x,%x", reg[0], regs[1]);
- } else
- sprintf (regstr, "@%x,%x", regs[0] >> 4, regs[1]);
- }
- }
- return regstr;
-}
-
-static int
-promWalkNode2Pathname(char *path, int parent, int node, int searchNode, int type)
-{
- int nextnode;
- int len, ntype = type;
- char *prop, *p;
-
- prop = promGetProperty("name", &len);
- *path = '/';
- if (!prop || len <= 0)
- return 0;
- if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type)
- ntype = PROM_NODE_SBUS;
- else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI)
- ntype = PROM_NODE_EBUS;
- else if (!strcmp(prop, "pci") && !type)
- ntype = PROM_NODE_PCI;
- strcpy (path + 1, prop);
- p = promGetReg(type);
- if (*p)
- strcat (path, p);
- if (node == searchNode)
- return 1;
- nextnode = promGetChild(node);
- if (nextnode &&
- promWalkNode2Pathname(strchr(path, 0), node, nextnode, searchNode, ntype))
- return 1;
- nextnode = promGetSibling(node);
- if (nextnode &&
- promWalkNode2Pathname(path, parent, nextnode, searchNode, type))
- return 1;
- return 0;
-}
-
-char *
-sparcPromNode2Pathname(sbusPromNodePtr pnode)
-{
- char *ret;
-
- if (!pnode->node) return NULL;
- ret = malloc(4096);
- if (!ret) return NULL;
- if (promWalkNode2Pathname(ret, promRootNode, promGetChild(promRootNode), pnode->node, 0))
- return ret;
- free(ret);
- return NULL;
-}
-
-static int
-promWalkPathname2Node(char *name, char *regstr, int parent, int type)
-{
- int len, node, ret;
- char *prop, *p;
-
- for (;;) {
- prop = promGetProperty("name", &len);
- if (!prop || len <= 0)
- return 0;
- if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type)
- type = PROM_NODE_SBUS;
- else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI)
- type = PROM_NODE_EBUS;
- else if (!strcmp(prop, "pci") && !type)
- type = PROM_NODE_PCI;
- for (node = promGetChild(parent); node; node = promGetSibling(node)) {
- prop = promGetProperty("name", &len);
- if (!prop || len <= 0)
- continue;
- if (*name && strcmp(name, prop))
- continue;
- if (*regstr) {
- p = promGetReg(type);
- if (! *p || strcmp(p + 1, regstr))
- continue;
- }
- break;
- }
- if (!node) {
- for (node = promGetChild(parent); node; node = promGetSibling(node)) {
- ret = promWalkPathname2Node(name, regstr, node, type);
- if (ret) return ret;
- }
- return 0;
- }
- name = strchr(regstr, 0) + 1;
- if (! *name)
- return node;
- p = strchr(name, '/');
- if (p)
- *p = 0;
- else
- p = strchr(name, 0);
- regstr = strchr(name, '@');
- if (regstr)
- *regstr++ = 0;
- else
- regstr = p;
- if (name == regstr)
- return 0;
- parent = node;
- }
-}
-
-int
-sparcPromPathname2Node(const char *pathName)
-{
- int i;
- char *name, *regstr, *p;
-
- i = strlen(pathName);
- name = malloc(i + 2);
- if (! name) return 0;
- strcpy (name, pathName);
- name [i + 1] = 0;
- if (name[0] != '/')
- return 0;
- p = strchr(name + 1, '/');
- if (p)
- *p = 0;
- else
- p = strchr(name, 0);
- regstr = strchr(name, '@');
- if (regstr)
- *regstr++ = 0;
- else
- regstr = p;
- if (name + 1 == regstr)
- return 0;
- promGetSibling(0);
- i = promWalkPathname2Node(name + 1, regstr, promRootNode, 0);
- free(name);
- return i;
-}
-
-pointer
-xf86MapSbusMem(sbusDevicePtr psdp, unsigned long offset, unsigned long size)
-{
- pointer ret;
- unsigned long pagemask = getpagesize() - 1;
- unsigned long off = offset & ~pagemask;
- unsigned long len = ((offset + size + pagemask) & ~pagemask) - off;
-
- if (psdp->fd == -1) {
- psdp->fd = open(psdp->device, O_RDWR);
- if (psdp->fd == -1)
- return NULL;
- } else if (psdp->fd < 0)
- return NULL;
-
- ret = (pointer) mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE,
- psdp->fd, off);
- if (ret == (pointer) -1) {
- ret = (pointer) mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED,
- psdp->fd, off);
- }
- if (ret == (pointer) -1)
- return NULL;
-
- return (char *)ret + (offset - off);
-}
-
-void
-xf86UnmapSbusMem(sbusDevicePtr psdp, pointer addr, unsigned long size)
-{
- unsigned long mask = getpagesize() - 1;
- unsigned long base = (unsigned long)addr & ~mask;
- unsigned long len = (((unsigned long)addr + size + mask) & ~mask) - base;
-
- munmap ((pointer)base, len);
-}
-
-/* Tell OS that we are driving the HW cursor ourselves. */
-void
-xf86SbusHideOsHwCursor(sbusDevicePtr psdp)
-{
- struct fbcursor fbcursor;
- unsigned char zeros[8];
-
- memset(&fbcursor, 0, sizeof(fbcursor));
- memset(&zeros, 0, sizeof(zeros));
- fbcursor.cmap.count = 2;
- fbcursor.cmap.red = zeros;
- fbcursor.cmap.green = zeros;
- fbcursor.cmap.blue = zeros;
- fbcursor.image = (char *)zeros;
- fbcursor.mask = (char *)zeros;
- fbcursor.size.x = 32;
- fbcursor.size.y = 1;
- fbcursor.set = FB_CUR_SETALL;
- ioctl(psdp->fd, FBIOSCURSOR, &fbcursor);
-}
-
-/* Set HW cursor colormap. */
-void
-xf86SbusSetOsHwCursorCmap(sbusDevicePtr psdp, int bg, int fg)
-{
- struct fbcursor fbcursor;
- unsigned char red[2], green[2], blue[2];
-
- memset(&fbcursor, 0, sizeof(fbcursor));
- red[0] = bg >> 16;
- green[0] = bg >> 8;
- blue[0] = bg;
- red[1] = fg >> 16;
- green[1] = fg >> 8;
- blue[1] = fg;
- fbcursor.cmap.count = 2;
- fbcursor.cmap.red = red;
- fbcursor.cmap.green = green;
- fbcursor.cmap.blue = blue;
- fbcursor.set = FB_CUR_SETCMAP;
- ioctl(psdp->fd, FBIOSCURSOR, &fbcursor);
-}
+/* + * SBUS and OpenPROM access functions. + * + * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#ifdef sun +#include <sys/utsname.h> +#endif +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +#include "xf86sbusBus.h" +#include "xf86Sbus.h" + +int promRootNode; + +static int promFd = -1; +static int promCurrentNode; +static int promOpenCount = 0; +static int promP1275 = -1; +#define MAX_PROP 128 +#define MAX_VAL (4096-128-4) +static struct openpromio *promOpio; + +sbusDevicePtr *xf86SbusInfo = NULL; + +struct sbus_devtable sbusDeviceTable[] = { + { SBUS_DEVICE_BW2, FBTYPE_SUN2BW, "bwtwo", "sunbw2", "Sun Monochrome (bwtwo)" }, + { SBUS_DEVICE_CG2, FBTYPE_SUN2COLOR, "cgtwo", NULL, "Sun Color2 (cgtwo)" }, + { SBUS_DEVICE_CG3, FBTYPE_SUN3COLOR, "cgthree", "suncg3", "Sun Color3 (cgthree)" }, + { SBUS_DEVICE_CG4, FBTYPE_SUN4COLOR, "cgfour", NULL, "Sun Color4 (cgfour)" }, + { SBUS_DEVICE_CG6, FBTYPE_SUNFAST_COLOR, "cgsix", "suncg6", "Sun GX" }, + { SBUS_DEVICE_CG8, FBTYPE_MEMCOLOR, "cgeight", NULL, "Sun CG8/RasterOps" }, + { SBUS_DEVICE_CG12, FBTYPE_SUNGP3, "cgtwelve", NULL, "Sun GS (cgtwelve)" }, + { SBUS_DEVICE_CG14, FBTYPE_MDICOLOR, "cgfourteen", "suncg14", "Sun SX" }, + { SBUS_DEVICE_GT, FBTYPE_SUNGT, "gt", NULL, "Sun Graphics Tower" }, + { SBUS_DEVICE_MGX, -1, "mgx", NULL, "Quantum 3D MGXplus" }, + { SBUS_DEVICE_LEO, FBTYPE_SUNLEO, "leo", "sunleo", "Sun ZX or Turbo ZX" }, + { SBUS_DEVICE_TCX, FBTYPE_TCXCOLOR, "tcx", "suntcx", "Sun TCX" }, + { SBUS_DEVICE_FFB, FBTYPE_CREATOR, "ffb", "sunffb", "Sun FFB" }, + { SBUS_DEVICE_FFB, FBTYPE_CREATOR, "afb", "sunffb", "Sun Elite3D" }, + { 0, 0, NULL } +}; + +int +promGetSibling(int node) +{ + promOpio->oprom_size = sizeof(int); + + if (node == -1) return 0; + *(int *)promOpio->oprom_array = node; + if (ioctl(promFd, OPROMNEXT, promOpio) < 0) + return 0; + promCurrentNode = *(int *)promOpio->oprom_array; + return *(int *)promOpio->oprom_array; +} + +int +promGetChild(int node) +{ + promOpio->oprom_size = sizeof(int); + + if (!node || node == -1) return 0; + *(int *)promOpio->oprom_array = node; + if (ioctl(promFd, OPROMCHILD, promOpio) < 0) + return 0; + promCurrentNode = *(int *)promOpio->oprom_array; + return *(int *)promOpio->oprom_array; +} + +char * +promGetProperty(const char *prop, int *lenp) +{ + promOpio->oprom_size = MAX_VAL; + + strcpy(promOpio->oprom_array, prop); + if (ioctl(promFd, OPROMGETPROP, promOpio) < 0) + return 0; + if (lenp) *lenp = promOpio->oprom_size; + return promOpio->oprom_array; +} + +int +promGetBool(const char *prop) +{ + promOpio->oprom_size = 0; + + *(int *)promOpio->oprom_array = 0; + for (;;) { + promOpio->oprom_size = MAX_PROP; + if (ioctl(promFd, OPROMNXTPROP, promOpio) < 0) + return 0; + if (!promOpio->oprom_size) + return 0; + if (!strcmp(promOpio->oprom_array, prop)) + return 1; + } +} + +#define PROM_NODE_SIBLING 0x01 +#define PROM_NODE_PREF 0x02 +#define PROM_NODE_SBUS 0x04 +#define PROM_NODE_EBUS 0x08 +#define PROM_NODE_PCI 0x10 + +static int +promSetNode(sbusPromNodePtr pnode) +{ + int node; + + if (!pnode->node || pnode->node == -1) + return -1; + if (pnode->cookie[0] & PROM_NODE_SIBLING) + node = promGetSibling(pnode->cookie[1]); + else + node = promGetChild(pnode->cookie[1]); + if (pnode->node != node) + return -1; + return 0; +} + +static void +promIsP1275(void) +{ +#ifdef linux + FILE *f; + char buffer[1024]; + + if (promP1275 != -1) + return; + promP1275 = 0; + f = fopen("/proc/cpuinfo","r"); + if (!f) return; + while (fgets(buffer, 1024, f) != NULL) + if (!strncmp (buffer, "type", 4) && strstr (buffer, "sun4u")) { + promP1275 = 1; + break; + } + fclose(f); +#elif defined(sun) + struct utsname buffer; + + if ((uname(&buffer) >= 0) && !strcmp(buffer.machine, "sun4u")) + promP1275 = TRUE; + else + promP1275 = FALSE; +#elif defined(__FreeBSD__) + promP1275 = TRUE; +#else +#error Missing promIsP1275() function for this OS +#endif +} + +void +sparcPromClose(void) +{ + if (promOpenCount > 1) { + promOpenCount--; + return; + } + if (promFd != -1) { + close(promFd); + promFd = -1; + } + free(promOpio); + promOpio = NULL; + promOpenCount = 0; +} + +int +sparcPromInit(void) +{ + if (promOpenCount) { + promOpenCount++; + return 0; + } + promFd = open("/dev/openprom", O_RDONLY, 0); + if (promFd == -1) + return -1; + promOpio = (struct openpromio *)malloc(4096); + if (!promOpio) { + sparcPromClose(); + return -1; + } + promRootNode = promGetSibling(0); + if (!promRootNode) { + sparcPromClose(); + return -1; + } + promIsP1275(); + promOpenCount++; + + return 0; +} + +char * +sparcPromGetProperty(sbusPromNodePtr pnode, const char *prop, int *lenp) +{ + if (promSetNode(pnode)) + return NULL; + return promGetProperty(prop, lenp); +} + +int +sparcPromGetBool(sbusPromNodePtr pnode, const char *prop) +{ + if (promSetNode(pnode)) + return 0; + return promGetBool(prop); +} + +static char * +promWalkGetDriverName(int node, int oldnode) +{ + int nextnode; + int len; + char *prop; + int devId, i; + + prop = promGetProperty("device_type", &len); + if (prop && (len > 0)) do { + if (!strcmp(prop, "display")) { + prop = promGetProperty("name", &len); + if (!prop || len <= 0) + break; + while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',') + prop++; + for (i = 0; sbusDeviceTable[i].devId; i++) + if (!strcmp(prop, sbusDeviceTable[i].promName)) + break; + devId = sbusDeviceTable[i].devId; + if (!devId) + break; + if (sbusDeviceTable[i].driverName) + return sbusDeviceTable[i].driverName; + } + } while (0); + + nextnode = promGetChild(node); + if (nextnode) { + char *name; + name = promWalkGetDriverName(nextnode, node); + if (name) + return name; + } + + nextnode = promGetSibling(node); + if (nextnode) + return promWalkGetDriverName(nextnode, node); + return NULL; +} + +char * +sparcDriverName(void) +{ + char *name; + + if (sparcPromInit() < 0) + return NULL; + promGetSibling(0); + name = promWalkGetDriverName(promRootNode, 0); + sparcPromClose(); + return name; +} + +static void +promWalkAssignNodes(int node, int oldnode, int flags, sbusDevicePtr *devicePtrs) +{ + int nextnode; + int len, sbus = flags & PROM_NODE_SBUS; + char *prop; + int devId, i, j; + sbusPromNode pNode, pNode2; + + prop = promGetProperty("device_type", &len); + if (prop && (len > 0)) do { + if (!strcmp(prop, "display")) { + prop = promGetProperty("name", &len); + if (!prop || len <= 0) + break; + while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',') + prop++; + for (i = 0; sbusDeviceTable[i].devId; i++) + if (!strcmp(prop, sbusDeviceTable[i].promName)) + break; + devId = sbusDeviceTable[i].devId; + if (!devId) + break; + if (!sbus) { + if (devId == SBUS_DEVICE_FFB) { + /* + * All /SUNW,ffb outside of SBUS tree come before all + * /SUNW,afb outside of SBUS tree in Linux. + */ + if (!strcmp(prop, "afb")) + flags |= PROM_NODE_PREF; + } else if (devId != SBUS_DEVICE_CG14) + break; + } + for (i = 0; i < 32; i++) { + if (!devicePtrs[i] || devicePtrs[i]->devId != devId) + continue; + if (devicePtrs[i]->node.node) { + if ((devicePtrs[i]->node.cookie[0] & ~PROM_NODE_SIBLING) <= + (flags & ~PROM_NODE_SIBLING)) + continue; + for (j = i + 1, pNode = devicePtrs[i]->node; j < 32; j++) { + if (!devicePtrs[j] || devicePtrs[j]->devId != devId) + continue; + pNode2 = devicePtrs[j]->node; + devicePtrs[j]->node = pNode; + pNode = pNode2; + } + } + devicePtrs[i]->node.node = node; + devicePtrs[i]->node.cookie[0] = flags; + devicePtrs[i]->node.cookie[1] = oldnode; + break; + } + break; + } + } while (0); + + prop = promGetProperty("name", &len); + if (prop && len > 0) { + if (!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) + sbus = PROM_NODE_SBUS; + } + + nextnode = promGetChild(node); + if (nextnode) + promWalkAssignNodes(nextnode, node, sbus, devicePtrs); + + nextnode = promGetSibling(node); + if (nextnode) + promWalkAssignNodes(nextnode, node, PROM_NODE_SIBLING | sbus, devicePtrs); +} + +void +sparcPromAssignNodes(void) +{ + sbusDevicePtr psdp, *psdpp; + int n, holes = 0, i, j; + FILE *f; + sbusDevicePtr devicePtrs[32]; + + memset(devicePtrs, 0, sizeof(devicePtrs)); + for (psdpp = xf86SbusInfo, n = 0; (psdp = *psdpp); psdpp++, n++) { + if (psdp->fbNum != n) + holes = 1; + devicePtrs[psdp->fbNum] = psdp; + } + if (holes && (f = fopen("/proc/fb", "r")) != NULL) { + /* We could not open one of fb devices, check /proc/fb to see what + * were the types of the cards missed. */ + char buffer[64]; + int fbNum, devId; + static struct { + int devId; + char *prefix; + } procFbPrefixes[] = { + { SBUS_DEVICE_BW2, "BWtwo" }, + { SBUS_DEVICE_CG14, "CGfourteen" }, + { SBUS_DEVICE_CG6, "CGsix" }, + { SBUS_DEVICE_CG3, "CGthree" }, + { SBUS_DEVICE_FFB, "Creator" }, + { SBUS_DEVICE_FFB, "Elite 3D" }, + { SBUS_DEVICE_LEO, "Leo" }, + { SBUS_DEVICE_TCX, "TCX" }, + { 0, NULL }, + }; + + while (fscanf(f, "%d %63s\n", &fbNum, buffer) == 2) { + for (i = 0; procFbPrefixes[i].devId; i++) + if (! strncmp(procFbPrefixes[i].prefix, buffer, + strlen(procFbPrefixes[i].prefix))) + break; + devId = procFbPrefixes[i].devId; + if (! devId) continue; + if (devicePtrs[fbNum]) { + if (devicePtrs[fbNum]->devId != devId) + xf86ErrorF("Inconsistent /proc/fb with FBIOGATTR\n"); + } else if (!devicePtrs[fbNum]) { + devicePtrs[fbNum] = psdp = xnfcalloc(sizeof (sbusDevice), 1); + psdp->devId = devId; + psdp->fbNum = fbNum; + psdp->fd = -2; + } + } + fclose(f); + } + promGetSibling(0); + promWalkAssignNodes(promRootNode, 0, PROM_NODE_PREF, devicePtrs); + for (i = 0, j = 0; i < 32; i++) + if (devicePtrs[i] && devicePtrs[i]->fbNum == -1) + j++; + xf86SbusInfo = xnfrealloc(xf86SbusInfo, sizeof(psdp) * (n + j + 1)); + for (i = 0, psdpp = xf86SbusInfo; i < 32; i++) + if (devicePtrs[i]) { + if (devicePtrs[i]->fbNum == -1) { + memmove(psdpp + 1, psdpp, sizeof(psdpp) * (n + 1)); + *psdpp = devicePtrs[i]; + } else + n--; + } +} + +static char * +promGetReg(int type) +{ + char *prop; + int len; + static char regstr[40]; + + regstr[0] = 0; + prop = promGetProperty("reg", &len); + if (prop && len >= 4) { + unsigned int *reg = (unsigned int *)prop; + if (!promP1275 || (type == PROM_NODE_SBUS) || (type == PROM_NODE_EBUS)) + snprintf (regstr, sizeof(regstr), "@%x,%x", reg[0], reg[1]); + else if (type == PROM_NODE_PCI) { + if ((reg[0] >> 8) & 7) + snprintf (regstr, sizeof(regstr), "@%x,%x", (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7); + else + snprintf (regstr, sizeof(regstr), "@%x", (reg[0] >> 11) & 0x1f); + } else if (len == 4) + snprintf (regstr, sizeof(regstr), "@%x", reg[0]); + else { + unsigned int regs[2]; + + /* Things get more complicated on UPA. If upa-portid exists, + then address is @upa-portid,second-int-in-reg, otherwise + it is @first-int-in-reg/16,second-int-in-reg (well, probably + upa-portid always exists, but just to be safe). */ + memcpy (regs, reg, sizeof(regs)); + prop = promGetProperty("upa-portid", &len); + if (prop && len == 4) { + reg = (unsigned int *)prop; + snprintf (regstr, sizeof(regstr), "@%x,%x", reg[0], regs[1]); + } else + snprintf (regstr, sizeof(regstr), "@%x,%x", regs[0] >> 4, regs[1]); + } + } + return regstr; +} + +static int +promWalkNode2Pathname(char *path, int parent, int node, int searchNode, int type) +{ + int nextnode; + int len, ntype = type; + char *prop, *p; + + prop = promGetProperty("name", &len); + *path = '/'; + if (!prop || len <= 0) + return 0; + if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type) + ntype = PROM_NODE_SBUS; + else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI) + ntype = PROM_NODE_EBUS; + else if (!strcmp(prop, "pci") && !type) + ntype = PROM_NODE_PCI; + strcpy (path + 1, prop); + p = promGetReg(type); + if (*p) + strcat (path, p); + if (node == searchNode) + return 1; + nextnode = promGetChild(node); + if (nextnode && + promWalkNode2Pathname(strchr(path, 0), node, nextnode, searchNode, ntype)) + return 1; + nextnode = promGetSibling(node); + if (nextnode && + promWalkNode2Pathname(path, parent, nextnode, searchNode, type)) + return 1; + return 0; +} + +char * +sparcPromNode2Pathname(sbusPromNodePtr pnode) +{ + char *ret; + + if (!pnode->node) return NULL; + ret = malloc(4096); + if (!ret) return NULL; + if (promWalkNode2Pathname(ret, promRootNode, promGetChild(promRootNode), pnode->node, 0)) + return ret; + free(ret); + return NULL; +} + +static int +promWalkPathname2Node(char *name, char *regstr, int parent, int type) +{ + int len, node, ret; + char *prop, *p; + + for (;;) { + prop = promGetProperty("name", &len); + if (!prop || len <= 0) + return 0; + if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type) + type = PROM_NODE_SBUS; + else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI) + type = PROM_NODE_EBUS; + else if (!strcmp(prop, "pci") && !type) + type = PROM_NODE_PCI; + for (node = promGetChild(parent); node; node = promGetSibling(node)) { + prop = promGetProperty("name", &len); + if (!prop || len <= 0) + continue; + if (*name && strcmp(name, prop)) + continue; + if (*regstr) { + p = promGetReg(type); + if (! *p || strcmp(p + 1, regstr)) + continue; + } + break; + } + if (!node) { + for (node = promGetChild(parent); node; node = promGetSibling(node)) { + ret = promWalkPathname2Node(name, regstr, node, type); + if (ret) return ret; + } + return 0; + } + name = strchr(regstr, 0) + 1; + if (! *name) + return node; + p = strchr(name, '/'); + if (p) + *p = 0; + else + p = strchr(name, 0); + regstr = strchr(name, '@'); + if (regstr) + *regstr++ = 0; + else + regstr = p; + if (name == regstr) + return 0; + parent = node; + } +} + +int +sparcPromPathname2Node(const char *pathName) +{ + int i; + char *name, *regstr, *p; + + i = strlen(pathName); + name = malloc(i + 2); + if (! name) return 0; + strcpy (name, pathName); + name [i + 1] = 0; + if (name[0] != '/') + return 0; + p = strchr(name + 1, '/'); + if (p) + *p = 0; + else + p = strchr(name, 0); + regstr = strchr(name, '@'); + if (regstr) + *regstr++ = 0; + else + regstr = p; + if (name + 1 == regstr) + return 0; + promGetSibling(0); + i = promWalkPathname2Node(name + 1, regstr, promRootNode, 0); + free(name); + return i; +} + +pointer +xf86MapSbusMem(sbusDevicePtr psdp, unsigned long offset, unsigned long size) +{ + pointer ret; + unsigned long pagemask = getpagesize() - 1; + unsigned long off = offset & ~pagemask; + unsigned long len = ((offset + size + pagemask) & ~pagemask) - off; + + if (psdp->fd == -1) { + psdp->fd = open(psdp->device, O_RDWR); + if (psdp->fd == -1) + return NULL; + } else if (psdp->fd < 0) + return NULL; + + ret = (pointer) mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, + psdp->fd, off); + if (ret == (pointer) -1) { + ret = (pointer) mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, + psdp->fd, off); + } + if (ret == (pointer) -1) + return NULL; + + return (char *)ret + (offset - off); +} + +void +xf86UnmapSbusMem(sbusDevicePtr psdp, pointer addr, unsigned long size) +{ + unsigned long mask = getpagesize() - 1; + unsigned long base = (unsigned long)addr & ~mask; + unsigned long len = (((unsigned long)addr + size + mask) & ~mask) - base; + + munmap ((pointer)base, len); +} + +/* Tell OS that we are driving the HW cursor ourselves. */ +void +xf86SbusHideOsHwCursor(sbusDevicePtr psdp) +{ + struct fbcursor fbcursor; + unsigned char zeros[8]; + + memset(&fbcursor, 0, sizeof(fbcursor)); + memset(&zeros, 0, sizeof(zeros)); + fbcursor.cmap.count = 2; + fbcursor.cmap.red = zeros; + fbcursor.cmap.green = zeros; + fbcursor.cmap.blue = zeros; + fbcursor.image = (char *)zeros; + fbcursor.mask = (char *)zeros; + fbcursor.size.x = 32; + fbcursor.size.y = 1; + fbcursor.set = FB_CUR_SETALL; + ioctl(psdp->fd, FBIOSCURSOR, &fbcursor); +} + +/* Set HW cursor colormap. */ +void +xf86SbusSetOsHwCursorCmap(sbusDevicePtr psdp, int bg, int fg) +{ + struct fbcursor fbcursor; + unsigned char red[2], green[2], blue[2]; + + memset(&fbcursor, 0, sizeof(fbcursor)); + red[0] = bg >> 16; + green[0] = bg >> 8; + blue[0] = bg; + red[1] = fg >> 16; + green[1] = fg >> 8; + blue[1] = fg; + fbcursor.cmap.count = 2; + fbcursor.cmap.red = red; + fbcursor.cmap.green = green; + fbcursor.cmap.blue = blue; + fbcursor.set = FB_CUR_SETCMAP; + ioctl(psdp->fd, FBIOSCURSOR, &fbcursor); +} diff --git a/xorg-server/hw/xfree86/os-support/linux/lnx_init.c b/xorg-server/hw/xfree86/os-support/linux/lnx_init.c index f18271f38..5f3e3a9fb 100644 --- a/xorg-server/hw/xfree86/os-support/linux/lnx_init.c +++ b/xorg-server/hw/xfree86/os-support/linux/lnx_init.c @@ -146,7 +146,7 @@ xf86OpenConsole(void) i=0; while (vcs[i] != NULL) { - sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ + snprintf(vtname, sizeof(vtname), vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) >= 0) break; i++; diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_agp.c b/xorg-server/hw/xfree86/os-support/solaris/sun_agp.c index 0331ac1c5..8c4e9f5c1 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_agp.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_agp.c @@ -233,7 +233,7 @@ xf86DeallocateGARTMemory(int screenNum, int key) if (!GARTInit(screenNum) || (acquiredScreen != screenNum)) return FALSE; - if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *)key) != 0) { + if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *)(uintptr_t)key) != 0) { xf86DrvMsg(screenNum, X_WARNING, "xf86DeAllocateGARTMemory: " "deallocation of gart memory with key %d failed\n" "\t(%s)\n", key, strerror(errno)); diff --git a/xorg-server/hw/xfree86/parser/Flags.c b/xorg-server/hw/xfree86/parser/Flags.c index f0a61707b..87fd3edf6 100644 --- a/xorg-server/hw/xfree86/parser/Flags.c +++ b/xorg-server/hw/xfree86/parser/Flags.c @@ -330,7 +330,7 @@ xf86findOption (XF86OptionPtr list, const char *name) * returned. If the option is not found, a NULL is returned. */ -char * +const char * xf86findOptionValue (XF86OptionPtr list, const char *name) { XF86OptionPtr p = xf86findOption (list, name); diff --git a/xorg-server/hw/xfree86/parser/InputClass.c b/xorg-server/hw/xfree86/parser/InputClass.c index 3f801700e..2cdc9125a 100644 --- a/xorg-server/hw/xfree86/parser/InputClass.c +++ b/xorg-server/hw/xfree86/parser/InputClass.c @@ -128,60 +128,70 @@ xf86parseInputClassSection(void) Error(QUOTE_MSG, "MatchProduct"); add_group_entry(&ptr->match_product, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_VENDOR: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchVendor"); add_group_entry(&ptr->match_vendor, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_DEVICE_PATH: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchDevicePath"); add_group_entry(&ptr->match_device, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_OS: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchOS"); add_group_entry(&ptr->match_os, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_PNPID: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchPnPID"); add_group_entry(&ptr->match_pnpid, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_USBID: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchUSBID"); add_group_entry(&ptr->match_usbid, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_DRIVER: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchDriver"); add_group_entry(&ptr->match_driver, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_TAG: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchTag"); add_group_entry(&ptr->match_tag, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_LAYOUT: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchLayout"); add_group_entry(&ptr->match_layout, xstrtokenize(val.str, TOKEN_SEP)); + free(val.str); break; case MATCH_IS_KEYBOARD: if (xf86getSubToken(&(ptr->comment)) != STRING) Error(QUOTE_MSG, "MatchIsKeyboard"); ptr->is_keyboard.set = xf86getBoolValue(&ptr->is_keyboard.val, val.str); + free(val.str); if (!ptr->is_keyboard.set) Error(BOOL_MSG, "MatchIsKeyboard"); break; @@ -190,6 +200,7 @@ xf86parseInputClassSection(void) Error(QUOTE_MSG, "MatchIsPointer"); ptr->is_pointer.set = xf86getBoolValue(&ptr->is_pointer.val, val.str); + free(val.str); if (!ptr->is_pointer.set) Error(BOOL_MSG, "MatchIsPointer"); break; @@ -198,6 +209,7 @@ xf86parseInputClassSection(void) Error(QUOTE_MSG, "MatchIsJoystick"); ptr->is_joystick.set = xf86getBoolValue(&ptr->is_joystick.val, val.str); + free(val.str); if (!ptr->is_joystick.set) Error(BOOL_MSG, "MatchIsJoystick"); break; @@ -206,6 +218,7 @@ xf86parseInputClassSection(void) Error(QUOTE_MSG, "MatchIsTablet"); ptr->is_tablet.set = xf86getBoolValue(&ptr->is_tablet.val, val.str); + free(val.str); if (!ptr->is_tablet.set) Error(BOOL_MSG, "MatchIsTablet"); break; @@ -214,6 +227,7 @@ xf86parseInputClassSection(void) Error(QUOTE_MSG, "MatchIsTouchpad"); ptr->is_touchpad.set = xf86getBoolValue(&ptr->is_touchpad.val, val.str); + free(val.str); if (!ptr->is_touchpad.set) Error(BOOL_MSG, "MatchIsTouchpad"); break; @@ -222,6 +236,7 @@ xf86parseInputClassSection(void) Error(QUOTE_MSG, "MatchIsTouchscreen"); ptr->is_touchscreen.set = xf86getBoolValue(&ptr->is_touchscreen.val, val.str); + free(val.str); if (!ptr->is_touchscreen.set) Error(BOOL_MSG, "MatchIsTouchscreen"); break; diff --git a/xorg-server/hw/xfree86/parser/configProcs.h b/xorg-server/hw/xfree86/parser/configProcs.h index 7d8a8e53a..114cdfe33 100644 --- a/xorg-server/hw/xfree86/parser/configProcs.h +++ b/xorg-server/hw/xfree86/parser/configProcs.h @@ -95,9 +95,9 @@ int xf86getSubToken(char **comment); int xf86getSubTokenWithTab(char **comment, xf86ConfigSymTabRec *tab); void xf86unGetToken(int token); char *xf86tokenString(void); -void xf86parseError(char *format, ...); -void xf86validationError(char *format, ...); -void xf86setSection(char *section); +void xf86parseError(const char *format, ...); +void xf86validationError(const char *format, ...); +void xf86setSection(const char *section); int xf86getStringToken(xf86ConfigSymTabRec *tab); /* write.c */ /* DRI.c */ diff --git a/xorg-server/hw/xfree86/parser/scan.c b/xorg-server/hw/xfree86/parser/scan.c index 99b325717..9099227bb 100644 --- a/xorg-server/hw/xfree86/parser/scan.c +++ b/xorg-server/hw/xfree86/parser/scan.c @@ -90,7 +90,7 @@ #define CONFIG_BUF_LEN 1024 #define CONFIG_MAX_FILES 64 -static int StringToToken (char *, xf86ConfigSymTabRec *); +static int StringToToken (const char *, xf86ConfigSymTabRec *); static struct { FILE *file; @@ -101,8 +101,6 @@ static int builtinIndex = 0; static int configPos = 0; /* current readers position */ static int configLineNo = 0; /* linenumber */ static char *configBuf, *configRBuf; /* buffer for lines */ -static char *configPath; /* path to config file */ -static char *configDirPath; /* path to config dir */ static char *configSection = NULL; /* name of current section being parsed */ static int numFiles = 0; /* number of config files */ static int curFileIndex = 0; /* index of current config file */ @@ -281,8 +279,10 @@ again: if (builtinConfig[builtinIndex] == NULL) ret = NULL; else { - ret = strncpy(configBuf, builtinConfig[builtinIndex], - CONFIG_BUF_LEN); + strlcpy(configBuf, + builtinConfig[builtinIndex], + CONFIG_BUF_LEN); + ret = configBuf; builtinIndex++; } } @@ -800,14 +800,12 @@ AddConfigDirFiles(const char *dirpath, struct dirent **list, int num) "files opened\n"); warnOnce = TRUE; } - free(list[i]); continue; } path = malloc(PATH_MAX + 1); snprintf(path, PATH_MAX + 1, "%s/%s", dirpath, list[i]->d_name); - free(list[i]); file = fopen(path, "r"); if (!file) { free(path); @@ -858,8 +856,10 @@ OpenConfigDir(const char *path, const char *cmdline, const char *projroot, if (!found) { free(dirpath); dirpath = NULL; - free(list); } + while (num--) + free(list[num]); + free(list); } free(pathcopy); @@ -892,7 +892,8 @@ xf86initConfigFiles(void) * of the located files. * * The return value is a pointer to the actual name of the file that was - * opened. When no file is found, the return value is NULL. + * opened. When no file is found, the return value is NULL. The caller should + * free() the returned value. * * The escape sequences allowed in the search path are defined above. * @@ -914,7 +915,7 @@ xf86initConfigFiles(void) "%P/lib/X11/%X" #endif -const char * +char * xf86openConfigFile(const char *path, const char *cmdline, const char *projroot) { if (!path || !path[0]) @@ -923,8 +924,7 @@ xf86openConfigFile(const char *path, const char *cmdline, const char *projroot) projroot = PROJECTROOT; /* Search for a config file */ - configPath = OpenConfigFile(path, cmdline, projroot, XCONFIGFILE); - return configPath; + return OpenConfigFile(path, cmdline, projroot, XCONFIGFILE); } /* @@ -937,12 +937,13 @@ xf86openConfigFile(const char *path, const char *cmdline, const char *projroot) * fails if it is not found. * * The return value is a pointer to the actual name of the direcoty that was - * opened. When no directory is found, the return value is NULL. + * opened. When no directory is found, the return value is NULL. The caller + * should free() the returned value. * * The escape sequences allowed in the search path are defined above. * */ -const char * +char * xf86openConfigDirFiles(const char *path, const char *cmdline, const char *projroot) { @@ -952,8 +953,7 @@ xf86openConfigDirFiles(const char *path, const char *cmdline, projroot = PROJECTROOT; /* Search for the multiconf directory */ - configDirPath = OpenConfigDir(path, cmdline, projroot, XCONFIGDIR); - return configDirPath; + return OpenConfigDir(path, cmdline, projroot, XCONFIGDIR); } void @@ -961,10 +961,6 @@ xf86closeConfigFile (void) { int i; - free (configPath); - configPath = NULL; - free (configDirPath); - configDirPath = NULL; free (configRBuf); configRBuf = NULL; free (configBuf); @@ -990,11 +986,11 @@ xf86setBuiltinConfig(const char *config[]) } void -xf86parseError (char *format,...) +xf86parseError (const char *format,...) { va_list ap; - char *filename = numFiles ? configFiles[curFileIndex].path : - "<builtin configuration>"; + const char *filename = numFiles ? configFiles[curFileIndex].path + : "<builtin configuration>"; ErrorF ("Parse error on line %d of section %s in file %s\n\t", configLineNo, configSection, filename); @@ -1006,11 +1002,11 @@ xf86parseError (char *format,...) } void -xf86validationError (char *format,...) +xf86validationError (const char *format,...) { va_list ap; - char *filename = numFiles ? configFiles[curFileIndex].path : - "<builtin configuration>"; + const char *filename = numFiles ? configFiles[curFileIndex].path + : "<builtin configuration>"; ErrorF ("Data incomplete in file %s\n\t", filename); va_start (ap, format); @@ -1021,7 +1017,7 @@ xf86validationError (char *format,...) } void -xf86setSection (char *section) +xf86setSection (const char *section) { free(configSection); configSection = strdup(section); @@ -1038,7 +1034,7 @@ xf86getStringToken (xf86ConfigSymTabRec * tab) } static int -StringToToken (char *str, xf86ConfigSymTabRec * tab) +StringToToken (const char *str, xf86ConfigSymTabRec * tab) { int i; diff --git a/xorg-server/hw/xfree86/parser/xf86Optrec.h b/xorg-server/hw/xfree86/parser/xf86Optrec.h index 61a8c5ff5..b8e9d6192 100644 --- a/xorg-server/hw/xfree86/parser/xf86Optrec.h +++ b/xorg-server/hw/xfree86/parser/xf86Optrec.h @@ -77,7 +77,7 @@ extern _X_EXPORT char *xf86optionValue(XF86OptionPtr opt); extern _X_EXPORT XF86OptionPtr xf86newOption(char *name, char *value); extern _X_EXPORT XF86OptionPtr xf86nextOption(XF86OptionPtr list); extern _X_EXPORT XF86OptionPtr xf86findOption(XF86OptionPtr list, const char *name); -extern _X_EXPORT char *xf86findOptionValue(XF86OptionPtr list, const char *name); +extern _X_EXPORT const char *xf86findOptionValue(XF86OptionPtr list, const char *name); extern _X_EXPORT XF86OptionPtr xf86optionListCreate(const char **options, int count, int used); extern _X_EXPORT XF86OptionPtr xf86optionListMerge(XF86OptionPtr head, XF86OptionPtr tail); extern _X_EXPORT int xf86nameCompare (const char *s1, const char *s2); diff --git a/xorg-server/hw/xfree86/parser/xf86Parser.h b/xorg-server/hw/xfree86/parser/xf86Parser.h index a8785c5fa..7d4662b98 100644 --- a/xorg-server/hw/xfree86/parser/xf86Parser.h +++ b/xorg-server/hw/xfree86/parser/xf86Parser.h @@ -479,7 +479,7 @@ XF86ConfigRec, *XF86ConfigPtr; typedef struct { int token; /* id of the token */ - char *name; /* pointer to the LOWERCASED name */ + const char *name; /* pointer to the LOWERCASED name */ } xf86ConfigSymTabRec, *xf86ConfigSymTabPtr; @@ -487,10 +487,10 @@ xf86ConfigSymTabRec, *xf86ConfigSymTabPtr; * prototypes for public functions */ extern void xf86initConfigFiles(void); -extern const char *xf86openConfigFile(const char *path, const char *cmdline, - const char *projroot); -extern const char *xf86openConfigDirFiles(const char *path, const char *cmdline, - const char *projroot); +extern char *xf86openConfigFile(const char *path, const char *cmdline, + const char *projroot); +extern char *xf86openConfigDirFiles(const char *path, const char *cmdline, + const char *projroot); extern void xf86setBuiltinConfig(const char *config[]); extern XF86ConfigPtr xf86readConfigFile(void); extern void xf86closeConfigFile(void); diff --git a/xorg-server/hw/xfree86/ramdac/BTPriv.h b/xorg-server/hw/xfree86/ramdac/BTPriv.h index 184b4811c..52737768f 100644 --- a/xorg-server/hw/xfree86/ramdac/BTPriv.h +++ b/xorg-server/hw/xfree86/ramdac/BTPriv.h @@ -6,7 +6,7 @@ #include "BT.h" typedef struct { - char *DeviceName; + const char *DeviceName; } xf86BTramdacInfo; extern xf86BTramdacInfo BTramdacDeviceInfo[]; diff --git a/xorg-server/hw/xfree86/ramdac/IBMPriv.h b/xorg-server/hw/xfree86/ramdac/IBMPriv.h index a33da9106..309a193ad 100644 --- a/xorg-server/hw/xfree86/ramdac/IBMPriv.h +++ b/xorg-server/hw/xfree86/ramdac/IBMPriv.h @@ -6,7 +6,7 @@ #include "IBM.h" typedef struct { - char *DeviceName; + const char *DeviceName; } xf86IBMramdacInfo; extern xf86IBMramdacInfo IBMramdacDeviceInfo[]; diff --git a/xorg-server/hw/xfree86/ramdac/TIPriv.h b/xorg-server/hw/xfree86/ramdac/TIPriv.h index 191c9b5ce..20e07f5cc 100644 --- a/xorg-server/hw/xfree86/ramdac/TIPriv.h +++ b/xorg-server/hw/xfree86/ramdac/TIPriv.h @@ -6,7 +6,7 @@ #include "TI.h" typedef struct { - char *DeviceName; + const char *DeviceName; } xf86TIramdacInfo; extern xf86TIramdacInfo TIramdacDeviceInfo[]; diff --git a/xorg-server/hw/xfree86/utils/gtf/gtf.c b/xorg-server/hw/xfree86/utils/gtf/gtf.c index 840626c66..87fcb3f0e 100644 --- a/xorg-server/hw/xfree86/utils/gtf/gtf.c +++ b/xorg-server/hw/xfree86/utils/gtf/gtf.c @@ -1,741 +1,741 @@ -/* gtf.c Generate mode timings using the GTF Timing Standard
- *
- * gcc gtf.c -o gtf -lm -Wall
- *
- * Copyright (c) 2001, Andy Ritger aritger@nvidia.com
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * o Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * o Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * o Neither the name of NVIDIA nor the names of its contributors
- * may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- *
- *
- * This program is based on the Generalized Timing Formula(GTF TM)
- * Standard Version: 1.0, Revision: 1.0
- *
- * The GTF Document contains the following Copyright information:
- *
- * Copyright (c) 1994, 1995, 1996 - Video Electronics Standards
- * Association. Duplication of this document within VESA member
- * companies for review purposes is permitted. All other rights
- * reserved.
- *
- * While every precaution has been taken in the preparation
- * of this standard, the Video Electronics Standards Association and
- * its contributors assume no responsibility for errors or omissions,
- * and make no warranties, expressed or implied, of functionality
- * of suitability for any purpose. The sample code contained within
- * this standard may be used without restriction.
- *
- *
- *
- * The GTF EXCEL(TM) SPREADSHEET, a sample (and the definitive)
- * implementation of the GTF Timing Standard, is available at:
- *
- * ftp://ftp.vesa.org/pub/GTF/GTF_V1R1.xls
- *
- *
- *
- * This program takes a desired resolution and vertical refresh rate,
- * and computes mode timings according to the GTF Timing Standard.
- * These mode timings can then be formatted as an XServer modeline
- * or a mode description for use by fbset(8).
- *
- *
- *
- * NOTES:
- *
- * The GTF allows for computation of "margins" (the visible border
- * surrounding the addressable video); on most non-overscan type
- * systems, the margin period is zero. I've implemented the margin
- * computations but not enabled it because 1) I don't really have
- * any experience with this, and 2) neither XServer modelines nor
- * fbset fb.modes provide an obvious way for margin timings to be
- * included in their mode descriptions (needs more investigation).
- *
- * The GTF provides for computation of interlaced mode timings;
- * I've implemented the computations but not enabled them, yet.
- * I should probably enable and test this at some point.
- *
- *
- *
- * TODO:
- *
- * o Add support for interlaced modes.
- *
- * o Implement the other portions of the GTF: compute mode timings
- * given either the desired pixel clock or the desired horizontal
- * frequency.
- *
- * o It would be nice if this were more general purpose to do things
- * outside the scope of the GTF: like generate double scan mode
- * timings, for example.
- *
- * o Printing digits to the right of the decimal point when the
- * digits are 0 annoys me.
- *
- * o Error checking.
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-# include <xorg-config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#define MARGIN_PERCENT 1.8 /* % of active vertical image */
-#define CELL_GRAN 8.0 /* assumed character cell granularity */
-#define MIN_PORCH 1 /* minimum front porch */
-#define V_SYNC_RQD 3 /* width of vsync in lines */
-#define H_SYNC_PERCENT 8.0 /* width of hsync as % of total line */
-#define MIN_VSYNC_PLUS_BP 550.0 /* min time of vsync + back porch (microsec) */
-#define M 600.0 /* blanking formula gradient */
-#define C 40.0 /* blanking formula offset */
-#define K 128.0 /* blanking formula scaling factor */
-#define J 20.0 /* blanking formula scaling factor */
-
-/* C' and M' are part of the Blanking Duty Cycle computation */
-
-#define C_PRIME (((C - J) * K/256.0) + J)
-#define M_PRIME (K/256.0 * M)
-
-
-/* struct definitions */
-
-typedef struct __mode
-{
- int hr, hss, hse, hfl;
- int vr, vss, vse, vfl;
- float pclk, h_freq, v_freq;
-} mode;
-
-
-typedef struct __options
-{
- int x, y;
- int xorgmode, fbmode;
- float v_freq;
-} options;
-
-
-
-
-/* prototypes */
-
-void print_value(int n, char *name, float val);
-void print_xf86_mode (mode *m);
-void print_fb_mode (mode *m);
-mode *vert_refresh (int h_pixels, int v_lines, float freq,
- int interlaced, int margins);
-options *parse_command_line (int argc, char *argv[]);
-
-
-
-
-/*
- * print_value() - print the result of the named computation; this is
- * useful when comparing against the GTF EXCEL spreadsheet.
- */
-
-int global_verbose = 0;
-
-void print_value(int n, char *name, float val)
-{
- if (global_verbose) {
- printf("%2d: %-27s: %15f\n", n, name, val);
- }
-}
-
-
-
-/* print_xf86_mode() - print the XServer modeline, given mode timings. */
-
-void print_xf86_mode (mode *m)
-{
- printf ("\n");
- printf (" # %dx%d @ %.2f Hz (GTF) hsync: %.2f kHz; pclk: %.2f MHz\n",
- m->hr, m->vr, m->v_freq, m->h_freq, m->pclk);
-
- printf (" Modeline \"%dx%d_%.2f\" %.2f"
- " %d %d %d %d"
- " %d %d %d %d"
- " -HSync +Vsync\n\n",
- m->hr, m->vr, m->v_freq, m->pclk,
- m->hr, m->hss, m->hse, m->hfl,
- m->vr, m->vss, m->vse, m->vfl);
-
-}
-
-
-
-/*
- * print_fb_mode() - print a mode description in fbset(8) format;
- * see the fb.modes(8) manpage. The timing description used in
- * this is rather odd; they use "left and right margin" to refer
- * to the portion of the hblank before and after the sync pulse
- * by conceptually wrapping the portion of the blank after the pulse
- * to infront of the visible region; ie:
- *
- *
- * Timing description I'm accustomed to:
- *
- *
- *
- * <--------1--------> <--2--> <--3--> <--4-->
- * _________
- * |-------------------|_______| |_______
- *
- * R SS SE FL
- *
- * 1: visible image
- * 2: blank before sync (aka front porch)
- * 3: sync pulse
- * 4: blank after sync (aka back porch)
- * R: Resolution
- * SS: Sync Start
- * SE: Sync End
- * FL: Frame Length
- *
- *
- * But the fb.modes format is:
- *
- *
- * <--4--> <--------1--------> <--2--> <--3-->
- * _________
- * _______|-------------------|_______| |
- *
- * The fb.modes(8) manpage refers to <4> and <2> as the left and
- * right "margin" (as well as upper and lower margin in the vertical
- * direction) -- note that this has nothing to do with the term
- * "margin" used in the GTF Timing Standard.
- *
- * XXX always prints the 32 bit mode -- should I provide a command
- * line option to specify the bpp? It's simple enough for a user
- * to edit the mode description after it's generated.
- */
-
-void print_fb_mode (mode *m)
-{
- printf ("\n");
- printf ("mode \"%dx%d %.2fHz 32bit (GTF)\"\n",
- m->hr, m->vr, m->v_freq);
- printf (" # PCLK: %.2f MHz, H: %.2f kHz, V: %.2f Hz\n",
- m->pclk, m->h_freq, m->v_freq);
- printf (" geometry %d %d %d %d 32\n",
- m->hr, m->vr, m->hr, m->vr);
- printf (" timings %d %d %d %d %d %d %d\n",
- (int) rint(1000000.0/m->pclk),/* pixclock in picoseconds */
- m->hfl - m->hse, /* left margin (in pixels) */
- m->hss - m->hr, /* right margin (in pixels) */
- m->vfl - m->vse, /* upper margin (in pixel lines) */
- m->vss - m->vr, /* lower margin (in pixel lines) */
- m->hse - m->hss, /* horizontal sync length (pixels) */
- m->vse - m->vss); /* vert sync length (pixel lines) */
- printf (" hsync low\n");
- printf (" vsync high\n");
- printf ("endmode\n\n");
-
-}
-
-
-
-
-/*
- * vert_refresh() - as defined by the GTF Timing Standard, compute the
- * Stage 1 Parameters using the vertical refresh frequency. In other
- * words: input a desired resolution and desired refresh rate, and
- * output the GTF mode timings.
- *
- * XXX All the code is in place to compute interlaced modes, but I don't
- * feel like testing it right now.
- *
- * XXX margin computations are implemented but not tested (nor used by
- * XServer of fbset mode descriptions, from what I can tell).
- */
-
-mode *vert_refresh (int h_pixels, int v_lines, float freq,
- int interlaced, int margins)
-{
- float h_pixels_rnd;
- float v_lines_rnd;
- float v_field_rate_rqd;
- float top_margin;
- float bottom_margin;
- float interlace;
- float h_period_est;
- float vsync_plus_bp;
- float v_back_porch;
- float total_v_lines;
- float v_field_rate_est;
- float h_period;
- float v_field_rate;
- float v_frame_rate;
- float left_margin;
- float right_margin;
- float total_active_pixels;
- float ideal_duty_cycle;
- float h_blank;
- float total_pixels;
- float pixel_freq;
- float h_freq;
-
- float h_sync;
- float h_front_porch;
- float v_odd_front_porch_lines;
-
- mode *m = (mode*) malloc (sizeof (mode));
-
-
- /* 1. In order to give correct results, the number of horizontal
- * pixels requested is first processed to ensure that it is divisible
- * by the character size, by rounding it to the nearest character
- * cell boundary:
- *
- * [H PIXELS RND] = ((ROUND([H PIXELS]/[CELL GRAN RND],0))*[CELLGRAN RND])
- */
-
- h_pixels_rnd = rint((float) h_pixels / CELL_GRAN) * CELL_GRAN;
-
- print_value(1, "[H PIXELS RND]", h_pixels_rnd);
-
-
- /* 2. If interlace is requested, the number of vertical lines assumed
- * by the calculation must be halved, as the computation calculates
- * the number of vertical lines per field. In either case, the
- * number of lines is rounded to the nearest integer.
- *
- * [V LINES RND] = IF([INT RQD?]="y", ROUND([V LINES]/2,0),
- * ROUND([V LINES],0))
- */
-
- v_lines_rnd = interlaced ?
- rint((float) v_lines) / 2.0 :
- rint((float) v_lines);
-
- print_value(2, "[V LINES RND]", v_lines_rnd);
-
-
- /* 3. Find the frame rate required:
- *
- * [V FIELD RATE RQD] = IF([INT RQD?]="y", [I/P FREQ RQD]*2,
- * [I/P FREQ RQD])
- */
-
- v_field_rate_rqd = interlaced ? (freq * 2.0) : (freq);
-
- print_value(3, "[V FIELD RATE RQD]", v_field_rate_rqd);
-
-
- /* 4. Find number of lines in Top margin:
- *
- * [TOP MARGIN (LINES)] = IF([MARGINS RQD?]="Y",
- * ROUND(([MARGIN%]/100*[V LINES RND]),0),
- * 0)
- */
-
- top_margin = margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0);
-
- print_value(4, "[TOP MARGIN (LINES)]", top_margin);
-
-
- /* 5. Find number of lines in Bottom margin:
- *
- * [BOT MARGIN (LINES)] = IF([MARGINS RQD?]="Y",
- * ROUND(([MARGIN%]/100*[V LINES RND]),0),
- * 0)
- */
-
- bottom_margin = margins ? rint(MARGIN_PERCENT/100.0 * v_lines_rnd) : (0.0);
-
- print_value(5, "[BOT MARGIN (LINES)]", bottom_margin);
-
-
- /* 6. If interlace is required, then set variable [INTERLACE]=0.5:
- *
- * [INTERLACE]=(IF([INT RQD?]="y",0.5,0))
- */
-
- interlace = interlaced ? 0.5 : 0.0;
-
- print_value(6, "[INTERLACE]", interlace);
-
-
- /* 7. Estimate the Horizontal period
- *
- * [H PERIOD EST] = ((1/[V FIELD RATE RQD]) - [MIN VSYNC+BP]/1000000) /
- * ([V LINES RND] + (2*[TOP MARGIN (LINES)]) +
- * [MIN PORCH RND]+[INTERLACE]) * 1000000
- */
-
- h_period_est = (((1.0/v_field_rate_rqd) - (MIN_VSYNC_PLUS_BP/1000000.0))
- / (v_lines_rnd + (2*top_margin) + MIN_PORCH + interlace)
- * 1000000.0);
-
- print_value(7, "[H PERIOD EST]", h_period_est);
-
-
- /* 8. Find the number of lines in V sync + back porch:
- *
- * [V SYNC+BP] = ROUND(([MIN VSYNC+BP]/[H PERIOD EST]),0)
- */
-
- vsync_plus_bp = rint(MIN_VSYNC_PLUS_BP/h_period_est);
-
- print_value(8, "[V SYNC+BP]", vsync_plus_bp);
-
-
- /* 9. Find the number of lines in V back porch alone:
- *
- * [V BACK PORCH] = [V SYNC+BP] - [V SYNC RND]
- *
- * XXX is "[V SYNC RND]" a typo? should be [V SYNC RQD]?
- */
-
- v_back_porch = vsync_plus_bp - V_SYNC_RQD;
-
- print_value(9, "[V BACK PORCH]", v_back_porch);
-
-
- /* 10. Find the total number of lines in Vertical field period:
- *
- * [TOTAL V LINES] = [V LINES RND] + [TOP MARGIN (LINES)] +
- * [BOT MARGIN (LINES)] + [V SYNC+BP] + [INTERLACE] +
- * [MIN PORCH RND]
- */
-
- total_v_lines = v_lines_rnd + top_margin + bottom_margin + vsync_plus_bp +
- interlace + MIN_PORCH;
-
- print_value(10, "[TOTAL V LINES]", total_v_lines);
-
-
- /* 11. Estimate the Vertical field frequency:
- *
- * [V FIELD RATE EST] = 1 / [H PERIOD EST] / [TOTAL V LINES] * 1000000
- */
-
- v_field_rate_est = 1.0 / h_period_est / total_v_lines * 1000000.0;
-
- print_value(11, "[V FIELD RATE EST]", v_field_rate_est);
-
-
- /* 12. Find the actual horizontal period:
- *
- * [H PERIOD] = [H PERIOD EST] / ([V FIELD RATE RQD] / [V FIELD RATE EST])
- */
-
- h_period = h_period_est / (v_field_rate_rqd / v_field_rate_est);
-
- print_value(12, "[H PERIOD]", h_period);
-
-
- /* 13. Find the actual Vertical field frequency:
- *
- * [V FIELD RATE] = 1 / [H PERIOD] / [TOTAL V LINES] * 1000000
- */
-
- v_field_rate = 1.0 / h_period / total_v_lines * 1000000.0;
-
- print_value(13, "[V FIELD RATE]", v_field_rate);
-
-
- /* 14. Find the Vertical frame frequency:
- *
- * [V FRAME RATE] = (IF([INT RQD?]="y", [V FIELD RATE]/2, [V FIELD RATE]))
- */
-
- v_frame_rate = interlaced ? v_field_rate / 2.0 : v_field_rate;
-
- print_value(14, "[V FRAME RATE]", v_frame_rate);
-
-
- /* 15. Find number of pixels in left margin:
- *
- * [LEFT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y",
- * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 /
- * [CELL GRAN RND]),0)) * [CELL GRAN RND],
- * 0))
- */
-
- left_margin = margins ?
- rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN :
- 0.0;
-
- print_value(15, "[LEFT MARGIN (PIXELS)]", left_margin);
-
-
- /* 16. Find number of pixels in right margin:
- *
- * [RIGHT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y",
- * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 /
- * [CELL GRAN RND]),0)) * [CELL GRAN RND],
- * 0))
- */
-
- right_margin = margins ?
- rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN :
- 0.0;
-
- print_value(16, "[RIGHT MARGIN (PIXELS)]", right_margin);
-
-
- /* 17. Find total number of active pixels in image and left and right
- * margins:
- *
- * [TOTAL ACTIVE PIXELS] = [H PIXELS RND] + [LEFT MARGIN (PIXELS)] +
- * [RIGHT MARGIN (PIXELS)]
- */
-
- total_active_pixels = h_pixels_rnd + left_margin + right_margin;
-
- print_value(17, "[TOTAL ACTIVE PIXELS]", total_active_pixels);
-
-
- /* 18. Find the ideal blanking duty cycle from the blanking duty cycle
- * equation:
- *
- * [IDEAL DUTY CYCLE] = [C'] - ([M']*[H PERIOD]/1000)
- */
-
- ideal_duty_cycle = C_PRIME - (M_PRIME * h_period / 1000.0);
-
- print_value(18, "[IDEAL DUTY CYCLE]", ideal_duty_cycle);
-
-
- /* 19. Find the number of pixels in the blanking time to the nearest
- * double character cell:
- *
- * [H BLANK (PIXELS)] = (ROUND(([TOTAL ACTIVE PIXELS] *
- * [IDEAL DUTY CYCLE] /
- * (100-[IDEAL DUTY CYCLE]) /
- * (2*[CELL GRAN RND])), 0))
- * * (2*[CELL GRAN RND])
- */
-
- h_blank = rint(total_active_pixels *
- ideal_duty_cycle /
- (100.0 - ideal_duty_cycle) /
- (2.0 * CELL_GRAN)) * (2.0 * CELL_GRAN);
-
- print_value(19, "[H BLANK (PIXELS)]", h_blank);
-
-
- /* 20. Find total number of pixels:
- *
- * [TOTAL PIXELS] = [TOTAL ACTIVE PIXELS] + [H BLANK (PIXELS)]
- */
-
- total_pixels = total_active_pixels + h_blank;
-
- print_value(20, "[TOTAL PIXELS]", total_pixels);
-
-
- /* 21. Find pixel clock frequency:
- *
- * [PIXEL FREQ] = [TOTAL PIXELS] / [H PERIOD]
- */
-
- pixel_freq = total_pixels / h_period;
-
- print_value(21, "[PIXEL FREQ]", pixel_freq);
-
-
- /* 22. Find horizontal frequency:
- *
- * [H FREQ] = 1000 / [H PERIOD]
- */
-
- h_freq = 1000.0 / h_period;
-
- print_value(22, "[H FREQ]", h_freq);
-
-
-
- /* Stage 1 computations are now complete; I should really pass
- the results to another function and do the Stage 2
- computations, but I only need a few more values so I'll just
- append the computations here for now */
-
-
-
- /* 17. Find the number of pixels in the horizontal sync period:
- *
- * [H SYNC (PIXELS)] =(ROUND(([H SYNC%] / 100 * [TOTAL PIXELS] /
- * [CELL GRAN RND]),0))*[CELL GRAN RND]
- */
-
- h_sync = rint(H_SYNC_PERCENT/100.0 * total_pixels / CELL_GRAN) * CELL_GRAN;
-
- print_value(17, "[H SYNC (PIXELS)]", h_sync);
-
-
- /* 18. Find the number of pixels in the horizontal front porch period:
- *
- * [H FRONT PORCH (PIXELS)] = ([H BLANK (PIXELS)]/2)-[H SYNC (PIXELS)]
- */
-
- h_front_porch = (h_blank / 2.0) - h_sync;
-
- print_value(18, "[H FRONT PORCH (PIXELS)]", h_front_porch);
-
-
- /* 36. Find the number of lines in the odd front porch period:
- *
- * [V ODD FRONT PORCH(LINES)]=([MIN PORCH RND]+[INTERLACE])
- */
-
- v_odd_front_porch_lines = MIN_PORCH + interlace;
-
- print_value(36, "[V ODD FRONT PORCH(LINES)]", v_odd_front_porch_lines);
-
-
- /* finally, pack the results in the mode struct */
-
- m->hr = (int) (h_pixels_rnd);
- m->hss = (int) (h_pixels_rnd + h_front_porch);
- m->hse = (int) (h_pixels_rnd + h_front_porch + h_sync);
- m->hfl = (int) (total_pixels);
-
- m->vr = (int) (v_lines_rnd);
- m->vss = (int) (v_lines_rnd + v_odd_front_porch_lines);
- m->vse = (int) (int) (v_lines_rnd + v_odd_front_porch_lines + V_SYNC_RQD);
- m->vfl = (int) (total_v_lines);
-
- m->pclk = pixel_freq;
- m->h_freq = h_freq;
- m->v_freq = freq;
-
- return m;
-
-}
-
-
-
-
-/*
- * parse_command_line() - parse the command line and return an
- * alloced structure containing the results. On error print usage
- * and return NULL.
- */
-
-options *parse_command_line (int argc, char *argv[])
-{
- int n;
-
- options *o = (options *) calloc (1, sizeof (options));
-
- if (argc < 4) goto bad_option;
-
- o->x = atoi (argv[1]);
- o->y = atoi (argv[2]);
- o->v_freq = atof (argv[3]);
-
- /* XXX should check for errors in the above */
-
- n = 4;
-
- while (n < argc) {
- if ((strcmp (argv[n], "-v") == 0) ||
- (strcmp (argv[n], "--verbose") == 0)) {
- global_verbose = 1;
- } else if ((strcmp (argv[n], "-f") == 0) ||
- (strcmp (argv[n], "--fbmode") == 0)) {
- o->fbmode = 1;
- } else if ((strcmp (argv[n], "-x") == 0) ||
- (strcmp (argv[n], "--xorgmode") == 0) ||
- (strcmp (argv[n], "--xf86mode") == 0)) {
- o->xorgmode = 1;
- } else {
- goto bad_option;
- }
-
- n++;
- }
-
- /* if neither xorgmode nor fbmode were requested, default to
- xorgmode */
-
- if (!o->fbmode && !o->xorgmode) o->xorgmode = 1;
-
- return o;
-
- bad_option:
-
- fprintf (stderr, "\n");
- fprintf (stderr, "usage: %s x y refresh [-v|--verbose] "
- "[-f|--fbmode] [-x|--xorgmode]\n", argv[0]);
-
- fprintf (stderr, "\n");
-
- fprintf (stderr, " x : the desired horizontal "
- "resolution (required)\n");
- fprintf (stderr, " y : the desired vertical "
- "resolution (required)\n");
- fprintf (stderr, " refresh : the desired refresh "
- "rate (required)\n");
- fprintf (stderr, " -v|--verbose : enable verbose printouts "
- "(traces each step of the computation)\n");
- fprintf (stderr, " -f|--fbmode : output an fbset(8)-style mode "
- "description\n");
- fprintf (stderr, " -x|--xorgmode : output an "__XSERVERNAME__"-style mode "
- "description (this is the default\n"
- " if no mode description is requested)\n");
-
- fprintf (stderr, "\n");
-
- free (o);
- return NULL;
-
-}
-
-
-
-int main (int argc, char *argv[])
-{
- mode *m;
- options *o;
-
- o = parse_command_line (argc, argv);
- if (!o) exit (1);
-
- m = vert_refresh (o->x, o->y, o->v_freq, 0, 0);
- if (!m) exit (1);
-
- if (o->xorgmode)
- print_xf86_mode(m);
-
- if (o->fbmode)
- print_fb_mode(m);
-
- return 0;
-
-}
+/* gtf.c Generate mode timings using the GTF Timing Standard + * + * gcc gtf.c -o gtf -lm -Wall + * + * Copyright (c) 2001, Andy Ritger aritger@nvidia.com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * o Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * o Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * o Neither the name of NVIDIA nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * + * This program is based on the Generalized Timing Formula(GTF TM) + * Standard Version: 1.0, Revision: 1.0 + * + * The GTF Document contains the following Copyright information: + * + * Copyright (c) 1994, 1995, 1996 - Video Electronics Standards + * Association. Duplication of this document within VESA member + * companies for review purposes is permitted. All other rights + * reserved. + * + * While every precaution has been taken in the preparation + * of this standard, the Video Electronics Standards Association and + * its contributors assume no responsibility for errors or omissions, + * and make no warranties, expressed or implied, of functionality + * of suitability for any purpose. The sample code contained within + * this standard may be used without restriction. + * + * + * + * The GTF EXCEL(TM) SPREADSHEET, a sample (and the definitive) + * implementation of the GTF Timing Standard, is available at: + * + * ftp://ftp.vesa.org/pub/GTF/GTF_V1R1.xls + * + * + * + * This program takes a desired resolution and vertical refresh rate, + * and computes mode timings according to the GTF Timing Standard. + * These mode timings can then be formatted as an XServer modeline + * or a mode description for use by fbset(8). + * + * + * + * NOTES: + * + * The GTF allows for computation of "margins" (the visible border + * surrounding the addressable video); on most non-overscan type + * systems, the margin period is zero. I've implemented the margin + * computations but not enabled it because 1) I don't really have + * any experience with this, and 2) neither XServer modelines nor + * fbset fb.modes provide an obvious way for margin timings to be + * included in their mode descriptions (needs more investigation). + * + * The GTF provides for computation of interlaced mode timings; + * I've implemented the computations but not enabled them, yet. + * I should probably enable and test this at some point. + * + * + * + * TODO: + * + * o Add support for interlaced modes. + * + * o Implement the other portions of the GTF: compute mode timings + * given either the desired pixel clock or the desired horizontal + * frequency. + * + * o It would be nice if this were more general purpose to do things + * outside the scope of the GTF: like generate double scan mode + * timings, for example. + * + * o Printing digits to the right of the decimal point when the + * digits are 0 annoys me. + * + * o Error checking. + * + */ + +#ifdef HAVE_XORG_CONFIG_H +# include <xorg-config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#define MARGIN_PERCENT 1.8 /* % of active vertical image */ +#define CELL_GRAN 8.0 /* assumed character cell granularity */ +#define MIN_PORCH 1 /* minimum front porch */ +#define V_SYNC_RQD 3 /* width of vsync in lines */ +#define H_SYNC_PERCENT 8.0 /* width of hsync as % of total line */ +#define MIN_VSYNC_PLUS_BP 550.0 /* min time of vsync + back porch (microsec) */ +#define M 600.0 /* blanking formula gradient */ +#define C 40.0 /* blanking formula offset */ +#define K 128.0 /* blanking formula scaling factor */ +#define J 20.0 /* blanking formula scaling factor */ + +/* C' and M' are part of the Blanking Duty Cycle computation */ + +#define C_PRIME (((C - J) * K/256.0) + J) +#define M_PRIME (K/256.0 * M) + + +/* struct definitions */ + +typedef struct __mode +{ + int hr, hss, hse, hfl; + int vr, vss, vse, vfl; + float pclk, h_freq, v_freq; +} mode; + + +typedef struct __options +{ + int x, y; + int xorgmode, fbmode; + float v_freq; +} options; + + + + +/* prototypes */ + +void print_value(int n, const char *name, float val); +void print_xf86_mode (mode *m); +void print_fb_mode (mode *m); +mode *vert_refresh (int h_pixels, int v_lines, float freq, + int interlaced, int margins); +options *parse_command_line (int argc, char *argv[]); + + + + +/* + * print_value() - print the result of the named computation; this is + * useful when comparing against the GTF EXCEL spreadsheet. + */ + +int global_verbose = 0; + +void print_value(int n, const char *name, float val) +{ + if (global_verbose) { + printf("%2d: %-27s: %15f\n", n, name, val); + } +} + + + +/* print_xf86_mode() - print the XServer modeline, given mode timings. */ + +void print_xf86_mode (mode *m) +{ + printf ("\n"); + printf (" # %dx%d @ %.2f Hz (GTF) hsync: %.2f kHz; pclk: %.2f MHz\n", + m->hr, m->vr, m->v_freq, m->h_freq, m->pclk); + + printf (" Modeline \"%dx%d_%.2f\" %.2f" + " %d %d %d %d" + " %d %d %d %d" + " -HSync +Vsync\n\n", + m->hr, m->vr, m->v_freq, m->pclk, + m->hr, m->hss, m->hse, m->hfl, + m->vr, m->vss, m->vse, m->vfl); + +} + + + +/* + * print_fb_mode() - print a mode description in fbset(8) format; + * see the fb.modes(8) manpage. The timing description used in + * this is rather odd; they use "left and right margin" to refer + * to the portion of the hblank before and after the sync pulse + * by conceptually wrapping the portion of the blank after the pulse + * to infront of the visible region; ie: + * + * + * Timing description I'm accustomed to: + * + * + * + * <--------1--------> <--2--> <--3--> <--4--> + * _________ + * |-------------------|_______| |_______ + * + * R SS SE FL + * + * 1: visible image + * 2: blank before sync (aka front porch) + * 3: sync pulse + * 4: blank after sync (aka back porch) + * R: Resolution + * SS: Sync Start + * SE: Sync End + * FL: Frame Length + * + * + * But the fb.modes format is: + * + * + * <--4--> <--------1--------> <--2--> <--3--> + * _________ + * _______|-------------------|_______| | + * + * The fb.modes(8) manpage refers to <4> and <2> as the left and + * right "margin" (as well as upper and lower margin in the vertical + * direction) -- note that this has nothing to do with the term + * "margin" used in the GTF Timing Standard. + * + * XXX always prints the 32 bit mode -- should I provide a command + * line option to specify the bpp? It's simple enough for a user + * to edit the mode description after it's generated. + */ + +void print_fb_mode (mode *m) +{ + printf ("\n"); + printf ("mode \"%dx%d %.2fHz 32bit (GTF)\"\n", + m->hr, m->vr, m->v_freq); + printf (" # PCLK: %.2f MHz, H: %.2f kHz, V: %.2f Hz\n", + m->pclk, m->h_freq, m->v_freq); + printf (" geometry %d %d %d %d 32\n", + m->hr, m->vr, m->hr, m->vr); + printf (" timings %d %d %d %d %d %d %d\n", + (int) rint(1000000.0/m->pclk),/* pixclock in picoseconds */ + m->hfl - m->hse, /* left margin (in pixels) */ + m->hss - m->hr, /* right margin (in pixels) */ + m->vfl - m->vse, /* upper margin (in pixel lines) */ + m->vss - m->vr, /* lower margin (in pixel lines) */ + m->hse - m->hss, /* horizontal sync length (pixels) */ + m->vse - m->vss); /* vert sync length (pixel lines) */ + printf (" hsync low\n"); + printf (" vsync high\n"); + printf ("endmode\n\n"); + +} + + + + +/* + * vert_refresh() - as defined by the GTF Timing Standard, compute the + * Stage 1 Parameters using the vertical refresh frequency. In other + * words: input a desired resolution and desired refresh rate, and + * output the GTF mode timings. + * + * XXX All the code is in place to compute interlaced modes, but I don't + * feel like testing it right now. + * + * XXX margin computations are implemented but not tested (nor used by + * XServer of fbset mode descriptions, from what I can tell). + */ + +mode *vert_refresh (int h_pixels, int v_lines, float freq, + int interlaced, int margins) +{ + float h_pixels_rnd; + float v_lines_rnd; + float v_field_rate_rqd; + float top_margin; + float bottom_margin; + float interlace; + float h_period_est; + float vsync_plus_bp; + float v_back_porch; + float total_v_lines; + float v_field_rate_est; + float h_period; + float v_field_rate; + float v_frame_rate; + float left_margin; + float right_margin; + float total_active_pixels; + float ideal_duty_cycle; + float h_blank; + float total_pixels; + float pixel_freq; + float h_freq; + + float h_sync; + float h_front_porch; + float v_odd_front_porch_lines; + + mode *m = (mode*) malloc (sizeof (mode)); + + + /* 1. In order to give correct results, the number of horizontal + * pixels requested is first processed to ensure that it is divisible + * by the character size, by rounding it to the nearest character + * cell boundary: + * + * [H PIXELS RND] = ((ROUND([H PIXELS]/[CELL GRAN RND],0))*[CELLGRAN RND]) + */ + + h_pixels_rnd = rint((float) h_pixels / CELL_GRAN) * CELL_GRAN; + + print_value(1, "[H PIXELS RND]", h_pixels_rnd); + + + /* 2. If interlace is requested, the number of vertical lines assumed + * by the calculation must be halved, as the computation calculates + * the number of vertical lines per field. In either case, the + * number of lines is rounded to the nearest integer. + * + * [V LINES RND] = IF([INT RQD?]="y", ROUND([V LINES]/2,0), + * ROUND([V LINES],0)) + */ + + v_lines_rnd = interlaced ? + rint((float) v_lines) / 2.0 : + rint((float) v_lines); + + print_value(2, "[V LINES RND]", v_lines_rnd); + + + /* 3. Find the frame rate required: + * + * [V FIELD RATE RQD] = IF([INT RQD?]="y", [I/P FREQ RQD]*2, + * [I/P FREQ RQD]) + */ + + v_field_rate_rqd = interlaced ? (freq * 2.0) : (freq); + + print_value(3, "[V FIELD RATE RQD]", v_field_rate_rqd); + + + /* 4. Find number of lines in Top margin: + * + * [TOP MARGIN (LINES)] = IF([MARGINS RQD?]="Y", + * ROUND(([MARGIN%]/100*[V LINES RND]),0), + * 0) + */ + + top_margin = margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0); + + print_value(4, "[TOP MARGIN (LINES)]", top_margin); + + + /* 5. Find number of lines in Bottom margin: + * + * [BOT MARGIN (LINES)] = IF([MARGINS RQD?]="Y", + * ROUND(([MARGIN%]/100*[V LINES RND]),0), + * 0) + */ + + bottom_margin = margins ? rint(MARGIN_PERCENT/100.0 * v_lines_rnd) : (0.0); + + print_value(5, "[BOT MARGIN (LINES)]", bottom_margin); + + + /* 6. If interlace is required, then set variable [INTERLACE]=0.5: + * + * [INTERLACE]=(IF([INT RQD?]="y",0.5,0)) + */ + + interlace = interlaced ? 0.5 : 0.0; + + print_value(6, "[INTERLACE]", interlace); + + + /* 7. Estimate the Horizontal period + * + * [H PERIOD EST] = ((1/[V FIELD RATE RQD]) - [MIN VSYNC+BP]/1000000) / + * ([V LINES RND] + (2*[TOP MARGIN (LINES)]) + + * [MIN PORCH RND]+[INTERLACE]) * 1000000 + */ + + h_period_est = (((1.0/v_field_rate_rqd) - (MIN_VSYNC_PLUS_BP/1000000.0)) + / (v_lines_rnd + (2*top_margin) + MIN_PORCH + interlace) + * 1000000.0); + + print_value(7, "[H PERIOD EST]", h_period_est); + + + /* 8. Find the number of lines in V sync + back porch: + * + * [V SYNC+BP] = ROUND(([MIN VSYNC+BP]/[H PERIOD EST]),0) + */ + + vsync_plus_bp = rint(MIN_VSYNC_PLUS_BP/h_period_est); + + print_value(8, "[V SYNC+BP]", vsync_plus_bp); + + + /* 9. Find the number of lines in V back porch alone: + * + * [V BACK PORCH] = [V SYNC+BP] - [V SYNC RND] + * + * XXX is "[V SYNC RND]" a typo? should be [V SYNC RQD]? + */ + + v_back_porch = vsync_plus_bp - V_SYNC_RQD; + + print_value(9, "[V BACK PORCH]", v_back_porch); + + + /* 10. Find the total number of lines in Vertical field period: + * + * [TOTAL V LINES] = [V LINES RND] + [TOP MARGIN (LINES)] + + * [BOT MARGIN (LINES)] + [V SYNC+BP] + [INTERLACE] + + * [MIN PORCH RND] + */ + + total_v_lines = v_lines_rnd + top_margin + bottom_margin + vsync_plus_bp + + interlace + MIN_PORCH; + + print_value(10, "[TOTAL V LINES]", total_v_lines); + + + /* 11. Estimate the Vertical field frequency: + * + * [V FIELD RATE EST] = 1 / [H PERIOD EST] / [TOTAL V LINES] * 1000000 + */ + + v_field_rate_est = 1.0 / h_period_est / total_v_lines * 1000000.0; + + print_value(11, "[V FIELD RATE EST]", v_field_rate_est); + + + /* 12. Find the actual horizontal period: + * + * [H PERIOD] = [H PERIOD EST] / ([V FIELD RATE RQD] / [V FIELD RATE EST]) + */ + + h_period = h_period_est / (v_field_rate_rqd / v_field_rate_est); + + print_value(12, "[H PERIOD]", h_period); + + + /* 13. Find the actual Vertical field frequency: + * + * [V FIELD RATE] = 1 / [H PERIOD] / [TOTAL V LINES] * 1000000 + */ + + v_field_rate = 1.0 / h_period / total_v_lines * 1000000.0; + + print_value(13, "[V FIELD RATE]", v_field_rate); + + + /* 14. Find the Vertical frame frequency: + * + * [V FRAME RATE] = (IF([INT RQD?]="y", [V FIELD RATE]/2, [V FIELD RATE])) + */ + + v_frame_rate = interlaced ? v_field_rate / 2.0 : v_field_rate; + + print_value(14, "[V FRAME RATE]", v_frame_rate); + + + /* 15. Find number of pixels in left margin: + * + * [LEFT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y", + * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 / + * [CELL GRAN RND]),0)) * [CELL GRAN RND], + * 0)) + */ + + left_margin = margins ? + rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN : + 0.0; + + print_value(15, "[LEFT MARGIN (PIXELS)]", left_margin); + + + /* 16. Find number of pixels in right margin: + * + * [RIGHT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y", + * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 / + * [CELL GRAN RND]),0)) * [CELL GRAN RND], + * 0)) + */ + + right_margin = margins ? + rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN : + 0.0; + + print_value(16, "[RIGHT MARGIN (PIXELS)]", right_margin); + + + /* 17. Find total number of active pixels in image and left and right + * margins: + * + * [TOTAL ACTIVE PIXELS] = [H PIXELS RND] + [LEFT MARGIN (PIXELS)] + + * [RIGHT MARGIN (PIXELS)] + */ + + total_active_pixels = h_pixels_rnd + left_margin + right_margin; + + print_value(17, "[TOTAL ACTIVE PIXELS]", total_active_pixels); + + + /* 18. Find the ideal blanking duty cycle from the blanking duty cycle + * equation: + * + * [IDEAL DUTY CYCLE] = [C'] - ([M']*[H PERIOD]/1000) + */ + + ideal_duty_cycle = C_PRIME - (M_PRIME * h_period / 1000.0); + + print_value(18, "[IDEAL DUTY CYCLE]", ideal_duty_cycle); + + + /* 19. Find the number of pixels in the blanking time to the nearest + * double character cell: + * + * [H BLANK (PIXELS)] = (ROUND(([TOTAL ACTIVE PIXELS] * + * [IDEAL DUTY CYCLE] / + * (100-[IDEAL DUTY CYCLE]) / + * (2*[CELL GRAN RND])), 0)) + * * (2*[CELL GRAN RND]) + */ + + h_blank = rint(total_active_pixels * + ideal_duty_cycle / + (100.0 - ideal_duty_cycle) / + (2.0 * CELL_GRAN)) * (2.0 * CELL_GRAN); + + print_value(19, "[H BLANK (PIXELS)]", h_blank); + + + /* 20. Find total number of pixels: + * + * [TOTAL PIXELS] = [TOTAL ACTIVE PIXELS] + [H BLANK (PIXELS)] + */ + + total_pixels = total_active_pixels + h_blank; + + print_value(20, "[TOTAL PIXELS]", total_pixels); + + + /* 21. Find pixel clock frequency: + * + * [PIXEL FREQ] = [TOTAL PIXELS] / [H PERIOD] + */ + + pixel_freq = total_pixels / h_period; + + print_value(21, "[PIXEL FREQ]", pixel_freq); + + + /* 22. Find horizontal frequency: + * + * [H FREQ] = 1000 / [H PERIOD] + */ + + h_freq = 1000.0 / h_period; + + print_value(22, "[H FREQ]", h_freq); + + + + /* Stage 1 computations are now complete; I should really pass + the results to another function and do the Stage 2 + computations, but I only need a few more values so I'll just + append the computations here for now */ + + + + /* 17. Find the number of pixels in the horizontal sync period: + * + * [H SYNC (PIXELS)] =(ROUND(([H SYNC%] / 100 * [TOTAL PIXELS] / + * [CELL GRAN RND]),0))*[CELL GRAN RND] + */ + + h_sync = rint(H_SYNC_PERCENT/100.0 * total_pixels / CELL_GRAN) * CELL_GRAN; + + print_value(17, "[H SYNC (PIXELS)]", h_sync); + + + /* 18. Find the number of pixels in the horizontal front porch period: + * + * [H FRONT PORCH (PIXELS)] = ([H BLANK (PIXELS)]/2)-[H SYNC (PIXELS)] + */ + + h_front_porch = (h_blank / 2.0) - h_sync; + + print_value(18, "[H FRONT PORCH (PIXELS)]", h_front_porch); + + + /* 36. Find the number of lines in the odd front porch period: + * + * [V ODD FRONT PORCH(LINES)]=([MIN PORCH RND]+[INTERLACE]) + */ + + v_odd_front_porch_lines = MIN_PORCH + interlace; + + print_value(36, "[V ODD FRONT PORCH(LINES)]", v_odd_front_porch_lines); + + + /* finally, pack the results in the mode struct */ + + m->hr = (int) (h_pixels_rnd); + m->hss = (int) (h_pixels_rnd + h_front_porch); + m->hse = (int) (h_pixels_rnd + h_front_porch + h_sync); + m->hfl = (int) (total_pixels); + + m->vr = (int) (v_lines_rnd); + m->vss = (int) (v_lines_rnd + v_odd_front_porch_lines); + m->vse = (int) (int) (v_lines_rnd + v_odd_front_porch_lines + V_SYNC_RQD); + m->vfl = (int) (total_v_lines); + + m->pclk = pixel_freq; + m->h_freq = h_freq; + m->v_freq = freq; + + return m; + +} + + + + +/* + * parse_command_line() - parse the command line and return an + * alloced structure containing the results. On error print usage + * and return NULL. + */ + +options *parse_command_line (int argc, char *argv[]) +{ + int n; + + options *o = (options *) calloc (1, sizeof (options)); + + if (argc < 4) goto bad_option; + + o->x = atoi (argv[1]); + o->y = atoi (argv[2]); + o->v_freq = atof (argv[3]); + + /* XXX should check for errors in the above */ + + n = 4; + + while (n < argc) { + if ((strcmp (argv[n], "-v") == 0) || + (strcmp (argv[n], "--verbose") == 0)) { + global_verbose = 1; + } else if ((strcmp (argv[n], "-f") == 0) || + (strcmp (argv[n], "--fbmode") == 0)) { + o->fbmode = 1; + } else if ((strcmp (argv[n], "-x") == 0) || + (strcmp (argv[n], "--xorgmode") == 0) || + (strcmp (argv[n], "--xf86mode") == 0)) { + o->xorgmode = 1; + } else { + goto bad_option; + } + + n++; + } + + /* if neither xorgmode nor fbmode were requested, default to + xorgmode */ + + if (!o->fbmode && !o->xorgmode) o->xorgmode = 1; + + return o; + + bad_option: + + fprintf (stderr, "\n"); + fprintf (stderr, "usage: %s x y refresh [-v|--verbose] " + "[-f|--fbmode] [-x|--xorgmode]\n", argv[0]); + + fprintf (stderr, "\n"); + + fprintf (stderr, " x : the desired horizontal " + "resolution (required)\n"); + fprintf (stderr, " y : the desired vertical " + "resolution (required)\n"); + fprintf (stderr, " refresh : the desired refresh " + "rate (required)\n"); + fprintf (stderr, " -v|--verbose : enable verbose printouts " + "(traces each step of the computation)\n"); + fprintf (stderr, " -f|--fbmode : output an fbset(8)-style mode " + "description\n"); + fprintf (stderr, " -x|--xorgmode : output an "__XSERVERNAME__"-style mode " + "description (this is the default\n" + " if no mode description is requested)\n"); + + fprintf (stderr, "\n"); + + free (o); + return NULL; + +} + + + +int main (int argc, char *argv[]) +{ + mode *m; + options *o; + + o = parse_command_line (argc, argv); + if (!o) exit (1); + + m = vert_refresh (o->x, o->y, o->v_freq, 0, 0); + if (!m) exit (1); + + if (o->xorgmode) + print_xf86_mode(m); + + if (o->fbmode) + print_fb_mode(m); + + return 0; + +} diff --git a/xorg-server/hw/xfree86/vbe/vbe.c b/xorg-server/hw/xfree86/vbe/vbe.c index 06a628457..6ecca6858 100644 --- a/xorg-server/hw/xfree86/vbe/vbe.c +++ b/xorg-server/hw/xfree86/vbe/vbe.c @@ -170,7 +170,7 @@ vbeFree(vbeInfoPtr pVbe) static Bool vbeProbeDDC(vbeInfoPtr pVbe) { - char *ddc_level; + const char *ddc_level; int screen = pVbe->pInt10->scrnIndex; if (pVbe->ddc == DDC_NONE) diff --git a/xorg-server/hw/xfree86/x86emu/debug.c b/xorg-server/hw/xfree86/x86emu/debug.c index 5eda90805..04d0741e0 100644 --- a/xorg-server/hw/xfree86/x86emu/debug.c +++ b/xorg-server/hw/xfree86/x86emu/debug.c @@ -172,7 +172,7 @@ void x86emu_decode_printf (char *x) void x86emu_decode_printf2 (char *x, int y) { char temp[100]; - sprintf(temp,x,y); + snprintf(temp,sizeof(temp),x,y); sprintf(M.x86.decoded_buf+M.x86.enc_str_pos,"%s",temp); M.x86.enc_str_pos += strlen(temp); } diff --git a/xorg-server/hw/xquartz/xpr/dri.c b/xorg-server/hw/xquartz/xpr/dri.c index 8bae6b009..a58f2c76d 100644 --- a/xorg-server/hw/xquartz/xpr/dri.c +++ b/xorg-server/hw/xquartz/xpr/dri.c @@ -813,8 +813,7 @@ Bool DRICreatePixmap(ScreenPtr pScreen, Drawable id, return FALSE; } - strncpy(path, shared->shmPath, pathmax); - path[pathmax - 1] = '\0'; + strlcpy(path, shared->shmPath, pathmax); dixSetPrivate(&pPix->devPrivates, DRIPixmapBufferPrivKey, shared); diff --git a/xorg-server/hw/xwin/winconfig.c b/xorg-server/hw/xwin/winconfig.c index 7b26432f2..4dbbe7ced 100644 --- a/xorg-server/hw/xwin/winconfig.c +++ b/xorg-server/hw/xwin/winconfig.c @@ -1,1112 +1,1114 @@ -/*
- *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
- *
- *Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- *"Software"), to deal in the Software without restriction, including
- *without limitation the rights to use, copy, modify, merge, publish,
- *distribute, sublicense, and/or sell copies of the Software, and to
- *permit persons to whom the Software is furnished to do so, subject to
- *the following conditions:
- *
- *The above copyright notice and this permission notice shall be
- *included in all copies or substantial portions of the Software.
- *
- *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
- *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *Except as contained in this notice, the name of the XFree86 Project
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from the XFree86 Project.
- *
- * Authors: Alexander Gottwald
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-#include "winconfig.h"
-#include "winmsg.h"
-#include "globals.h"
-
-#include "xkbsrv.h"
-
-#ifdef XWIN_XF86CONFIG
-#ifndef CONFIGPATH
-#define CONFIGPATH "%A," "%R," \
- "/etc/X11/%R," "%P/etc/X11/%R," \
- "%E," "%F," \
- "/etc/X11/%F," "%P/etc/X11/%F," \
- "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
- "%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
- "%P/etc/X11/%X," \
- "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
- "%P/lib/X11/%X"
-#endif
-#ifndef CONFIGDIRPATH
-#define CONFIGDIRPATH "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
- "%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
- "%P/etc/X11/%X," \
- "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
- "%P/lib/X11/%X"
-#endif
-
-XF86ConfigPtr g_xf86configptr = NULL;
-#endif
-
-WinCmdlineRec g_cmdline = {
-#ifdef XWIN_XF86CONFIG
- NULL, /* configFile */
- NULL, /* configDir */
-#endif
- NULL, /* fontPath */
-#ifdef XWIN_XF86CONFIG
- NULL, /* keyboard */
-#endif
- NULL, /* xkbRules */
- NULL, /* xkbModel */
- NULL, /* xkbLayout */
- NULL, /* xkbVariant */
- NULL, /* xkbOptions */
- NULL, /* screenname */
- NULL, /* mousename */
- FALSE, /* emulate3Buttons */
- 0 /* emulate3Timeout */
-};
-
-winInfoRec g_winInfo = {
- { /* keyboard */
- 0, /* leds */
- 500, /* delay */
- 30 /* rate */
- }
- ,
- { /* xkb */
- NULL, /* rules */
- NULL, /* model */
- NULL, /* layout */
- NULL, /* variant */
- NULL, /* options */
- }
- ,
- {
- FALSE,
- 50}
-};
-
-#define NULL_IF_EMPTY(x) (winNameCompare(x,"")?x:NULL)
-
-#ifdef XWIN_XF86CONFIG
-serverLayoutRec g_winConfigLayout;
-
-static Bool ParseOptionValue (int scrnIndex, pointer options,
- OptionInfoPtr p);
-static Bool configLayout (serverLayoutPtr, XF86ConfLayoutPtr, char *);
-static Bool configImpliedLayout (serverLayoutPtr, XF86ConfScreenPtr);
-static Bool GetBoolValue (OptionInfoPtr p, const char *s);
-
-
-Bool
-winReadConfigfile ()
-{
- Bool retval = TRUE;
- const char *filename, *dirname;
- MessageType filefrom = X_DEFAULT;
- MessageType dirfrom = X_DEFAULT;
- char *xf86ConfigFile = NULL;
- char *xf86ConfigDir = NULL;
-
- if (g_cmdline.configFile)
- {
- filefrom = X_CMDLINE;
- xf86ConfigFile = g_cmdline.configFile;
- }
- if (g_cmdline.configDir)
- {
- dirfrom = X_CMDLINE;
- xf86ConfigDir = g_cmdline.configDir;
- }
-
- /* Parse config file into data structure */
- xf86initConfigFiles();
- dirname = xf86openConfigDirFiles (CONFIGDIRPATH, xf86ConfigDir, PROJECTROOT);
- filename = xf86openConfigFile (CONFIGPATH, xf86ConfigFile, PROJECTROOT);
-
- /* Hack for backward compatibility */
- if (!filename && from == X_DEFAULT)
- filename = xf86openConfigFile (CONFIGPATH, "XF86Config", PROJECTROOT);
-
- if (filename)
- {
- winMsg (from, "Using config file: \"%s\"\n", filename);
- }
- else
- {
- winMsg (X_ERROR, "Unable to locate/open config file");
- if (xf86ConfigFile)
- ErrorF (": \"%s\"", xf86ConfigFile);
- ErrorF ("\n");
- }
- if (dirname)
- {
- winMsg (from, "Using config directory: \"%s\"\n", dirname);
- }
- else
- {
- winMsg (X_ERROR, "Unable to locate/open config directory");
- if (xf86ConfigDir)
- ErrorF (": \"%s\"", xf86ConfigDir);
- ErrorF ("\n");
- }
- if (!filename && !dirname)
- {
- return FALSE;
- }
- if ((g_xf86configptr = xf86readConfigFile ()) == NULL)
- {
- winMsg (X_ERROR, "Problem parsing the config file\n");
- return FALSE;
- }
- xf86closeConfigFile ();
-
- LogPrintMarkers();
-
- /* set options from data structure */
-
- if (g_xf86configptr->conf_layout_lst == NULL || g_cmdline.screenname != NULL)
- {
- if (g_cmdline.screenname == NULL)
- {
- winMsg (X_WARNING,
- "No Layout section. Using the first Screen section.\n");
- }
- if (!configImpliedLayout (&g_winConfigLayout,
- g_xf86configptr->conf_screen_lst))
- {
- winMsg (X_ERROR, "Unable to determine the screen layout\n");
- return FALSE;
- }
- }
- else
- {
- /* Check if layout is given in the config file */
- if (g_xf86configptr->conf_flags != NULL)
- {
- char *dfltlayout = NULL;
- pointer optlist = g_xf86configptr->conf_flags->flg_option_lst;
-
- if (optlist && winFindOption (optlist, "defaultserverlayout"))
- dfltlayout =
- winSetStrOption (optlist, "defaultserverlayout", NULL);
-
- if (!configLayout (&g_winConfigLayout,
- g_xf86configptr->conf_layout_lst,
- dfltlayout))
- {
- winMsg (X_ERROR, "Unable to determine the screen layout\n");
- return FALSE;
- }
- }
- else
- {
- if (!configLayout (&g_winConfigLayout,
- g_xf86configptr->conf_layout_lst,
- NULL))
- {
- winMsg (X_ERROR, "Unable to determine the screen layout\n");
- return FALSE;
- }
- }
- }
-
- /* setup special config files */
- winConfigFiles ();
- return retval;
-}
-#endif
-
-/* load layout definitions */
-#include "winlayouts.h"
-
-/* Set the keyboard configuration */
-Bool
-winConfigKeyboard (DeviceIntPtr pDevice)
-{
- char layoutName[KL_NAMELENGTH];
- unsigned char layoutFriendlyName[256];
- static unsigned int layoutNum = 0;
- int keyboardType;
-#ifdef XWIN_XF86CONFIG
- XF86ConfInputPtr kbd = NULL;
- XF86ConfInputPtr input_list = NULL;
- MessageType kbdfrom = X_CONFIG;
-#endif
- MessageType from = X_DEFAULT;
- char *s = NULL;
-
- /* Setup defaults */
- XkbGetRulesDflts(&g_winInfo.xkb);
-
- /*
- * Query the windows autorepeat settings and change the xserver defaults.
- */
- {
- int kbd_delay;
- DWORD kbd_speed;
- if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &kbd_delay, 0) &&
- SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &kbd_speed, 0))
- {
- switch (kbd_delay)
- {
- case 0: g_winInfo.keyboard.delay = 250; break;
- case 1: g_winInfo.keyboard.delay = 500; break;
- case 2: g_winInfo.keyboard.delay = 750; break;
- default:
- case 3: g_winInfo.keyboard.delay = 1000; break;
- }
- g_winInfo.keyboard.rate = (kbd_speed>0)?kbd_speed:1;
- winMsgVerb(X_PROBED, 1, "Setting autorepeat to delay=%d, rate=%d\n",
- g_winInfo.keyboard.delay, g_winInfo.keyboard.rate);
- }
- }
-
-
- keyboardType = GetKeyboardType (0);
- if (keyboardType > 0 && GetKeyboardLayoutName (layoutName))
- {
- WinKBLayoutPtr pLayout;
- Bool bfound = FALSE;
-
- if (! layoutNum)
- layoutNum = strtoul (layoutName, (char **)NULL, 16);
- if ((layoutNum & 0xffff) == 0x411) {
- /* The japanese layouts know a lot of different IMEs which all have
- different layout numbers set. Map them to a single entry.
- Same might apply for chinese, korean and other symbol languages
- too */
- layoutNum = (layoutNum & 0xffff);
- if (keyboardType == 7)
- {
- /* Japanese layouts have problems with key event messages
- such as the lack of WM_KEYUP for Caps Lock key.
- Loading US layout fixes this problem. */
- if (LoadKeyboardLayout("00000409", KLF_ACTIVATE) != NULL)
- winMsg (X_INFO, "Loading US keyboard layout.\n");
- else
- winMsg (X_ERROR, "LoadKeyboardLayout failed.\n");
- }
- }
-
- /* Discover the friendly name of the current layout */
- {
- HKEY regkey = NULL;
- const char regtempl[] = "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\";
- char *regpath;
- DWORD namesize = sizeof(layoutFriendlyName);
-
- regpath = malloc(sizeof(regtempl) + KL_NAMELENGTH + 1);
- strcpy(regpath, regtempl);
- strcat(regpath, layoutName);
-
- if (!RegOpenKey(HKEY_LOCAL_MACHINE, regpath, ®key))
- RegQueryValueEx(regkey, "Layout Text", 0, NULL, layoutFriendlyName, &namesize);
-
- /* Close registry key */
- if (regkey)
- RegCloseKey (regkey);
- free(regpath);
- }
-
- winMsg (X_PROBED, "Windows keyboard layout: \"%s\" (%08x) \"%s\", type %d\n",
- layoutName, layoutNum, layoutFriendlyName, keyboardType);
-
- for (pLayout = winKBLayouts; pLayout->winlayout != -1; pLayout++)
- {
- if (pLayout->winlayout != layoutNum)
- continue;
- if (pLayout->winkbtype > 0 && pLayout->winkbtype != keyboardType)
- continue;
-
- bfound = TRUE;
- winMsg (X_PROBED,
- "Found matching XKB configuration \"%s\"\n",
- pLayout->layoutname);
-
- winMsg(X_PROBED,
- "Model = \"%s\" Layout = \"%s\""
- " Variant = \"%s\" Options = \"%s\"\n",
- pLayout->xkbmodel ? pLayout->xkbmodel : "none",
- pLayout->xkblayout ? pLayout->xkblayout : "none",
- pLayout->xkbvariant ? pLayout->xkbvariant : "none",
- pLayout->xkboptions ? pLayout->xkboptions : "none");
-
- g_winInfo.xkb.model = pLayout->xkbmodel;
- g_winInfo.xkb.layout = pLayout->xkblayout;
- g_winInfo.xkb.variant = pLayout->xkbvariant;
- g_winInfo.xkb.options = pLayout->xkboptions;
-
-
- break;
- }
-
- if (!bfound)
- {
- winMsg (X_ERROR, "Keyboardlayout \"%s\" (%s) is unknown, using X server default layout\n", layoutFriendlyName, layoutName);
- }
- }
-
- /* parse the configuration */
-#ifdef XWIN_XF86CONFIG
- if (g_cmdline.keyboard)
- kbdfrom = X_CMDLINE;
-
- /*
- * Until the layout code is finished, I search for the keyboard
- * device and configure the server with it.
- */
-
- if (g_xf86configptr != NULL)
- input_list = g_xf86configptr->conf_input_lst;
-
- while (input_list != NULL)
- {
- if (winNameCompare (input_list->inp_driver, "keyboard") == 0)
- {
- /* Check if device name matches requested name */
- if (g_cmdline.keyboard && winNameCompare (input_list->inp_identifier,
- g_cmdline.keyboard))
- continue;
- kbd = input_list;
- }
- input_list = input_list->list.next;
- }
-
- if (kbd != NULL)
- {
-
- if (kbd->inp_identifier)
- winMsg (kbdfrom, "Using keyboard \"%s\" as primary keyboard\n",
- kbd->inp_identifier);
-
- if ((s = winSetStrOption(kbd->inp_option_lst, "AutoRepeat", NULL)))
- {
- if ((sscanf(s, "%ld %ld", &g_winInfo.keyboard.delay,
- &g_winInfo.keyboard.rate) != 2) ||
- (g_winInfo.keyboard.delay < 1) ||
- (g_winInfo.keyboard.rate == 0) ||
- (1000 / g_winInfo.keyboard.rate) < 1)
- {
- winErrorFVerb (2, "\"%s\" is not a valid AutoRepeat value", s);
- free(s);
- return FALSE;
- }
- free(s);
- winMsg (X_CONFIG, "AutoRepeat: %ld %ld\n",
- g_winInfo.keyboard.delay, g_winInfo.keyboard.rate);
- }
-#endif
-
- s = NULL;
- if (g_cmdline.xkbRules)
- {
- s = g_cmdline.xkbRules;
- from = X_CMDLINE;
- }
-#ifdef XWIN_XF86CONFIG
- else
- {
- s = winSetStrOption (kbd->inp_option_lst, "XkbRules", NULL);
- from = X_CONFIG;
- }
-#endif
- if (s)
- {
- g_winInfo.xkb.rules = NULL_IF_EMPTY (s);
- winMsg (from, "XKB: rules: \"%s\"\n", s);
- }
-
- s = NULL;
- if (g_cmdline.xkbModel)
- {
- s = g_cmdline.xkbModel;
- from = X_CMDLINE;
- }
-#ifdef XWIN_XF86CONFIG
- else
- {
- s = winSetStrOption (kbd->inp_option_lst, "XkbModel", NULL);
- from = X_CONFIG;
- }
-#endif
- if (s)
- {
- g_winInfo.xkb.model = NULL_IF_EMPTY (s);
- winMsg (from, "XKB: model: \"%s\"\n", s);
- }
-
- s = NULL;
- if (g_cmdline.xkbLayout)
- {
- s = g_cmdline.xkbLayout;
- from = X_CMDLINE;
- }
-#ifdef XWIN_XF86CONFIG
- else
- {
- s = winSetStrOption (kbd->inp_option_lst, "XkbLayout", NULL);
- from = X_CONFIG;
- }
-#endif
- if (s)
- {
- g_winInfo.xkb.layout = NULL_IF_EMPTY (s);
- winMsg (from, "XKB: layout: \"%s\"\n", s);
- }
-
- s = NULL;
- if (g_cmdline.xkbVariant)
- {
- s = g_cmdline.xkbVariant;
- from = X_CMDLINE;
- }
-#ifdef XWIN_XF86CONFIG
- else
- {
- s = winSetStrOption (kbd->inp_option_lst, "XkbVariant", NULL);
- from = X_CONFIG;
- }
-#endif
- if (s)
- {
- g_winInfo.xkb.variant = NULL_IF_EMPTY (s);
- winMsg (from, "XKB: variant: \"%s\"\n", s);
- }
-
- s = NULL;
- if (g_cmdline.xkbOptions)
- {
- s = g_cmdline.xkbOptions;
- from = X_CMDLINE;
- }
-#ifdef XWIN_XF86CONFIG
- else
- {
- s = winSetStrOption (kbd->inp_option_lst, "XkbOptions", NULL);
- from = X_CONFIG;
- }
-#endif
- if (s)
- {
- g_winInfo.xkb.options = NULL_IF_EMPTY (s);
- winMsg (from, "XKB: options: \"%s\"\n", s);
- }
-
-#ifdef XWIN_XF86CONFIG
- }
-#endif
-
- return TRUE;
-}
-
-
-#ifdef XWIN_XF86CONFIG
-Bool
-winConfigMouse (DeviceIntPtr pDevice)
-{
- MessageType mousefrom = X_CONFIG;
-
- XF86ConfInputPtr mouse = NULL;
- XF86ConfInputPtr input_list = NULL;
-
- if (g_cmdline.mouse)
- mousefrom = X_CMDLINE;
-
- if (g_xf86configptr != NULL)
- input_list = g_xf86configptr->conf_input_lst;
-
- while (input_list != NULL)
- {
- if (winNameCompare (input_list->inp_driver, "mouse") == 0)
- {
- /* Check if device name matches requested name */
- if (g_cmdline.mouse && winNameCompare (input_list->inp_identifier,
- g_cmdline.mouse))
- continue;
- mouse = input_list;
- }
- input_list = input_list->list.next;
- }
-
- if (mouse != NULL)
- {
- if (mouse->inp_identifier)
- winMsg (mousefrom, "Using pointer \"%s\" as primary pointer\n",
- mouse->inp_identifier);
-
- g_winInfo.pointer.emulate3Buttons =
- winSetBoolOption (mouse->inp_option_lst, "Emulate3Buttons", FALSE);
- if (g_cmdline.emulate3buttons)
- g_winInfo.pointer.emulate3Buttons = g_cmdline.emulate3buttons;
-
- g_winInfo.pointer.emulate3Timeout =
- winSetIntOption (mouse->inp_option_lst, "Emulate3Timeout", 50);
- if (g_cmdline.emulate3timeout)
- g_winInfo.pointer.emulate3Timeout = g_cmdline.emulate3timeout;
- }
- else
- {
- winMsg (X_ERROR, "No primary pointer configured\n");
- winMsg (X_DEFAULT, "Using compiletime defaults for pointer\n");
- }
-
- return TRUE;
-}
-
-
-Bool
-winConfigFiles ()
-{
- MessageType from;
- XF86ConfFilesPtr filesptr = NULL;
-
- /* set some shortcuts */
- if (g_xf86configptr != NULL)
- {
- filesptr = g_xf86configptr->conf_files;
- }
-
-
- /* Fontpath */
- from = X_DEFAULT;
-
- if (g_cmdline.fontPath)
- {
- from = X_CMDLINE;
- defaultFontPath = g_cmdline.fontPath;
- }
- else if (filesptr != NULL && filesptr->file_fontpath)
- {
- from = X_CONFIG;
- defaultFontPath = strdup (filesptr->file_fontpath);
- }
- winMsg (from, "FontPath set to \"%s\"\n", defaultFontPath);
-
- return TRUE;
-}
-#else
-Bool
-winConfigFiles (void)
-{
- /* Fontpath */
- if (g_cmdline.fontPath)
- {
- defaultFontPath = g_cmdline.fontPath;
- winMsg (X_CMDLINE, "FontPath set to \"%s\"\n", defaultFontPath);
- }
-
- return TRUE;
-}
-#endif
-
-
-Bool
-winConfigOptions (void)
-{
- return TRUE;
-}
-
-
-Bool
-winConfigScreens (void)
-{
- return TRUE;
-}
-
-
-#ifdef XWIN_XF86CONFIG
-char *
-winSetStrOption (pointer optlist, const char *name, char *deflt)
-{
- OptionInfoRec o;
-
- o.name = name;
- o.type = OPTV_STRING;
- if (ParseOptionValue (-1, optlist, &o))
- deflt = o.value.str;
- if (deflt)
- return strdup (deflt);
- else
- return NULL;
-}
-
-
-int
-winSetBoolOption (pointer optlist, const char *name, int deflt)
-{
- OptionInfoRec o;
-
- o.name = name;
- o.type = OPTV_BOOLEAN;
- if (ParseOptionValue (-1, optlist, &o))
- deflt = o.value.bool;
- return deflt;
-}
-
-
-int
-winSetIntOption (pointer optlist, const char *name, int deflt)
-{
- OptionInfoRec o;
-
- o.name = name;
- o.type = OPTV_INTEGER;
- if (ParseOptionValue (-1, optlist, &o))
- deflt = o.value.num;
- return deflt;
-}
-
-
-double
-winSetRealOption (pointer optlist, const char *name, double deflt)
-{
- OptionInfoRec o;
-
- o.name = name;
- o.type = OPTV_REAL;
- if (ParseOptionValue (-1, optlist, &o))
- deflt = o.value.realnum;
- return deflt;
-}
-
-double
-winSetPercentOption (pointer optlist, const char *name, double deflt)
-{
- OptionInfoRec o;
-
- o.name = name;
- o.type = OPTV_PERCENT;
- if (ParseOptionValue (-1, optlist, &o))
- deflt = o.value.realnum;
- return deflt;
-}
-#endif
-
-
-/*
- * Compare two strings for equality. This is caseinsensitive and
- * The characters '_', ' ' (space) and '\t' (tab) are treated as
- * not existing.
- */
-
-int
-winNameCompare (const char *s1, const char *s2)
-{
- char c1, c2;
-
- if (!s1 || *s1 == 0)
- {
- if (!s2 || *s2 == 0)
- return 0;
- else
- return 1;
- }
-
- while (*s1 == '_' || *s1 == ' ' || *s1 == '\t')
- s1++;
- while (*s2 == '_' || *s2 == ' ' || *s2 == '\t')
- s2++;
-
- c1 = (isupper ((int)*s1) ? tolower ((int)*s1) : *s1);
- c2 = (isupper ((int)*s2) ? tolower ((int)*s2) : *s2);
-
- while (c1 == c2)
- {
- if (c1 == 0)
- return 0;
- s1++;
- s2++;
-
- while (*s1 == '_' || *s1 == ' ' || *s1 == '\t')
- s1++;
- while (*s2 == '_' || *s2 == ' ' || *s2 == '\t')
- s2++;
-
- c1 = (isupper ((int)*s1) ? tolower ((int)*s1) : *s1);
- c2 = (isupper ((int)*s2) ? tolower ((int)*s2) : *s2);
- }
- return c1 - c2;
-}
-
-
-#ifdef XWIN_XF86CONFIG
-/*
- * Find the named option in the list.
- * @return the pointer to the option record, or NULL if not found.
- */
-
-XF86OptionPtr
-winFindOption (XF86OptionPtr list, const char *name)
-{
- while (list)
- {
- if (winNameCompare (list->opt_name, name) == 0)
- return list;
- list = list->list.next;
- }
- return NULL;
-}
-
-
-/*
- * Find the Value of an named option.
- * @return The option value or NULL if not found.
- */
-
-char *
-winFindOptionValue (XF86OptionPtr list, const char *name)
-{
- list = winFindOption (list, name);
- if (list)
- {
- if (list->opt_val)
- return list->opt_val;
- else
- return "";
- }
- return NULL;
-}
-
-
-/*
- * Parse the option.
- */
-
-static Bool
-ParseOptionValue (int scrnIndex, pointer options, OptionInfoPtr p)
-{
- char *s, *end;
-
- if ((s = winFindOptionValue (options, p->name)) != NULL)
- {
- switch (p->type)
- {
- case OPTV_INTEGER:
- if (*s == '\0')
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires an integer value\n",
- p->name);
- p->found = FALSE;
- }
- else
- {
- p->value.num = strtoul (s, &end, 0);
- if (*end == '\0')
- {
- p->found = TRUE;
- }
- else
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires an integer value\n",
- p->name);
- p->found = FALSE;
- }
- }
- break;
- case OPTV_STRING:
- if (*s == '\0')
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires an string value\n", p->name);
- p->found = FALSE;
- }
- else
- {
- p->value.str = s;
- p->found = TRUE;
- }
- break;
- case OPTV_ANYSTR:
- p->value.str = s;
- p->found = TRUE;
- break;
- case OPTV_REAL:
- if (*s == '\0')
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a floating point value\n",
- p->name);
- p->found = FALSE;
- }
- else
- {
- p->value.realnum = strtod (s, &end);
- if (*end == '\0')
- {
- p->found = TRUE;
- }
- else
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a floating point value\n",
- p->name);
- p->found = FALSE;
- }
- }
- break;
- case OPTV_BOOLEAN:
- if (GetBoolValue (p, s))
- {
- p->found = TRUE;
- }
- else
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a boolean value\n", p->name);
- p->found = FALSE;
- }
- break;
- case OPTV_PERCENT:
- if (*s == '\0')
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a percent value\n",
- p->name);
- p->found = FALSE;
- }
- else
- {
- double percent = strtod (s, &end);
-
- if (end != s && winNameCompare (end, "%"))
- {
- p->found = TRUE;
- p->value.realnum = percent;
- }
- else
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a frequency value\n",
- p->name);
- p->found = FALSE;
- }
- }
- case OPTV_FREQ:
- if (*s == '\0')
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a frequency value\n",
- p->name);
- p->found = FALSE;
- }
- else
- {
- double freq = strtod (s, &end);
- int units = 0;
-
- if (end != s)
- {
- p->found = TRUE;
- if (!winNameCompare (end, "Hz"))
- units = 1;
- else if (!winNameCompare (end, "kHz") ||
- !winNameCompare (end, "k"))
- units = 1000;
- else if (!winNameCompare (end, "MHz") ||
- !winNameCompare (end, "M"))
- units = 1000000;
- else
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a frequency value\n",
- p->name);
- p->found = FALSE;
- }
- if (p->found)
- freq *= (double) units;
- }
- else
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a frequency value\n",
- p->name);
- p->found = FALSE;
- }
- if (p->found)
- {
- p->value.freq.freq = freq;
- p->value.freq.units = units;
- }
- }
- break;
- case OPTV_NONE:
- /* Should never get here */
- p->found = FALSE;
- break;
- }
- if (p->found)
- {
- winDrvMsgVerb (scrnIndex, X_CONFIG, 2, "Option \"%s\"", p->name);
- if (!(p->type == OPTV_BOOLEAN && *s == 0))
- {
- winErrorFVerb (2, " \"%s\"", s);
- }
- winErrorFVerb (2, "\n");
- }
- }
- else if (p->type == OPTV_BOOLEAN)
- {
- /* Look for matches with options with or without a "No" prefix. */
- char *n, *newn;
- OptionInfoRec opt;
-
- n = winNormalizeName (p->name);
- if (!n)
- {
- p->found = FALSE;
- return FALSE;
- }
- if (strncmp (n, "no", 2) == 0)
- {
- newn = n + 2;
- }
- else
- {
- free (n);
- n = malloc (strlen (p->name) + 2 + 1);
- if (!n)
- {
- p->found = FALSE;
- return FALSE;
- }
- strcpy (n, "No");
- strcat (n, p->name);
- newn = n;
- }
- if ((s = winFindOptionValue (options, newn)) != NULL)
- {
- if (GetBoolValue (&opt, s))
- {
- p->value.bool = !opt.value.bool;
- p->found = TRUE;
- }
- else
- {
- winDrvMsg (scrnIndex, X_WARNING,
- "Option \"%s\" requires a boolean value\n", newn);
- p->found = FALSE;
- }
- }
- else
- {
- p->found = FALSE;
- }
- if (p->found)
- {
- winDrvMsgVerb (scrnIndex, X_CONFIG, 2, "Option \"%s\"", newn);
- if (*s != 0)
- {
- winErrorFVerb (2, " \"%s\"", s);
- }
- winErrorFVerb (2, "\n");
- }
- free (n);
- }
- else
- {
- p->found = FALSE;
- }
- return p->found;
-}
-
-
-static Bool
-configLayout (serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
- char *default_layout)
-{
-#if 0
-#pragma warn UNIMPLEMENTED
-#endif
- return TRUE;
-}
-
-
-static Bool
-configImpliedLayout (serverLayoutPtr servlayoutp,
- XF86ConfScreenPtr conf_screen)
-{
-#if 0
-#pragma warn UNIMPLEMENTED
-#endif
- return TRUE;
-}
-
-
-static Bool
-GetBoolValue (OptionInfoPtr p, const char *s)
-{
- if (*s == 0)
- {
- p->value.bool = TRUE;
- }
- else
- {
- if (winNameCompare (s, "1") == 0)
- p->value.bool = TRUE;
- else if (winNameCompare (s, "on") == 0)
- p->value.bool = TRUE;
- else if (winNameCompare (s, "true") == 0)
- p->value.bool = TRUE;
- else if (winNameCompare (s, "yes") == 0)
- p->value.bool = TRUE;
- else if (winNameCompare (s, "0") == 0)
- p->value.bool = FALSE;
- else if (winNameCompare (s, "off") == 0)
- p->value.bool = FALSE;
- else if (winNameCompare (s, "false") == 0)
- p->value.bool = FALSE;
- else if (winNameCompare (s, "no") == 0)
- p->value.bool = FALSE;
- }
- return TRUE;
-}
-#endif
-
-
-char *
-winNormalizeName (const char *s)
-{
- char *ret, *q;
- const char *p;
-
- if (s == NULL)
- return NULL;
-
- ret = malloc (strlen (s) + 1);
- for (p = s, q = ret; *p != 0; p++)
- {
- switch (*p)
- {
- case '_':
- case ' ':
- case '\t':
- continue;
- default:
- if (isupper ((int)*p))
- *q++ = tolower ((int)*p);
- else
- *q++ = *p;
- }
- }
- *q = '\0';
- return ret;
-}
-
+/* + *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. + * + *Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + *"Software"), to deal in the Software without restriction, including + *without limitation the rights to use, copy, modify, merge, publish, + *distribute, sublicense, and/or sell copies of the Software, and to + *permit persons to whom the Software is furnished to do so, subject to + *the following conditions: + * + *The above copyright notice and this permission notice shall be + *included in all copies or substantial portions of the Software. + * + *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR + *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *Except as contained in this notice, the name of the XFree86 Project + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from the XFree86 Project. + * + * Authors: Alexander Gottwald + */ + +#ifdef HAVE_XWIN_CONFIG_H +#include <xwin-config.h> +#endif +#include "win.h" +#include "winconfig.h" +#include "winmsg.h" +#include "globals.h" + +#include "xkbsrv.h" + +#ifdef XWIN_XF86CONFIG +#ifndef CONFIGPATH +#define CONFIGPATH "%A," "%R," \ + "/etc/X11/%R," "%P/etc/X11/%R," \ + "%E," "%F," \ + "/etc/X11/%F," "%P/etc/X11/%F," \ + "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \ + "%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \ + "%P/etc/X11/%X," \ + "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \ + "%P/lib/X11/%X" +#endif +#ifndef CONFIGDIRPATH +#define CONFIGDIRPATH "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \ + "%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \ + "%P/etc/X11/%X," \ + "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \ + "%P/lib/X11/%X" +#endif + +XF86ConfigPtr g_xf86configptr = NULL; +#endif + +WinCmdlineRec g_cmdline = { +#ifdef XWIN_XF86CONFIG + NULL, /* configFile */ + NULL, /* configDir */ +#endif + NULL, /* fontPath */ +#ifdef XWIN_XF86CONFIG + NULL, /* keyboard */ +#endif + NULL, /* xkbRules */ + NULL, /* xkbModel */ + NULL, /* xkbLayout */ + NULL, /* xkbVariant */ + NULL, /* xkbOptions */ + NULL, /* screenname */ + NULL, /* mousename */ + FALSE, /* emulate3Buttons */ + 0 /* emulate3Timeout */ +}; + +winInfoRec g_winInfo = { + { /* keyboard */ + 0, /* leds */ + 500, /* delay */ + 30 /* rate */ + } + , + { /* xkb */ + NULL, /* rules */ + NULL, /* model */ + NULL, /* layout */ + NULL, /* variant */ + NULL, /* options */ + } + , + { + FALSE, + 50} +}; + +#define NULL_IF_EMPTY(x) (winNameCompare(x,"")?x:NULL) + +#ifdef XWIN_XF86CONFIG +serverLayoutRec g_winConfigLayout; + +static Bool ParseOptionValue (int scrnIndex, pointer options, + OptionInfoPtr p); +static Bool configLayout (serverLayoutPtr, XF86ConfLayoutPtr, char *); +static Bool configImpliedLayout (serverLayoutPtr, XF86ConfScreenPtr); +static Bool GetBoolValue (OptionInfoPtr p, const char *s); + + +Bool +winReadConfigfile () +{ + Bool retval = TRUE; + char *filename, *dirname; + MessageType filefrom = X_DEFAULT; + MessageType dirfrom = X_DEFAULT; + char *xf86ConfigFile = NULL; + char *xf86ConfigDir = NULL; + + if (g_cmdline.configFile) + { + filefrom = X_CMDLINE; + xf86ConfigFile = g_cmdline.configFile; + } + if (g_cmdline.configDir) + { + dirfrom = X_CMDLINE; + xf86ConfigDir = g_cmdline.configDir; + } + + /* Parse config file into data structure */ + xf86initConfigFiles(); + dirname = xf86openConfigDirFiles (CONFIGDIRPATH, xf86ConfigDir, PROJECTROOT); + filename = xf86openConfigFile (CONFIGPATH, xf86ConfigFile, PROJECTROOT); + + /* Hack for backward compatibility */ + if (!filename && from == X_DEFAULT) + filename = xf86openConfigFile (CONFIGPATH, "XF86Config", PROJECTROOT); + + if (filename) + { + winMsg (from, "Using config file: \"%s\"\n", filename); + } + else + { + winMsg (X_ERROR, "Unable to locate/open config file"); + if (xf86ConfigFile) + ErrorF (": \"%s\"", xf86ConfigFile); + ErrorF ("\n"); + } + if (dirname) + { + winMsg (from, "Using config directory: \"%s\"\n", dirname); + } + else + { + winMsg (X_ERROR, "Unable to locate/open config directory"); + if (xf86ConfigDir) + ErrorF (": \"%s\"", xf86ConfigDir); + ErrorF ("\n"); + } + if (!filename && !dirname) + { + return FALSE; + } + free(filename); + free(dirname); + if ((g_xf86configptr = xf86readConfigFile ()) == NULL) + { + winMsg (X_ERROR, "Problem parsing the config file\n"); + return FALSE; + } + xf86closeConfigFile (); + + LogPrintMarkers(); + + /* set options from data structure */ + + if (g_xf86configptr->conf_layout_lst == NULL || g_cmdline.screenname != NULL) + { + if (g_cmdline.screenname == NULL) + { + winMsg (X_WARNING, + "No Layout section. Using the first Screen section.\n"); + } + if (!configImpliedLayout (&g_winConfigLayout, + g_xf86configptr->conf_screen_lst)) + { + winMsg (X_ERROR, "Unable to determine the screen layout\n"); + return FALSE; + } + } + else + { + /* Check if layout is given in the config file */ + if (g_xf86configptr->conf_flags != NULL) + { + char *dfltlayout = NULL; + pointer optlist = g_xf86configptr->conf_flags->flg_option_lst; + + if (optlist && winFindOption (optlist, "defaultserverlayout")) + dfltlayout = + winSetStrOption (optlist, "defaultserverlayout", NULL); + + if (!configLayout (&g_winConfigLayout, + g_xf86configptr->conf_layout_lst, + dfltlayout)) + { + winMsg (X_ERROR, "Unable to determine the screen layout\n"); + return FALSE; + } + } + else + { + if (!configLayout (&g_winConfigLayout, + g_xf86configptr->conf_layout_lst, + NULL)) + { + winMsg (X_ERROR, "Unable to determine the screen layout\n"); + return FALSE; + } + } + } + + /* setup special config files */ + winConfigFiles (); + return retval; +} +#endif + +/* load layout definitions */ +#include "winlayouts.h" + +/* Set the keyboard configuration */ +Bool +winConfigKeyboard (DeviceIntPtr pDevice) +{ + char layoutName[KL_NAMELENGTH]; + unsigned char layoutFriendlyName[256]; + static unsigned int layoutNum = 0; + int keyboardType; +#ifdef XWIN_XF86CONFIG + XF86ConfInputPtr kbd = NULL; + XF86ConfInputPtr input_list = NULL; + MessageType kbdfrom = X_CONFIG; +#endif + MessageType from = X_DEFAULT; + char *s = NULL; + + /* Setup defaults */ + XkbGetRulesDflts(&g_winInfo.xkb); + + /* + * Query the windows autorepeat settings and change the xserver defaults. + */ + { + int kbd_delay; + DWORD kbd_speed; + if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &kbd_delay, 0) && + SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &kbd_speed, 0)) + { + switch (kbd_delay) + { + case 0: g_winInfo.keyboard.delay = 250; break; + case 1: g_winInfo.keyboard.delay = 500; break; + case 2: g_winInfo.keyboard.delay = 750; break; + default: + case 3: g_winInfo.keyboard.delay = 1000; break; + } + g_winInfo.keyboard.rate = (kbd_speed>0)?kbd_speed:1; + winMsgVerb(X_PROBED, 1, "Setting autorepeat to delay=%d, rate=%d\n", + g_winInfo.keyboard.delay, g_winInfo.keyboard.rate); + } + } + + + keyboardType = GetKeyboardType (0); + if (keyboardType > 0 && GetKeyboardLayoutName (layoutName)) + { + WinKBLayoutPtr pLayout; + Bool bfound = FALSE; + + if (! layoutNum) + layoutNum = strtoul (layoutName, (char **)NULL, 16); + if ((layoutNum & 0xffff) == 0x411) { + /* The japanese layouts know a lot of different IMEs which all have + different layout numbers set. Map them to a single entry. + Same might apply for chinese, korean and other symbol languages + too */ + layoutNum = (layoutNum & 0xffff); + if (keyboardType == 7) + { + /* Japanese layouts have problems with key event messages + such as the lack of WM_KEYUP for Caps Lock key. + Loading US layout fixes this problem. */ + if (LoadKeyboardLayout("00000409", KLF_ACTIVATE) != NULL) + winMsg (X_INFO, "Loading US keyboard layout.\n"); + else + winMsg (X_ERROR, "LoadKeyboardLayout failed.\n"); + } + } + + /* Discover the friendly name of the current layout */ + { + HKEY regkey = NULL; + const char regtempl[] = "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\"; + char *regpath; + DWORD namesize = sizeof(layoutFriendlyName); + + regpath = malloc(sizeof(regtempl) + KL_NAMELENGTH + 1); + strcpy(regpath, regtempl); + strcat(regpath, layoutName); + + if (!RegOpenKey(HKEY_LOCAL_MACHINE, regpath, ®key)) + RegQueryValueEx(regkey, "Layout Text", 0, NULL, layoutFriendlyName, &namesize); + + /* Close registry key */ + if (regkey) + RegCloseKey (regkey); + free(regpath); + } + + winMsg (X_PROBED, "Windows keyboard layout: \"%s\" (%08x) \"%s\", type %d\n", + layoutName, layoutNum, layoutFriendlyName, keyboardType); + + for (pLayout = winKBLayouts; pLayout->winlayout != -1; pLayout++) + { + if (pLayout->winlayout != layoutNum) + continue; + if (pLayout->winkbtype > 0 && pLayout->winkbtype != keyboardType) + continue; + + bfound = TRUE; + winMsg (X_PROBED, + "Found matching XKB configuration \"%s\"\n", + pLayout->layoutname); + + winMsg(X_PROBED, + "Model = \"%s\" Layout = \"%s\"" + " Variant = \"%s\" Options = \"%s\"\n", + pLayout->xkbmodel ? pLayout->xkbmodel : "none", + pLayout->xkblayout ? pLayout->xkblayout : "none", + pLayout->xkbvariant ? pLayout->xkbvariant : "none", + pLayout->xkboptions ? pLayout->xkboptions : "none"); + + g_winInfo.xkb.model = pLayout->xkbmodel; + g_winInfo.xkb.layout = pLayout->xkblayout; + g_winInfo.xkb.variant = pLayout->xkbvariant; + g_winInfo.xkb.options = pLayout->xkboptions; + + + break; + } + + if (!bfound) + { + winMsg (X_ERROR, "Keyboardlayout \"%s\" (%s) is unknown, using X server default layout\n", layoutFriendlyName, layoutName); + } + } + + /* parse the configuration */ +#ifdef XWIN_XF86CONFIG + if (g_cmdline.keyboard) + kbdfrom = X_CMDLINE; + + /* + * Until the layout code is finished, I search for the keyboard + * device and configure the server with it. + */ + + if (g_xf86configptr != NULL) + input_list = g_xf86configptr->conf_input_lst; + + while (input_list != NULL) + { + if (winNameCompare (input_list->inp_driver, "keyboard") == 0) + { + /* Check if device name matches requested name */ + if (g_cmdline.keyboard && winNameCompare (input_list->inp_identifier, + g_cmdline.keyboard)) + continue; + kbd = input_list; + } + input_list = input_list->list.next; + } + + if (kbd != NULL) + { + + if (kbd->inp_identifier) + winMsg (kbdfrom, "Using keyboard \"%s\" as primary keyboard\n", + kbd->inp_identifier); + + if ((s = winSetStrOption(kbd->inp_option_lst, "AutoRepeat", NULL))) + { + if ((sscanf(s, "%ld %ld", &g_winInfo.keyboard.delay, + &g_winInfo.keyboard.rate) != 2) || + (g_winInfo.keyboard.delay < 1) || + (g_winInfo.keyboard.rate == 0) || + (1000 / g_winInfo.keyboard.rate) < 1) + { + winErrorFVerb (2, "\"%s\" is not a valid AutoRepeat value", s); + free(s); + return FALSE; + } + free(s); + winMsg (X_CONFIG, "AutoRepeat: %ld %ld\n", + g_winInfo.keyboard.delay, g_winInfo.keyboard.rate); + } +#endif + + s = NULL; + if (g_cmdline.xkbRules) + { + s = g_cmdline.xkbRules; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbRules", NULL); + from = X_CONFIG; + } +#endif + if (s) + { + g_winInfo.xkb.rules = NULL_IF_EMPTY (s); + winMsg (from, "XKB: rules: \"%s\"\n", s); + } + + s = NULL; + if (g_cmdline.xkbModel) + { + s = g_cmdline.xkbModel; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbModel", NULL); + from = X_CONFIG; + } +#endif + if (s) + { + g_winInfo.xkb.model = NULL_IF_EMPTY (s); + winMsg (from, "XKB: model: \"%s\"\n", s); + } + + s = NULL; + if (g_cmdline.xkbLayout) + { + s = g_cmdline.xkbLayout; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbLayout", NULL); + from = X_CONFIG; + } +#endif + if (s) + { + g_winInfo.xkb.layout = NULL_IF_EMPTY (s); + winMsg (from, "XKB: layout: \"%s\"\n", s); + } + + s = NULL; + if (g_cmdline.xkbVariant) + { + s = g_cmdline.xkbVariant; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbVariant", NULL); + from = X_CONFIG; + } +#endif + if (s) + { + g_winInfo.xkb.variant = NULL_IF_EMPTY (s); + winMsg (from, "XKB: variant: \"%s\"\n", s); + } + + s = NULL; + if (g_cmdline.xkbOptions) + { + s = g_cmdline.xkbOptions; + from = X_CMDLINE; + } +#ifdef XWIN_XF86CONFIG + else + { + s = winSetStrOption (kbd->inp_option_lst, "XkbOptions", NULL); + from = X_CONFIG; + } +#endif + if (s) + { + g_winInfo.xkb.options = NULL_IF_EMPTY (s); + winMsg (from, "XKB: options: \"%s\"\n", s); + } + +#ifdef XWIN_XF86CONFIG + } +#endif + + return TRUE; +} + + +#ifdef XWIN_XF86CONFIG +Bool +winConfigMouse (DeviceIntPtr pDevice) +{ + MessageType mousefrom = X_CONFIG; + + XF86ConfInputPtr mouse = NULL; + XF86ConfInputPtr input_list = NULL; + + if (g_cmdline.mouse) + mousefrom = X_CMDLINE; + + if (g_xf86configptr != NULL) + input_list = g_xf86configptr->conf_input_lst; + + while (input_list != NULL) + { + if (winNameCompare (input_list->inp_driver, "mouse") == 0) + { + /* Check if device name matches requested name */ + if (g_cmdline.mouse && winNameCompare (input_list->inp_identifier, + g_cmdline.mouse)) + continue; + mouse = input_list; + } + input_list = input_list->list.next; + } + + if (mouse != NULL) + { + if (mouse->inp_identifier) + winMsg (mousefrom, "Using pointer \"%s\" as primary pointer\n", + mouse->inp_identifier); + + g_winInfo.pointer.emulate3Buttons = + winSetBoolOption (mouse->inp_option_lst, "Emulate3Buttons", FALSE); + if (g_cmdline.emulate3buttons) + g_winInfo.pointer.emulate3Buttons = g_cmdline.emulate3buttons; + + g_winInfo.pointer.emulate3Timeout = + winSetIntOption (mouse->inp_option_lst, "Emulate3Timeout", 50); + if (g_cmdline.emulate3timeout) + g_winInfo.pointer.emulate3Timeout = g_cmdline.emulate3timeout; + } + else + { + winMsg (X_ERROR, "No primary pointer configured\n"); + winMsg (X_DEFAULT, "Using compiletime defaults for pointer\n"); + } + + return TRUE; +} + + +Bool +winConfigFiles () +{ + MessageType from; + XF86ConfFilesPtr filesptr = NULL; + + /* set some shortcuts */ + if (g_xf86configptr != NULL) + { + filesptr = g_xf86configptr->conf_files; + } + + + /* Fontpath */ + from = X_DEFAULT; + + if (g_cmdline.fontPath) + { + from = X_CMDLINE; + defaultFontPath = g_cmdline.fontPath; + } + else if (filesptr != NULL && filesptr->file_fontpath) + { + from = X_CONFIG; + defaultFontPath = strdup (filesptr->file_fontpath); + } + winMsg (from, "FontPath set to \"%s\"\n", defaultFontPath); + + return TRUE; +} +#else +Bool +winConfigFiles (void) +{ + /* Fontpath */ + if (g_cmdline.fontPath) + { + defaultFontPath = g_cmdline.fontPath; + winMsg (X_CMDLINE, "FontPath set to \"%s\"\n", defaultFontPath); + } + + return TRUE; +} +#endif + + +Bool +winConfigOptions (void) +{ + return TRUE; +} + + +Bool +winConfigScreens (void) +{ + return TRUE; +} + + +#ifdef XWIN_XF86CONFIG +char * +winSetStrOption (pointer optlist, const char *name, char *deflt) +{ + OptionInfoRec o; + + o.name = name; + o.type = OPTV_STRING; + if (ParseOptionValue (-1, optlist, &o)) + deflt = o.value.str; + if (deflt) + return strdup (deflt); + else + return NULL; +} + + +int +winSetBoolOption (pointer optlist, const char *name, int deflt) +{ + OptionInfoRec o; + + o.name = name; + o.type = OPTV_BOOLEAN; + if (ParseOptionValue (-1, optlist, &o)) + deflt = o.value.bool; + return deflt; +} + + +int +winSetIntOption (pointer optlist, const char *name, int deflt) +{ + OptionInfoRec o; + + o.name = name; + o.type = OPTV_INTEGER; + if (ParseOptionValue (-1, optlist, &o)) + deflt = o.value.num; + return deflt; +} + + +double +winSetRealOption (pointer optlist, const char *name, double deflt) +{ + OptionInfoRec o; + + o.name = name; + o.type = OPTV_REAL; + if (ParseOptionValue (-1, optlist, &o)) + deflt = o.value.realnum; + return deflt; +} + +double +winSetPercentOption (pointer optlist, const char *name, double deflt) +{ + OptionInfoRec o; + + o.name = name; + o.type = OPTV_PERCENT; + if (ParseOptionValue (-1, optlist, &o)) + deflt = o.value.realnum; + return deflt; +} +#endif + + +/* + * Compare two strings for equality. This is caseinsensitive and + * The characters '_', ' ' (space) and '\t' (tab) are treated as + * not existing. + */ + +int +winNameCompare (const char *s1, const char *s2) +{ + char c1, c2; + + if (!s1 || *s1 == 0) + { + if (!s2 || *s2 == 0) + return 0; + else + return 1; + } + + while (*s1 == '_' || *s1 == ' ' || *s1 == '\t') + s1++; + while (*s2 == '_' || *s2 == ' ' || *s2 == '\t') + s2++; + + c1 = (isupper ((int)*s1) ? tolower ((int)*s1) : *s1); + c2 = (isupper ((int)*s2) ? tolower ((int)*s2) : *s2); + + while (c1 == c2) + { + if (c1 == 0) + return 0; + s1++; + s2++; + + while (*s1 == '_' || *s1 == ' ' || *s1 == '\t') + s1++; + while (*s2 == '_' || *s2 == ' ' || *s2 == '\t') + s2++; + + c1 = (isupper ((int)*s1) ? tolower ((int)*s1) : *s1); + c2 = (isupper ((int)*s2) ? tolower ((int)*s2) : *s2); + } + return c1 - c2; +} + + +#ifdef XWIN_XF86CONFIG +/* + * Find the named option in the list. + * @return the pointer to the option record, or NULL if not found. + */ + +XF86OptionPtr +winFindOption (XF86OptionPtr list, const char *name) +{ + while (list) + { + if (winNameCompare (list->opt_name, name) == 0) + return list; + list = list->list.next; + } + return NULL; +} + + +/* + * Find the Value of an named option. + * @return The option value or NULL if not found. + */ + +char * +winFindOptionValue (XF86OptionPtr list, const char *name) +{ + list = winFindOption (list, name); + if (list) + { + if (list->opt_val) + return list->opt_val; + else + return ""; + } + return NULL; +} + + +/* + * Parse the option. + */ + +static Bool +ParseOptionValue (int scrnIndex, pointer options, OptionInfoPtr p) +{ + char *s, *end; + + if ((s = winFindOptionValue (options, p->name)) != NULL) + { + switch (p->type) + { + case OPTV_INTEGER: + if (*s == '\0') + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires an integer value\n", + p->name); + p->found = FALSE; + } + else + { + p->value.num = strtoul (s, &end, 0); + if (*end == '\0') + { + p->found = TRUE; + } + else + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires an integer value\n", + p->name); + p->found = FALSE; + } + } + break; + case OPTV_STRING: + if (*s == '\0') + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires an string value\n", p->name); + p->found = FALSE; + } + else + { + p->value.str = s; + p->found = TRUE; + } + break; + case OPTV_ANYSTR: + p->value.str = s; + p->found = TRUE; + break; + case OPTV_REAL: + if (*s == '\0') + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a floating point value\n", + p->name); + p->found = FALSE; + } + else + { + p->value.realnum = strtod (s, &end); + if (*end == '\0') + { + p->found = TRUE; + } + else + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a floating point value\n", + p->name); + p->found = FALSE; + } + } + break; + case OPTV_BOOLEAN: + if (GetBoolValue (p, s)) + { + p->found = TRUE; + } + else + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a boolean value\n", p->name); + p->found = FALSE; + } + break; + case OPTV_PERCENT: + if (*s == '\0') + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a percent value\n", + p->name); + p->found = FALSE; + } + else + { + double percent = strtod (s, &end); + + if (end != s && winNameCompare (end, "%")) + { + p->found = TRUE; + p->value.realnum = percent; + } + else + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a frequency value\n", + p->name); + p->found = FALSE; + } + } + case OPTV_FREQ: + if (*s == '\0') + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a frequency value\n", + p->name); + p->found = FALSE; + } + else + { + double freq = strtod (s, &end); + int units = 0; + + if (end != s) + { + p->found = TRUE; + if (!winNameCompare (end, "Hz")) + units = 1; + else if (!winNameCompare (end, "kHz") || + !winNameCompare (end, "k")) + units = 1000; + else if (!winNameCompare (end, "MHz") || + !winNameCompare (end, "M")) + units = 1000000; + else + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a frequency value\n", + p->name); + p->found = FALSE; + } + if (p->found) + freq *= (double) units; + } + else + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a frequency value\n", + p->name); + p->found = FALSE; + } + if (p->found) + { + p->value.freq.freq = freq; + p->value.freq.units = units; + } + } + break; + case OPTV_NONE: + /* Should never get here */ + p->found = FALSE; + break; + } + if (p->found) + { + winDrvMsgVerb (scrnIndex, X_CONFIG, 2, "Option \"%s\"", p->name); + if (!(p->type == OPTV_BOOLEAN && *s == 0)) + { + winErrorFVerb (2, " \"%s\"", s); + } + winErrorFVerb (2, "\n"); + } + } + else if (p->type == OPTV_BOOLEAN) + { + /* Look for matches with options with or without a "No" prefix. */ + char *n, *newn; + OptionInfoRec opt; + + n = winNormalizeName (p->name); + if (!n) + { + p->found = FALSE; + return FALSE; + } + if (strncmp (n, "no", 2) == 0) + { + newn = n + 2; + } + else + { + free (n); + n = malloc (strlen (p->name) + 2 + 1); + if (!n) + { + p->found = FALSE; + return FALSE; + } + strcpy (n, "No"); + strcat (n, p->name); + newn = n; + } + if ((s = winFindOptionValue (options, newn)) != NULL) + { + if (GetBoolValue (&opt, s)) + { + p->value.bool = !opt.value.bool; + p->found = TRUE; + } + else + { + winDrvMsg (scrnIndex, X_WARNING, + "Option \"%s\" requires a boolean value\n", newn); + p->found = FALSE; + } + } + else + { + p->found = FALSE; + } + if (p->found) + { + winDrvMsgVerb (scrnIndex, X_CONFIG, 2, "Option \"%s\"", newn); + if (*s != 0) + { + winErrorFVerb (2, " \"%s\"", s); + } + winErrorFVerb (2, "\n"); + } + free (n); + } + else + { + p->found = FALSE; + } + return p->found; +} + + +static Bool +configLayout (serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, + char *default_layout) +{ +#if 0 +#pragma warn UNIMPLEMENTED +#endif + return TRUE; +} + + +static Bool +configImpliedLayout (serverLayoutPtr servlayoutp, + XF86ConfScreenPtr conf_screen) +{ +#if 0 +#pragma warn UNIMPLEMENTED +#endif + return TRUE; +} + + +static Bool +GetBoolValue (OptionInfoPtr p, const char *s) +{ + if (*s == 0) + { + p->value.bool = TRUE; + } + else + { + if (winNameCompare (s, "1") == 0) + p->value.bool = TRUE; + else if (winNameCompare (s, "on") == 0) + p->value.bool = TRUE; + else if (winNameCompare (s, "true") == 0) + p->value.bool = TRUE; + else if (winNameCompare (s, "yes") == 0) + p->value.bool = TRUE; + else if (winNameCompare (s, "0") == 0) + p->value.bool = FALSE; + else if (winNameCompare (s, "off") == 0) + p->value.bool = FALSE; + else if (winNameCompare (s, "false") == 0) + p->value.bool = FALSE; + else if (winNameCompare (s, "no") == 0) + p->value.bool = FALSE; + } + return TRUE; +} +#endif + + +char * +winNormalizeName (const char *s) +{ + char *ret, *q; + const char *p; + + if (s == NULL) + return NULL; + + ret = malloc (strlen (s) + 1); + for (p = s, q = ret; *p != 0; p++) + { + switch (*p) + { + case '_': + case ' ': + case '\t': + continue; + default: + if (isupper ((int)*p)) + *q++ = tolower ((int)*p); + else + *q++ = *p; + } + } + *q = '\0'; + return ret; +} + diff --git a/xorg-server/include/dix-config.h.in b/xorg-server/include/dix-config.h.in index 7d6cb966c..e1d3a9eaa 100644 --- a/xorg-server/include/dix-config.h.in +++ b/xorg-server/include/dix-config.h.in @@ -190,6 +190,9 @@ /* Define to 1 if you have the <string.h> header file. */ #undef HAVE_STRING_H +/* Define to 1 if you have the `strndup' function. */ +#undef HAVE_STRNDUP + /* Define to 1 if you have the `strrchr' function. */ #undef HAVE_STRRCHR diff --git a/xorg-server/include/exevents.h b/xorg-server/include/exevents.h index 720fb2e5a..12ea37885 100644 --- a/xorg-server/include/exevents.h +++ b/xorg-server/include/exevents.h @@ -126,7 +126,7 @@ extern _X_EXPORT void XIUnregisterPropertyHandler( ); extern _X_EXPORT Atom XIGetKnownProperty( - char* name + const char* name ); extern _X_EXPORT DeviceIntPtr XIGetDevice(xEvent *ev); diff --git a/xorg-server/include/extension.h b/xorg-server/include/extension.h index 29a11c300..ee6260eb5 100644 --- a/xorg-server/include/extension.h +++ b/xorg-server/include/extension.h @@ -54,9 +54,9 @@ extern _X_EXPORT unsigned short StandardMinorOpcode(ClientPtr /*client*/); extern _X_EXPORT unsigned short MinorOpcodeOfRequest(ClientPtr /*client*/); -extern _X_EXPORT Bool EnableDisableExtension(char *name, Bool enable); +extern _X_EXPORT Bool EnableDisableExtension(const char *name, Bool enable); -extern _X_EXPORT void EnableDisableExtensionError(char *name, Bool enable); +extern _X_EXPORT void EnableDisableExtensionError(const char *name, Bool enable); extern _X_EXPORT void InitExtensions(int argc, char **argv); diff --git a/xorg-server/include/extinit.h b/xorg-server/include/extinit.h index c3aa7b681..8e47beb48 100644 --- a/xorg-server/include/extinit.h +++ b/xorg-server/include/extinit.h @@ -41,7 +41,7 @@ extern _X_EXPORT void AssignTypeAndName ( DeviceIntPtr /* dev */, Atom /* type */, - char * /* name */ + const char * /* name */ ); #endif /* EXTINIT_H */ diff --git a/xorg-server/include/extnsionst.h b/xorg-server/include/extnsionst.h index 92790b38f..aeefa9918 100644 --- a/xorg-server/include/extnsionst.h +++ b/xorg-server/include/extnsionst.h @@ -1,112 +1,112 @@ -/***********************************************************
-
-Copyright 1987, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-#ifndef EXTENSIONSTRUCT_H
-#define EXTENSIONSTRUCT_H
-
-#include "dix.h"
-#include "misc.h"
-#include "screenint.h"
-#include "extension.h"
-#include "gc.h"
-#include "privates.h"
-
-typedef struct _ExtensionEntry {
- int index;
- void (* CloseDown)( /* called at server shutdown */
- struct _ExtensionEntry * /* extension */);
- char *name; /* extension name */
- int base; /* base request number */
- int eventBase;
- int eventLast;
- int errorBase;
- int errorLast;
- int num_aliases;
- char **aliases;
- pointer extPrivate;
- unsigned short (* MinorOpcode)( /* called for errors */
- ClientPtr /* client */);
- PrivateRec *devPrivates;
-} ExtensionEntry;
-
-/*
- * The arguments may be different for extension event swapping functions.
- * Deal with this by casting when initializing the event's EventSwapVector[]
- * entries.
- */
-typedef void (*EventSwapPtr) (xEvent *, xEvent *);
-
-extern _X_EXPORT EventSwapPtr EventSwapVector[128];
-
-extern _X_EXPORT void NotImplemented ( /* FIXME: this may move to another file... */
- xEvent *,
- xEvent *) _X_NORETURN;
-
-#define SetGCVector(pGC, VectorElement, NewRoutineAddress, Atom) \
- pGC->VectorElement = NewRoutineAddress;
-
-#define GetGCValue(pGC, GCElement) (pGC->GCElement)
-
-extern _X_EXPORT ExtensionEntry *AddExtension(
- char* /*name*/,
- int /*NumEvents*/,
- int /*NumErrors*/,
- int (* /*MainProc*/)(ClientPtr /*client*/),
- int (* /*SwappedMainProc*/)(ClientPtr /*client*/),
- void (* /*CloseDownProc*/)(ExtensionEntry * /*extension*/),
- unsigned short (* /*MinorOpcodeProc*/)(ClientPtr /*client*/)
-);
-
-extern _X_EXPORT Bool AddExtensionAlias(
- char* /*alias*/,
- ExtensionEntry * /*extension*/);
-
-extern _X_EXPORT ExtensionEntry *CheckExtension(const char *extname);
-extern _X_EXPORT ExtensionEntry *GetExtensionEntry(int major);
-
-#endif /* EXTENSIONSTRUCT_H */
-
+/*********************************************************** + +Copyright 1987, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + + +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ + +#ifndef EXTENSIONSTRUCT_H +#define EXTENSIONSTRUCT_H + +#include "dix.h" +#include "misc.h" +#include "screenint.h" +#include "extension.h" +#include "gc.h" +#include "privates.h" + +typedef struct _ExtensionEntry { + int index; + void (* CloseDown)( /* called at server shutdown */ + struct _ExtensionEntry * /* extension */); + char *name; /* extension name */ + int base; /* base request number */ + int eventBase; + int eventLast; + int errorBase; + int errorLast; + int num_aliases; + char **aliases; + pointer extPrivate; + unsigned short (* MinorOpcode)( /* called for errors */ + ClientPtr /* client */); + PrivateRec *devPrivates; +} ExtensionEntry; + +/* + * The arguments may be different for extension event swapping functions. + * Deal with this by casting when initializing the event's EventSwapVector[] + * entries. + */ +typedef void (*EventSwapPtr) (xEvent *, xEvent *); + +extern _X_EXPORT EventSwapPtr EventSwapVector[128]; + +extern _X_EXPORT void NotImplemented ( /* FIXME: this may move to another file... */ + xEvent *, + xEvent *) _X_NORETURN; + +#define SetGCVector(pGC, VectorElement, NewRoutineAddress, Atom) \ + pGC->VectorElement = NewRoutineAddress; + +#define GetGCValue(pGC, GCElement) (pGC->GCElement) + +extern _X_EXPORT ExtensionEntry *AddExtension( + const char* /*name*/, + int /*NumEvents*/, + int /*NumErrors*/, + int (* /*MainProc*/)(ClientPtr /*client*/), + int (* /*SwappedMainProc*/)(ClientPtr /*client*/), + void (* /*CloseDownProc*/)(ExtensionEntry * /*extension*/), + unsigned short (* /*MinorOpcodeProc*/)(ClientPtr /*client*/) +); + +extern _X_EXPORT Bool AddExtensionAlias( + const char* /*alias*/, + ExtensionEntry * /*extension*/); + +extern _X_EXPORT ExtensionEntry *CheckExtension(const char *extname); +extern _X_EXPORT ExtensionEntry *GetExtensionEntry(int major); + +#endif /* EXTENSIONSTRUCT_H */ + diff --git a/xorg-server/include/input.h b/xorg-server/include/input.h index 9ef726f4e..87bb2aa01 100644 --- a/xorg-server/include/input.h +++ b/xorg-server/include/input.h @@ -505,7 +505,7 @@ extern _X_EXPORT DeviceIntPtr GetPairedDevice(DeviceIntPtr kbd); extern DeviceIntPtr GetMaster(DeviceIntPtr dev, int type); extern _X_EXPORT int AllocDevicePair(ClientPtr client, - char* name, + const char* name, DeviceIntPtr* ptr, DeviceIntPtr* keybd, DeviceProc ptr_proc, @@ -521,7 +521,7 @@ extern _X_EXPORT int generate_modkeymap(ClientPtr client, DeviceIntPtr dev, extern int change_modmap(ClientPtr client, DeviceIntPtr dev, KeyCode *map, int max_keys_per_mod); extern int AllocXTestDevice(ClientPtr client, - char* name, + const char* name, DeviceIntPtr* ptr, DeviceIntPtr* keybd, DeviceIntPtr master_ptr, diff --git a/xorg-server/include/misc.h b/xorg-server/include/misc.h index dc039113d..2e8dd1b89 100644 --- a/xorg-server/include/misc.h +++ b/xorg-server/include/misc.h @@ -269,7 +269,7 @@ static inline void wrong_size(void) } #endif -#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C < 0x590))) +#if !(defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))) static inline int __builtin_constant_p(int x) { return 0; diff --git a/xorg-server/include/os.h b/xorg-server/include/os.h index 823fe5d29..22983814b 100644 --- a/xorg-server/include/os.h +++ b/xorg-server/include/os.h @@ -307,10 +307,10 @@ extern _X_EXPORT void OsReleaseSignals (void); extern _X_EXPORT void OsAbort (void) _X_NORETURN; #if !defined(WIN32) -extern _X_EXPORT int System(char *); -extern _X_EXPORT pointer Popen(char *, char *); +extern _X_EXPORT int System(const char *); +extern _X_EXPORT pointer Popen(const char *, const char *); extern _X_EXPORT int Pclose(pointer); -extern _X_EXPORT pointer Fopen(char *, char *); +extern _X_EXPORT pointer Fopen(const char *, const char *); extern _X_EXPORT int Fclose(pointer); #else #define System(a) system(a) @@ -492,6 +492,10 @@ extern _X_EXPORT size_t strlcpy(char *dst, const char *src, size_t siz); extern _X_EXPORT size_t strlcat(char *dst, const char *src, size_t siz); #endif +#ifndef HAVE_STRNDUP +extern _X_EXPORT char * strndup(const char *str, size_t n); +#endif + /* Logging. */ typedef enum _LogParameter { XLOG_FLUSH, diff --git a/xorg-server/include/xkbfile.h b/xorg-server/include/xkbfile.h index a4b99ee07..db7dbfa40 100644 --- a/xorg-server/include/xkbfile.h +++ b/xorg-server/include/xkbfile.h @@ -136,7 +136,7 @@ extern _X_EXPORT char * XkbConfigText( unsigned /* format */ ); -extern _X_EXPORT char * XkbSIMatchText( +extern _X_EXPORT const char * XkbSIMatchText( unsigned /* type */, unsigned /* format */ ); @@ -161,7 +161,7 @@ extern _X_EXPORT char * XkbDoodadTypeText( unsigned /* format */ ); -extern _X_EXPORT char * XkbActionTypeText( +extern _X_EXPORT const char * XkbActionTypeText( unsigned /* type */, unsigned /* format */ ); diff --git a/xorg-server/include/xkbsrv.h b/xorg-server/include/xkbsrv.h index c6f86f544..7b0053486 100644 --- a/xorg-server/include/xkbsrv.h +++ b/xorg-server/include/xkbsrv.h @@ -296,8 +296,8 @@ extern void xkbUnwrapProc(DeviceIntPtr, DeviceHandleProc, pointer); extern _X_EXPORT int XkbReqCode; extern _X_EXPORT int XkbEventBase; extern _X_EXPORT int XkbKeyboardErrorCode; -extern _X_EXPORT char * XkbBaseDirectory; -extern _X_EXPORT char * XkbBinDirectory; +extern _X_EXPORT const char * XkbBaseDirectory; +extern _X_EXPORT const char * XkbBinDirectory; extern _X_EXPORT CARD32 xkbDebugFlags; diff --git a/xorg-server/mi/miinitext.c b/xorg-server/mi/miinitext.c index 4499f377c..883699259 100644 --- a/xorg-server/mi/miinitext.c +++ b/xorg-server/mi/miinitext.c @@ -268,7 +268,7 @@ extern void GEExtensionInit(INITARGS); * configurable extensions. */ typedef struct { - char *name; + const char *name; Bool *disablePtr; } ExtensionToggle; @@ -337,7 +337,7 @@ static ExtensionToggle ExtensionToggleList[] = { NULL, NULL } }; -Bool EnableDisableExtension(char *name, Bool enable) +Bool EnableDisableExtension(const char *name, Bool enable) { ExtensionToggle *ext = &ExtensionToggleList[0]; @@ -357,7 +357,7 @@ Bool EnableDisableExtension(char *name, Bool enable) return FALSE; } -void EnableDisableExtensionError(char *name, Bool enable) +void EnableDisableExtensionError(const char *name, Bool enable) { ExtensionToggle *ext = &ExtensionToggleList[0]; Bool found = FALSE; diff --git a/xorg-server/os/Makefile.am b/xorg-server/os/Makefile.am index ef9ecddcf..8dd809531 100644 --- a/xorg-server/os/Makefile.am +++ b/xorg-server/os/Makefile.am @@ -41,6 +41,10 @@ if NEED_STRLCAT libos_la_SOURCES += $(STRLCAT_SRCS) endif +if NEED_STRNDUP +libos_la_SOURCES += $(STRNDUP_SRCS) +endif + EXTRA_DIST = $(SECURERPC_SRCS) $(INTERNALMALLOC_SRCS) \ $(XDMCP_SRCS) $(STRLCAT_SRCS) diff --git a/xorg-server/os/access.c b/xorg-server/os/access.c index b7b19279f..159894007 100644 --- a/xorg-server/os/access.c +++ b/xorg-server/os/access.c @@ -528,7 +528,7 @@ DefineSelf (int fd) ifn.lifn_family = AF_UNSPEC; ifn.lifn_flags = 0; if (ioctl (fd, SIOCGLIFNUM, (char *) &ifn) < 0) - Error ("Getting interface count"); + ErrorF ("Getting interface count: %s\n", strerror(errno)); if (len < (ifn.lifn_count * sizeof(struct lifreq))) { len = ifn.lifn_count * sizeof(struct lifreq); bufptr = malloc(len); @@ -558,7 +558,7 @@ DefineSelf (int fd) #endif if (ifioctl (fd, IFC_IOCTL_REQ, (pointer) &ifc) < 0) - Error ("Getting interface configuration (4)"); + ErrorF ("Getting interface configuration (4): %s\n", strerror(errno)); cplim = (char *) IFC_IFC_REQ + IFC_IFC_LEN; @@ -1756,8 +1756,7 @@ siHostnameAddrMatch(int family, pointer addr, int len, if (siAddrLen >= sizeof(hostname)) return FALSE; - strncpy(hostname, siAddr, siAddrLen); - hostname[siAddrLen] = '\0'; + strlcpy(hostname, siAddr, siAddrLen + 1); if (getaddrinfo(hostname, NULL, NULL, &addresses) == 0) { for (a = addresses ; a != NULL ; a = a->ai_next) { @@ -1786,8 +1785,7 @@ siHostnameAddrMatch(int family, pointer addr, int len, if (siAddrLen >= sizeof(hostname)) return FALSE; - strncpy(hostname, siAddr, siAddrLen); - hostname[siAddrLen] = '\0'; + strlcpy(hostname, siAddr, siAddrLen + 1); if ((hp = _XGethostbyname(hostname, hparams)) != NULL) { #ifdef h_addr /* new 4.3bsd version of gethostent */ diff --git a/xorg-server/os/client.c b/xorg-server/os/client.c index b5349778b..4aec097e1 100644 --- a/xorg-server/os/client.c +++ b/xorg-server/os/client.c @@ -149,13 +149,7 @@ void DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs) cmdsize = strlen(path) + 1; if (cmdname) { - char *name = malloc(cmdsize); - if (name) - { - strncpy(name, path, cmdsize); - name[cmdsize - 1] = '\0'; - *cmdname = name; - } + *cmdname = strdup(path); } /* Construct the arguments for client process. */ diff --git a/xorg-server/os/connection.c b/xorg-server/os/connection.c index b339f4e96..c5fc5a07e 100644 --- a/xorg-server/os/connection.c +++ b/xorg-server/os/connection.c @@ -386,7 +386,7 @@ CreateWellKnownSockets(void) FD_ZERO (&WellKnownConnections); - sprintf (port, "%d", atoi (display)); + snprintf (port, sizeof(port), "%d", atoi (display)); if ((_XSERVTransMakeAllCOTSServerListeners (port, &partial, &ListenTransCount, &ListenTransConns) >= 0) && @@ -499,7 +499,6 @@ AuthAudit (ClientPtr client, Bool letin, unsigned int proto_n, char *auth_proto, int auth_id) { char addr[128]; - char *out = addr; char client_uid_string[64]; LocalClientCredRec *lcc; #ifdef XSERVER_DTRACE @@ -508,7 +507,7 @@ AuthAudit (ClientPtr client, Bool letin, #endif if (!len) - strcpy(out, "local host"); + strlcpy(addr, "local host", sizeof(addr)); else switch (saddr->sa_family) { @@ -516,11 +515,11 @@ AuthAudit (ClientPtr client, Bool letin, #if defined(UNIXCONN) || defined(LOCALCONN) case AF_UNIX: #endif - strcpy(out, "local host"); + strlcpy(addr, "local host", sizeof(addr)); break; #if defined(TCPCONN) || defined(STREAMSCONN) case AF_INET: - sprintf(out, "IP %s", + snprintf(addr, sizeof(addr), "IP %s", inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr)); break; #if defined(IPv6) && defined(AF_INET6) @@ -528,13 +527,13 @@ AuthAudit (ClientPtr client, Bool letin, char ipaddr[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, &((struct sockaddr_in6 *) saddr)->sin6_addr, ipaddr, sizeof(ipaddr)); - sprintf(out, "IP %s", ipaddr); + snprintf(addr, sizeof(addr), "IP %s", ipaddr); } break; #endif #endif default: - strcpy(out, "unknown address"); + strlcpy(addr, "unknown address", sizeof(addr)); } if (GetLocalClientCreds(client, &lcc) != -1) { @@ -1267,7 +1266,7 @@ void ListenOnOpenFD(int fd, int noxauth) { strcpy(port, display_env); } else { /* Just some default so things don't break and die. */ - sprintf(port, ":%d", atoi(display)); + snprintf(port, sizeof(port), ":%d", atoi(display)); } /* Make our XtransConnInfo diff --git a/xorg-server/os/log.c b/xorg-server/os/log.c index 9ee32c93d..671a01bb6 100644 --- a/xorg-server/os/log.c +++ b/xorg-server/os/log.c @@ -371,7 +371,7 @@ LogVMessageVerb(MessageType type, int verb, const char *format, va_list args) { const char *type_str; char tmpFormat[1024]; - char *new_format; + const char *new_format; type_str = LogMessageTypeVerbString(type, verb); if (!type_str) diff --git a/xorg-server/os/osinit.c b/xorg-server/os/osinit.c index 69e4933e6..acea682ce 100644 --- a/xorg-server/os/osinit.c +++ b/xorg-server/os/osinit.c @@ -1,308 +1,308 @@ -/***********************************************************
-
-Copyright 1987, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <stdio.h>
-#include <X11/X.h>
-#include "os.h"
-#include "osdep.h"
-#include <X11/Xos.h>
-#include <signal.h>
-#include <errno.h>
-#ifdef HAVE_DLFCN_H
-# include <dlfcn.h>
-#endif
-#ifdef HAVE_BACKTRACE
-#include <execinfo.h>
-#endif
-
-#include "misc.h"
-
-#include "dixstruct.h"
-
-
-#if !defined(SYSV) && !defined(WIN32)
-#include <sys/resource.h>
-#endif
-
-#ifndef ADMPATH
-#define ADMPATH "/usr/adm/X%smsgs"
-#endif
-
-extern char *display;
-#ifdef RLIMIT_DATA
-int limitDataSpace = -1;
-#endif
-#ifdef RLIMIT_STACK
-int limitStackSpace = -1;
-#endif
-#ifdef RLIMIT_NOFILE
-int limitNoFile = -1;
-#endif
-
-static OsSigWrapperPtr OsSigWrapper = NULL;
-
-OsSigWrapperPtr
-OsRegisterSigWrapper(OsSigWrapperPtr newSigWrapper)
-{
- OsSigWrapperPtr oldSigWrapper = OsSigWrapper;
-
- OsSigWrapper = newSigWrapper;
-
- return oldSigWrapper;
-}
-
-/*
- * OsSigHandler --
- * Catch unexpected signals and exit or continue cleanly.
- */
-static void
-#ifdef SA_SIGINFO
-OsSigHandler(int signo, siginfo_t *sip, void *unused)
-#else
-OsSigHandler(int signo)
-#endif
-{
-#ifdef RTLD_DI_SETSIGNAL
- const char *dlerr = dlerror();
-
- if (dlerr) {
- LogMessage(X_ERROR, "Dynamic loader error: %s\n", dlerr);
- }
-#endif /* RTLD_DI_SETSIGNAL */
-
- if (OsSigWrapper != NULL) {
- if (OsSigWrapper(signo) == 0) {
- /* ddx handled signal and wants us to continue */
- return;
- }
- }
-
- /* log, cleanup, and abort */
- xorg_backtrace();
-
-#ifdef SA_SIGINFO
- if (sip->si_code == SI_USER) {
- ErrorF("Recieved signal %d sent by process %ld, uid %ld\n",
- signo, (long) sip->si_pid, (long) sip->si_uid);
- } else {
- switch (signo) {
- case SIGSEGV:
- case SIGBUS:
- case SIGILL:
- case SIGFPE:
- ErrorF("%s at address %p\n", strsignal(signo), sip->si_addr);
- }
- }
-#endif
-
- FatalError("Caught signal %d (%s). Server aborting\n",
- signo, strsignal(signo));
-}
-
-void
-OsInit(void)
-{
- static Bool been_here = FALSE;
- static char* devnull = "/dev/null";
- char fname[PATH_MAX];
-
- if (!been_here) {
- struct sigaction act, oact;
- int i;
- int siglist[] = { SIGSEGV, SIGQUIT, SIGILL, SIGFPE, SIGBUS,
- SIGSYS,
- SIGXCPU,
- SIGXFSZ,
-#ifdef SIGEMT
- SIGEMT,
-#endif
- 0 /* must be last */ };
- sigemptyset(&act.sa_mask);
-#ifdef SA_SIGINFO
- act.sa_sigaction = OsSigHandler;
- act.sa_flags = SA_SIGINFO;
-#else
- act.sa_handler = OsSigHandler;
- act.sa_flags = 0;
-#endif
- for (i = 0; siglist[i] != 0; i++) {
- if (sigaction(siglist[i], &act, &oact)) {
- ErrorF("failed to install signal handler for signal %d: %s\n",
- siglist[i], strerror(errno));
- }
- }
-#ifdef HAVE_BACKTRACE
- /*
- * initialize the backtracer, since the ctor calls dlopen(), which
- * calls malloc(), which isn't signal-safe.
- */
- do {
- void *array;
- backtrace(&array, 1);
- } while (0);
-#endif
-
-#ifdef RTLD_DI_SETSIGNAL
- /* Tell runtime linker to send a signal we can catch instead of SIGKILL
- * for failures to load libraries/modules at runtime so we can clean up
- * after ourselves.
- */
- int failure_signal = SIGQUIT;
- dlinfo(RTLD_SELF, RTLD_DI_SETSIGNAL, &failure_signal);
-#endif
-
-#if !defined(__CYGWIN__)
- fclose(stdin);
- fclose(stdout);
-#endif
- /*
- * If a write of zero bytes to stderr returns non-zero, i.e. -1,
- * then writing to stderr failed, and we'll write somewhere else
- * instead. (Apparently this never happens in the Real World.)
- */
- if (write (2, fname, 0) == -1)
- {
- FILE *err;
-
- if (strlen (display) + strlen (ADMPATH) + 1 < sizeof fname)
- sprintf (fname, ADMPATH, display);
- else
- strcpy (fname, devnull);
- /*
- * uses stdio to avoid os dependencies here,
- * a real os would use
- * open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666)
- */
- if (!(err = fopen (fname, "a+")))
- err = fopen (devnull, "w");
- if (err && (fileno(err) != 2)) {
- dup2 (fileno (err), 2);
- fclose (err);
- }
-#if defined(SYSV) || defined(SVR4) || defined(WIN32) || defined(__CYGWIN__)
- {
- static char buf[BUFSIZ];
- setvbuf (stderr, buf, _IOLBF, BUFSIZ);
- }
-#else
- setlinebuf(stderr);
-#endif
- }
-
- if (getpgrp () == 0)
- setpgid (0, 0);
-
-#ifdef RLIMIT_DATA
- if (limitDataSpace >= 0)
- {
- struct rlimit rlim;
-
- if (!getrlimit(RLIMIT_DATA, &rlim))
- {
- if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max))
- rlim.rlim_cur = limitDataSpace;
- else
- rlim.rlim_cur = rlim.rlim_max;
- (void)setrlimit(RLIMIT_DATA, &rlim);
- }
- }
-#endif
-#ifdef RLIMIT_STACK
- if (limitStackSpace >= 0)
- {
- struct rlimit rlim;
-
- if (!getrlimit(RLIMIT_STACK, &rlim))
- {
- if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max))
- rlim.rlim_cur = limitStackSpace;
- else
- rlim.rlim_cur = rlim.rlim_max;
- (void)setrlimit(RLIMIT_STACK, &rlim);
- }
- }
-#endif
-#ifdef RLIMIT_NOFILE
- if (limitNoFile >= 0)
- {
- struct rlimit rlim;
-
- if (!getrlimit(RLIMIT_NOFILE, &rlim))
- {
- if ((limitNoFile > 0) && (limitNoFile < rlim.rlim_max))
- rlim.rlim_cur = limitNoFile;
- else
- rlim.rlim_cur = rlim.rlim_max;
- (void)setrlimit(RLIMIT_NOFILE, &rlim);
- }
- }
-#endif
- LockServer();
- been_here = TRUE;
- }
- TimerInit();
- OsVendorInit();
- /*
- * No log file by default. OsVendorInit() should call LogInit() with the
- * log file name if logging to a file is desired.
- */
- LogInit(NULL, NULL);
- SmartScheduleInit ();
-}
-
-void
-OsCleanup(Bool terminating)
-{
- if (terminating)
- {
- UnlockServer();
- }
-}
+/*********************************************************** + +Copyright 1987, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + + +Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <stdio.h> +#include <X11/X.h> +#include "os.h" +#include "osdep.h" +#include <X11/Xos.h> +#include <signal.h> +#include <errno.h> +#ifdef HAVE_DLFCN_H +# include <dlfcn.h> +#endif +#ifdef HAVE_BACKTRACE +#include <execinfo.h> +#endif + +#include "misc.h" + +#include "dixstruct.h" + + +#if !defined(SYSV) && !defined(WIN32) +#include <sys/resource.h> +#endif + +#ifndef ADMPATH +#define ADMPATH "/usr/adm/X%smsgs" +#endif + +extern char *display; +#ifdef RLIMIT_DATA +int limitDataSpace = -1; +#endif +#ifdef RLIMIT_STACK +int limitStackSpace = -1; +#endif +#ifdef RLIMIT_NOFILE +int limitNoFile = -1; +#endif + +static OsSigWrapperPtr OsSigWrapper = NULL; + +OsSigWrapperPtr +OsRegisterSigWrapper(OsSigWrapperPtr newSigWrapper) +{ + OsSigWrapperPtr oldSigWrapper = OsSigWrapper; + + OsSigWrapper = newSigWrapper; + + return oldSigWrapper; +} + +/* + * OsSigHandler -- + * Catch unexpected signals and exit or continue cleanly. + */ +static void +#ifdef SA_SIGINFO +OsSigHandler(int signo, siginfo_t *sip, void *unused) +#else +OsSigHandler(int signo) +#endif +{ +#ifdef RTLD_DI_SETSIGNAL + const char *dlerr = dlerror(); + + if (dlerr) { + LogMessage(X_ERROR, "Dynamic loader error: %s\n", dlerr); + } +#endif /* RTLD_DI_SETSIGNAL */ + + if (OsSigWrapper != NULL) { + if (OsSigWrapper(signo) == 0) { + /* ddx handled signal and wants us to continue */ + return; + } + } + + /* log, cleanup, and abort */ + xorg_backtrace(); + +#ifdef SA_SIGINFO + if (sip->si_code == SI_USER) { + ErrorF("Recieved signal %d sent by process %ld, uid %ld\n", + signo, (long) sip->si_pid, (long) sip->si_uid); + } else { + switch (signo) { + case SIGSEGV: + case SIGBUS: + case SIGILL: + case SIGFPE: + ErrorF("%s at address %p\n", strsignal(signo), sip->si_addr); + } + } +#endif + + FatalError("Caught signal %d (%s). Server aborting\n", + signo, strsignal(signo)); +} + +void +OsInit(void) +{ + static Bool been_here = FALSE; + static char* devnull = "/dev/null"; + char fname[PATH_MAX]; + + if (!been_here) { + struct sigaction act, oact; + int i; + int siglist[] = { SIGSEGV, SIGQUIT, SIGILL, SIGFPE, SIGBUS, + SIGSYS, + SIGXCPU, + SIGXFSZ, +#ifdef SIGEMT + SIGEMT, +#endif + 0 /* must be last */ }; + sigemptyset(&act.sa_mask); +#ifdef SA_SIGINFO + act.sa_sigaction = OsSigHandler; + act.sa_flags = SA_SIGINFO; +#else + act.sa_handler = OsSigHandler; + act.sa_flags = 0; +#endif + for (i = 0; siglist[i] != 0; i++) { + if (sigaction(siglist[i], &act, &oact)) { + ErrorF("failed to install signal handler for signal %d: %s\n", + siglist[i], strerror(errno)); + } + } +#ifdef HAVE_BACKTRACE + /* + * initialize the backtracer, since the ctor calls dlopen(), which + * calls malloc(), which isn't signal-safe. + */ + do { + void *array; + backtrace(&array, 1); + } while (0); +#endif + +#ifdef RTLD_DI_SETSIGNAL + /* Tell runtime linker to send a signal we can catch instead of SIGKILL + * for failures to load libraries/modules at runtime so we can clean up + * after ourselves. + */ + int failure_signal = SIGQUIT; + dlinfo(RTLD_SELF, RTLD_DI_SETSIGNAL, &failure_signal); +#endif + +#if !defined(__CYGWIN__) + fclose(stdin); + fclose(stdout); +#endif + /* + * If a write of zero bytes to stderr returns non-zero, i.e. -1, + * then writing to stderr failed, and we'll write somewhere else + * instead. (Apparently this never happens in the Real World.) + */ + if (write (2, fname, 0) == -1) + { + FILE *err; + + if (strlen (display) + strlen (ADMPATH) + 1 < sizeof fname) + snprintf (fname, sizeof(fname), ADMPATH, display); + else + strcpy (fname, devnull); + /* + * uses stdio to avoid os dependencies here, + * a real os would use + * open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666) + */ + if (!(err = fopen (fname, "a+"))) + err = fopen (devnull, "w"); + if (err && (fileno(err) != 2)) { + dup2 (fileno (err), 2); + fclose (err); + } +#if defined(SYSV) || defined(SVR4) || defined(WIN32) || defined(__CYGWIN__) + { + static char buf[BUFSIZ]; + setvbuf (stderr, buf, _IOLBF, BUFSIZ); + } +#else + setlinebuf(stderr); +#endif + } + + if (getpgrp () == 0) + setpgid (0, 0); + +#ifdef RLIMIT_DATA + if (limitDataSpace >= 0) + { + struct rlimit rlim; + + if (!getrlimit(RLIMIT_DATA, &rlim)) + { + if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max)) + rlim.rlim_cur = limitDataSpace; + else + rlim.rlim_cur = rlim.rlim_max; + (void)setrlimit(RLIMIT_DATA, &rlim); + } + } +#endif +#ifdef RLIMIT_STACK + if (limitStackSpace >= 0) + { + struct rlimit rlim; + + if (!getrlimit(RLIMIT_STACK, &rlim)) + { + if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max)) + rlim.rlim_cur = limitStackSpace; + else + rlim.rlim_cur = rlim.rlim_max; + (void)setrlimit(RLIMIT_STACK, &rlim); + } + } +#endif +#ifdef RLIMIT_NOFILE + if (limitNoFile >= 0) + { + struct rlimit rlim; + + if (!getrlimit(RLIMIT_NOFILE, &rlim)) + { + if ((limitNoFile > 0) && (limitNoFile < rlim.rlim_max)) + rlim.rlim_cur = limitNoFile; + else + rlim.rlim_cur = rlim.rlim_max; + (void)setrlimit(RLIMIT_NOFILE, &rlim); + } + } +#endif + LockServer(); + been_here = TRUE; + } + TimerInit(); + OsVendorInit(); + /* + * No log file by default. OsVendorInit() should call LogInit() with the + * log file name if logging to a file is desired. + */ + LogInit(NULL, NULL); + SmartScheduleInit (); +} + +void +OsCleanup(Bool terminating) +{ + if (terminating) + { + UnlockServer(); + } +} diff --git a/xorg-server/os/rpcauth.c b/xorg-server/os/rpcauth.c index b40f9359a..989a49a06 100644 --- a/xorg-server/os/rpcauth.c +++ b/xorg-server/os/rpcauth.c @@ -1,193 +1,194 @@ -/*
-
-Copyright 1991, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-/*
- * SUN-DES-1 authentication mechanism
- * Author: Mayank Choudhary, Sun Microsystems
- */
-
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifdef SECURE_RPC
-
-#include <X11/X.h>
-#include <X11/Xauth.h>
-#include "misc.h"
-#include "os.h"
-#include "osdep.h"
-#include "dixstruct.h"
-
-#include <rpc/rpc.h>
-
-#ifdef sun
-/* <rpc/auth.h> only includes this if _KERNEL is #defined... */
-extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
-#endif
-
-static enum auth_stat why;
-
-static char *
-authdes_ezdecode(const char *inmsg, int len)
-{
- struct rpc_msg msg;
- char cred_area[MAX_AUTH_BYTES];
- char verf_area[MAX_AUTH_BYTES];
- char *temp_inmsg;
- struct svc_req r;
- bool_t res0, res1;
- XDR xdr;
- SVCXPRT xprt;
-
- temp_inmsg = malloc(len);
- memmove(temp_inmsg, inmsg, len);
-
- memset((char *)&msg, 0, sizeof(msg));
- memset((char *)&r, 0, sizeof(r));
- memset(cred_area, 0, sizeof(cred_area));
- memset(verf_area, 0, sizeof(verf_area));
-
- msg.rm_call.cb_cred.oa_base = cred_area;
- msg.rm_call.cb_verf.oa_base = verf_area;
- why = AUTH_FAILED;
- xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE);
-
- if ((r.rq_clntcred = malloc(MAX_AUTH_BYTES)) == NULL)
- goto bad1;
- r.rq_xprt = &xprt;
-
- /* decode into msg */
- res0 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_cred));
- res1 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_verf));
- if ( ! (res0 && res1) )
- goto bad2;
-
- /* do the authentication */
-
- r.rq_cred = msg.rm_call.cb_cred; /* read by opaque stuff */
- if (r.rq_cred.oa_flavor != AUTH_DES) {
- why = AUTH_TOOWEAK;
- goto bad2;
- }
-#ifdef SVR4
- if ((why = __authenticate(&r, &msg)) != AUTH_OK) {
-#else
- if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
-#endif
- goto bad2;
- }
- return (((struct authdes_cred *) r.rq_clntcred)->adc_fullname.name);
-
-bad2:
- free(r.rq_clntcred);
-bad1:
- return ((char *)0); /* ((struct authdes_cred *) NULL); */
-}
-
-static XID rpc_id = (XID) ~0L;
-
-static Bool
-CheckNetName (
- unsigned char *addr,
- short len,
- pointer closure
-)
-{
- return (len == strlen ((char *) closure) &&
- strncmp ((char *) addr, (char *) closure, len) == 0);
-}
-
-static char rpc_error[MAXNETNAMELEN+50];
-
-_X_HIDDEN XID
-SecureRPCCheck (unsigned short data_length, const char *data,
- ClientPtr client, char **reason)
-{
- char *fullname;
-
- if (rpc_id == (XID) ~0L) {
- *reason = "Secure RPC authorization not initialized";
- } else {
- fullname = authdes_ezdecode(data, data_length);
- if (fullname == (char *)0) {
- sprintf(rpc_error, "Unable to authenticate secure RPC client (why=%d)", why);
- *reason = rpc_error;
- } else {
- if (ForEachHostInFamily (FamilyNetname, CheckNetName, fullname))
- return rpc_id;
- sprintf(rpc_error, "Principal \"%s\" is not authorized to connect",
- fullname);
- *reason = rpc_error;
- }
- }
- return (XID) ~0L;
-}
-
-_X_HIDDEN void
-SecureRPCInit (void)
-{
- if (rpc_id == ~0L)
- AddAuthorization (9, "SUN-DES-1", 0, (char *) 0);
-}
-
-_X_HIDDEN int
-SecureRPCAdd (unsigned short data_length, const char *data, XID id)
-{
- if (data_length)
- AddHost ((pointer) 0, FamilyNetname, data_length, data);
- rpc_id = id;
- return 1;
-}
-
-_X_HIDDEN int
-SecureRPCReset (void)
-{
- rpc_id = (XID) ~0L;
- return 1;
-}
-
-_X_HIDDEN XID
-SecureRPCToID (unsigned short data_length, char *data)
-{
- return rpc_id;
-}
-
-_X_HIDDEN int
-SecureRPCFromID (XID id, unsigned short *data_lenp, char **datap)
-{
- return 0;
-}
-
-_X_HIDDEN int
-SecureRPCRemove (unsigned short data_length, const char *data)
-{
- return 0;
-}
-#endif /* SECURE_RPC */
+/* + +Copyright 1991, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ + +/* + * SUN-DES-1 authentication mechanism + * Author: Mayank Choudhary, Sun Microsystems + */ + + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#ifdef SECURE_RPC + +#include <X11/X.h> +#include <X11/Xauth.h> +#include "misc.h" +#include "os.h" +#include "osdep.h" +#include "dixstruct.h" + +#include <rpc/rpc.h> + +#ifdef sun +/* <rpc/auth.h> only includes this if _KERNEL is #defined... */ +extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); +#endif + +static enum auth_stat why; + +static char * +authdes_ezdecode(const char *inmsg, int len) +{ + struct rpc_msg msg; + char cred_area[MAX_AUTH_BYTES]; + char verf_area[MAX_AUTH_BYTES]; + char *temp_inmsg; + struct svc_req r; + bool_t res0, res1; + XDR xdr; + SVCXPRT xprt; + + temp_inmsg = malloc(len); + memmove(temp_inmsg, inmsg, len); + + memset((char *)&msg, 0, sizeof(msg)); + memset((char *)&r, 0, sizeof(r)); + memset(cred_area, 0, sizeof(cred_area)); + memset(verf_area, 0, sizeof(verf_area)); + + msg.rm_call.cb_cred.oa_base = cred_area; + msg.rm_call.cb_verf.oa_base = verf_area; + why = AUTH_FAILED; + xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE); + + if ((r.rq_clntcred = malloc(MAX_AUTH_BYTES)) == NULL) + goto bad1; + r.rq_xprt = &xprt; + + /* decode into msg */ + res0 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_cred)); + res1 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_verf)); + if ( ! (res0 && res1) ) + goto bad2; + + /* do the authentication */ + + r.rq_cred = msg.rm_call.cb_cred; /* read by opaque stuff */ + if (r.rq_cred.oa_flavor != AUTH_DES) { + why = AUTH_TOOWEAK; + goto bad2; + } +#ifdef SVR4 + if ((why = __authenticate(&r, &msg)) != AUTH_OK) { +#else + if ((why = _authenticate(&r, &msg)) != AUTH_OK) { +#endif + goto bad2; + } + return (((struct authdes_cred *) r.rq_clntcred)->adc_fullname.name); + +bad2: + free(r.rq_clntcred); +bad1: + return ((char *)0); /* ((struct authdes_cred *) NULL); */ +} + +static XID rpc_id = (XID) ~0L; + +static Bool +CheckNetName ( + unsigned char *addr, + short len, + pointer closure +) +{ + return (len == strlen ((char *) closure) && + strncmp ((char *) addr, (char *) closure, len) == 0); +} + +static char rpc_error[MAXNETNAMELEN+50]; + +_X_HIDDEN XID +SecureRPCCheck (unsigned short data_length, const char *data, + ClientPtr client, char **reason) +{ + char *fullname; + + if (rpc_id == (XID) ~0L) { + *reason = "Secure RPC authorization not initialized"; + } else { + fullname = authdes_ezdecode(data, data_length); + if (fullname == (char *)0) { + snprintf(rpc_error, sizeof(rpc_error), + "Unable to authenticate secure RPC client (why=%d)", why); + *reason = rpc_error; + } else { + if (ForEachHostInFamily (FamilyNetname, CheckNetName, fullname)) + return rpc_id; + snprintf(rpc_error, sizeof(rpc_error), + "Principal \"%s\" is not authorized to connect", fullname); + *reason = rpc_error; + } + } + return (XID) ~0L; +} + +_X_HIDDEN void +SecureRPCInit (void) +{ + if (rpc_id == ~0L) + AddAuthorization (9, "SUN-DES-1", 0, (char *) 0); +} + +_X_HIDDEN int +SecureRPCAdd (unsigned short data_length, const char *data, XID id) +{ + if (data_length) + AddHost ((pointer) 0, FamilyNetname, data_length, data); + rpc_id = id; + return 1; +} + +_X_HIDDEN int +SecureRPCReset (void) +{ + rpc_id = (XID) ~0L; + return 1; +} + +_X_HIDDEN XID +SecureRPCToID (unsigned short data_length, char *data) +{ + return rpc_id; +} + +_X_HIDDEN int +SecureRPCFromID (XID id, unsigned short *data_lenp, char **datap) +{ + return 0; +} + +_X_HIDDEN int +SecureRPCRemove (unsigned short data_length, const char *data) +{ + return 0; +} +#endif /* SECURE_RPC */ diff --git a/xorg-server/os/strndup.c b/xorg-server/os/strndup.c new file mode 100644 index 000000000..bf8e982d4 --- /dev/null +++ b/xorg-server/os/strndup.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include "os.h" + +char * +strndup(const char *str, size_t n) +{ + size_t len; + char *copy; + + for (len = 0; len < n && str[len]; len++) + continue; + + if ((copy = malloc(len + 1)) == NULL) + return (NULL); + memcpy(copy, str, len); + copy[len] = '\0'; + return (copy); +} diff --git a/xorg-server/os/utils.c b/xorg-server/os/utils.c index 07cf4c24f..b49fd3251 100644 --- a/xorg-server/os/utils.c +++ b/xorg-server/os/utils.c @@ -258,7 +258,7 @@ LockServer(void) */ tmppath = LOCK_DIR; - sprintf(port, "%d", atoi(display)); + snprintf(port, sizeof(port), "%d", atoi(display)); len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) : strlen(LOCK_TMP_PREFIX); len += strlen(tmppath) + strlen(port) + strlen(LOCK_SUFFIX) + 1; @@ -295,7 +295,7 @@ LockServer(void) } if (lfd < 0) FatalError("Could not create lock file in %s\n", tmp); - (void) sprintf(pid_str, "%10ld\n", (long)getpid()); + snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long)getpid()); (void) write(lfd, pid_str, 11); (void) fchmod(lfd, 0444); (void) close(lfd); @@ -1252,7 +1252,7 @@ OsAbort (void) */ int -System(char *command) +System(const char *command) { int pid, p; void (*csig)(int); @@ -1302,7 +1302,7 @@ static struct pid { OsSigHandlerPtr old_alarm = NULL; /* XXX horrible awful hack */ pointer -Popen(char *command, char *type) +Popen(const char *command, const char *type) { struct pid *cur; FILE *iop; @@ -1388,7 +1388,7 @@ Popen(char *command, char *type) /* fopen that drops privileges */ pointer -Fopen(char *file, char *type) +Fopen(const char *file, const char *type) { FILE *iop; #ifndef HAS_SAVED_IDS_AND_SETEUID @@ -1664,13 +1664,11 @@ CheckUserParameters(int argc, char **argv, char **envp) if (!eq) continue; len = eq - envp[i]; - e = malloc(len + 1); + e = strndup(envp[i], len); if (!e) { bad = InternalError; break; } - strncpy(e, envp[i], len); - e[len] = 0; if (len >= 4 && (strcmp(e + len - 4, "PATH") == 0 || strcmp(e, "TERMCAP") == 0)) { diff --git a/xorg-server/os/xdmcp.c b/xorg-server/os/xdmcp.c index 8da2cb05c..46440718c 100644 --- a/xorg-server/os/xdmcp.c +++ b/xorg-server/os/xdmcp.c @@ -1,1661 +1,1661 @@ -/*
- * Copyright 1989 Network Computing Devices, Inc., Mountain View, California.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of N.C.D. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. N.C.D. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifdef WIN32
-#include <X11/Xwinsock.h>
-#endif
-
-#include <X11/Xos.h>
-
-#if !defined(WIN32)
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <X11/X.h>
-#include <X11/Xmd.h>
-#include "misc.h"
-#include <X11/Xpoll.h>
-#include "osdep.h"
-#include "input.h"
-#include "dixstruct.h"
-#include "opaque.h"
-#include "site.h"
-
-#ifdef STREAMSCONN
-#include <tiuser.h>
-#include <netconfig.h>
-#include <netdir.h>
-#endif
-
-#ifdef XDMCP
-#undef REQUEST
-
-#ifdef XDMCP_NO_IPV6
-#undef IPv6
-#endif
-
-#include <X11/Xdmcp.h>
-
-#define X_INCLUDE_NETDB_H
-#include <X11/Xos_r.h>
-
-static char *defaultDisplayClass = COMPILEDDISPLAYCLASS;
-
-static int xdmcpSocket, sessionSocket;
-static xdmcp_states state;
-#if defined(IPv6) && defined(AF_INET6)
-static int xdmcpSocket6;
-static struct sockaddr_storage req_sockaddr;
-#else
-static struct sockaddr_in req_sockaddr;
-#endif
-static int req_socklen;
-static CARD32 SessionID;
-static CARD32 timeOutTime;
-static int timeOutRtx;
-static CARD32 defaultKeepaliveDormancy = XDM_DEF_DORMANCY;
-static CARD32 keepaliveDormancy = XDM_DEF_DORMANCY;
-static CARD16 DisplayNumber;
-static xdmcp_states XDM_INIT_STATE = XDM_OFF;
-#ifdef HASXDMAUTH
-static char *xdmAuthCookie;
-#endif
-
-static XdmcpBuffer buffer;
-
-#if defined(IPv6) && defined(AF_INET6)
-
-static struct addrinfo *mgrAddr;
-static struct addrinfo *mgrAddrFirst;
-
-#define SOCKADDR_TYPE struct sockaddr_storage
-#define SOCKADDR_FAMILY(s) ((struct sockaddr *)&(s))->sa_family
-
-#ifdef BSD44SOCKETS
-#define SOCKLEN_FIELD(s) ((struct sockaddr *)&(s))->sa_len
-#define SOCKLEN_TYPE unsigned char
-#else
-#define SOCKLEN_TYPE unsigned int
-#endif
-
-#else
-
-#define SOCKADDR_TYPE struct sockaddr_in
-#define SOCKADDR_FAMILY(s) (s).sin_family
-
-#ifdef BSD44SOCKETS
-#define SOCKLEN_FIELD(s) (s).sin_len
-#define SOCKLEN_TYPE unsigned char
-#else
-#define SOCKLEN_TYPE size_t
-#endif
-
-#endif
-
-static SOCKADDR_TYPE ManagerAddress;
-static SOCKADDR_TYPE FromAddress;
-
-#ifdef SOCKLEN_FIELD
-#define ManagerAddressLen SOCKLEN_FIELD(ManagerAddress)
-#define FromAddressLen SOCKLEN_FIELD(FromAddress)
-#else
-static SOCKLEN_TYPE ManagerAddressLen, FromAddressLen;
-#endif
-
-#if defined(IPv6) && defined(AF_INET6)
-static struct multicastinfo {
- struct multicastinfo *next;
- struct addrinfo *ai;
- int hops;
-} *mcastlist;
-#endif
-
-static void XdmcpAddHost(
- const struct sockaddr *from,
- int fromlen,
- ARRAY8Ptr AuthenticationName,
- ARRAY8Ptr hostname,
- ARRAY8Ptr status);
-
-static void XdmcpSelectHost(
- const struct sockaddr *host_sockaddr,
- int host_len,
- ARRAY8Ptr AuthenticationName);
-
-static void get_xdmcp_sock(void);
-
-static void send_query_msg(void);
-
-static void recv_willing_msg(
- struct sockaddr * /*from*/,
- int /*fromlen*/,
- unsigned /*length*/);
-
-static void send_request_msg(void);
-
-static void recv_accept_msg(unsigned /*length*/);
-
-static void recv_decline_msg(unsigned /*length*/);
-
-static void send_manage_msg(void);
-
-static void recv_refuse_msg(unsigned /*length*/);
-
-static void recv_failed_msg(unsigned /*length*/);
-
-static void send_keepalive_msg(void);
-
-static void recv_alive_msg(unsigned /*length*/);
-
-static void XdmcpFatal(
- const char * /*type*/,
- ARRAY8Ptr /*status*/);
-
-static void XdmcpWarning(const char * /*str*/);
-
-static void get_manager_by_name(
- int /*argc*/,
- char ** /*argv*/,
- int /*i*/);
-
-static void get_fromaddr_by_name(int /*argc*/, char ** /*argv*/, int /*i*/);
-
-#if defined(IPv6) && defined(AF_INET6)
-static int get_mcast_options(int /*argc*/, char ** /*argv*/, int /*i*/);
-#endif
-
-static void receive_packet(int /*socketfd*/);
-
-static void send_packet(void);
-
-static void timeout(void);
-
-static void restart(void);
-
-static void XdmcpBlockHandler(
- pointer /*data*/,
- struct timeval ** /*wt*/,
- pointer /*LastSelectMask*/);
-
-static void XdmcpWakeupHandler(
- pointer /*data*/,
- int /*i*/,
- pointer /*LastSelectMask*/);
-
-/*
- * Register the Manufacturer display ID
- */
-
-static ARRAY8 ManufacturerDisplayID;
-
-static void
-XdmcpRegisterManufacturerDisplayID (const char *name, int length)
-{
- int i;
-
- XdmcpDisposeARRAY8 (&ManufacturerDisplayID);
- if (!XdmcpAllocARRAY8 (&ManufacturerDisplayID, length))
- return;
- for (i = 0; i < length; i++)
- ManufacturerDisplayID.data[i] = (CARD8) name[i];
-}
-
-static unsigned short xdm_udp_port = XDM_UDP_PORT;
-static Bool OneSession = FALSE;
-static const char *xdm_from = NULL;
-
-void
-XdmcpUseMsg (void)
-{
- ErrorF("-query host-name contact named host for XDMCP\n");
- ErrorF("-broadcast broadcast for XDMCP\n");
-#if defined(IPv6) && defined(AF_INET6)
- ErrorF("-multicast [addr [hops]] IPv6 multicast for XDMCP\n");
-#endif
- ErrorF("-indirect host-name contact named host for indirect XDMCP\n");
- ErrorF("-port port-num UDP port number to send messages to\n");
- ErrorF("-from local-address specify the local address to connect from\n");
- ErrorF("-once Terminate server after one session\n");
- ErrorF("-class display-class specify display class to send in manage\n");
-#ifdef HASXDMAUTH
- ErrorF("-cookie xdm-auth-bits specify the magic cookie for XDMCP\n");
-#endif
- ErrorF("-displayID display-id manufacturer display ID for request\n");
-}
-
-int
-XdmcpOptions(int argc, char **argv, int i)
-{
- if (strcmp(argv[i], "-query") == 0) {
- get_manager_by_name(argc, argv, i++);
- XDM_INIT_STATE = XDM_QUERY;
- AccessUsingXdmcp ();
- return i + 1;
- }
- if (strcmp(argv[i], "-broadcast") == 0) {
- XDM_INIT_STATE = XDM_BROADCAST;
- AccessUsingXdmcp ();
- return i + 1;
- }
-#if defined(IPv6) && defined(AF_INET6)
- if (strcmp(argv[i], "-multicast") == 0) {
- i = get_mcast_options(argc, argv, ++i);
- XDM_INIT_STATE = XDM_MULTICAST;
- AccessUsingXdmcp ();
- return i + 1;
- }
-#endif
- if (strcmp(argv[i], "-indirect") == 0) {
- get_manager_by_name(argc, argv, i++);
- XDM_INIT_STATE = XDM_INDIRECT;
- AccessUsingXdmcp ();
- return i + 1;
- }
- if (strcmp(argv[i], "-port") == 0) {
- if (++i == argc) {
- FatalError("Xserver: missing port number in command line\n");
- }
- xdm_udp_port = (unsigned short) atoi(argv[i]);
- return i + 1;
- }
- if (strcmp(argv[i], "-from") == 0) {
- get_fromaddr_by_name(argc, argv, ++i);
- return i + 1;
- }
- if (strcmp(argv[i], "-once") == 0) {
- OneSession = TRUE;
- return i + 1;
- }
- if (strcmp(argv[i], "-class") == 0) {
- if (++i == argc) {
- FatalError("Xserver: missing class name in command line\n");
- }
- defaultDisplayClass = argv[i];
- return i + 1;
- }
-#ifdef HASXDMAUTH
- if (strcmp(argv[i], "-cookie") == 0) {
- if (++i == argc) {
- FatalError("Xserver: missing cookie data in command line\n");
- }
- xdmAuthCookie = argv[i];
- return i + 1;
- }
-#endif
- if (strcmp(argv[i], "-displayID") == 0) {
- if (++i == argc) {
- FatalError("Xserver: missing displayID in command line\n");
- }
- XdmcpRegisterManufacturerDisplayID (argv[i], strlen (argv[i]));
- return i + 1;
- }
- return i;
-}
-
-/*
- * This section is a collection of routines for
- * registering server-specific data with the XDMCP
- * state machine.
- */
-
-
-/*
- * Save all broadcast addresses away so BroadcastQuery
- * packets get sent everywhere
- */
-
-#define MAX_BROADCAST 10
-
-/* This stays sockaddr_in since IPv6 doesn't support broadcast */
-static struct sockaddr_in BroadcastAddresses[MAX_BROADCAST];
-static int NumBroadcastAddresses;
-
-void
-XdmcpRegisterBroadcastAddress (const struct sockaddr_in *addr)
-{
- struct sockaddr_in *bcast;
- if (NumBroadcastAddresses >= MAX_BROADCAST)
- return;
- bcast = &BroadcastAddresses[NumBroadcastAddresses++];
- memset(bcast, 0, sizeof (struct sockaddr_in));
-#ifdef BSD44SOCKETS
- bcast->sin_len = addr->sin_len;
-#endif
- bcast->sin_family = addr->sin_family;
- bcast->sin_port = htons (xdm_udp_port);
- bcast->sin_addr = addr->sin_addr;
-}
-
-/*
- * Each authentication type is registered here; Validator
- * will be called to check all access attempts using
- * the specified authentication type
- */
-
-static ARRAYofARRAY8 AuthenticationNames, AuthenticationDatas;
-typedef struct _AuthenticationFuncs {
- ValidatorFunc Validator;
- GeneratorFunc Generator;
- AddAuthorFunc AddAuth;
-} AuthenticationFuncsRec, *AuthenticationFuncsPtr;
-
-static AuthenticationFuncsPtr AuthenticationFuncsList;
-
-void
-XdmcpRegisterAuthentication (
- const char *name,
- int namelen,
- const char *data,
- int datalen,
- ValidatorFunc Validator,
- GeneratorFunc Generator,
- AddAuthorFunc AddAuth)
-{
- int i;
- ARRAY8 AuthenticationName, AuthenticationData;
- static AuthenticationFuncsPtr newFuncs;
-
- if (!XdmcpAllocARRAY8 (&AuthenticationName, namelen))
- return;
- if (!XdmcpAllocARRAY8 (&AuthenticationData, datalen))
- {
- XdmcpDisposeARRAY8 (&AuthenticationName);
- return;
- }
- for (i = 0; i < namelen; i++)
- AuthenticationName.data[i] = name[i];
- for (i = 0; i < datalen; i++)
- AuthenticationData.data[i] = data[i];
- if (!(XdmcpReallocARRAYofARRAY8 (&AuthenticationNames,
- AuthenticationNames.length + 1) &&
- XdmcpReallocARRAYofARRAY8 (&AuthenticationDatas,
- AuthenticationDatas.length + 1) &&
- (newFuncs = malloc((AuthenticationNames.length + 1) * sizeof (AuthenticationFuncsRec)))))
- {
- XdmcpDisposeARRAY8 (&AuthenticationName);
- XdmcpDisposeARRAY8 (&AuthenticationData);
- return;
- }
- for (i = 0; i < AuthenticationNames.length - 1; i++)
- newFuncs[i] = AuthenticationFuncsList[i];
- newFuncs[AuthenticationNames.length-1].Validator = Validator;
- newFuncs[AuthenticationNames.length-1].Generator = Generator;
- newFuncs[AuthenticationNames.length-1].AddAuth = AddAuth;
- free(AuthenticationFuncsList);
- AuthenticationFuncsList = newFuncs;
- AuthenticationNames.data[AuthenticationNames.length-1] = AuthenticationName;
- AuthenticationDatas.data[AuthenticationDatas.length-1] = AuthenticationData;
-}
-
-/*
- * Select the authentication type to be used; this is
- * set by the manager of the host to be connected to.
- */
-
-static ARRAY8 noAuthenticationName = {(CARD16) 0, (CARD8Ptr) 0};
-static ARRAY8 noAuthenticationData = {(CARD16) 0, (CARD8Ptr) 0};
-static ARRAY8Ptr AuthenticationName = &noAuthenticationName;
-static ARRAY8Ptr AuthenticationData = &noAuthenticationData;
-static AuthenticationFuncsPtr AuthenticationFuncs;
-
-static void
-XdmcpSetAuthentication (const ARRAY8Ptr name)
-{
- int i;
-
- for (i = 0; i < AuthenticationNames.length; i++)
- if (XdmcpARRAY8Equal (&AuthenticationNames.data[i], name))
- {
- AuthenticationName = &AuthenticationNames.data[i];
- AuthenticationData = &AuthenticationDatas.data[i];
- AuthenticationFuncs = &AuthenticationFuncsList[i];
- break;
- }
-}
-
-/*
- * Register the host address for the display
- */
-
-static ARRAY16 ConnectionTypes;
-static ARRAYofARRAY8 ConnectionAddresses;
-static long xdmcpGeneration;
-
-void
-XdmcpRegisterConnection (
- int type,
- const char *address,
- int addrlen)
-{
- int i;
- CARD8 *newAddress;
-
- if (xdmcpGeneration != serverGeneration)
- {
- XdmcpDisposeARRAY16 (&ConnectionTypes);
- XdmcpDisposeARRAYofARRAY8 (&ConnectionAddresses);
- xdmcpGeneration = serverGeneration;
- }
- if (xdm_from != NULL) { /* Only register the requested address */
- const void *regAddr = address;
- const void *fromAddr = NULL;
- int regAddrlen = addrlen;
-
- if (addrlen == sizeof(struct in_addr)) {
- if (SOCKADDR_FAMILY(FromAddress) == AF_INET) {
- fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr;
- }
-#if defined(IPv6) && defined(AF_INET6)
- else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET6) &&
- IN6_IS_ADDR_V4MAPPED(
- &((struct sockaddr_in6 *)&FromAddress)->sin6_addr)) {
- fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr.s6_addr[12];
- }
-#endif
- }
-#if defined(IPv6) && defined(AF_INET6)
- else if (addrlen == sizeof(struct in6_addr)) {
- if (SOCKADDR_FAMILY(FromAddress) == AF_INET6) {
- fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr;
- } else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET) &&
- IN6_IS_ADDR_V4MAPPED((struct in6_addr *) address)) {
- fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr;
- regAddr = &((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr[12];
- regAddrlen = sizeof(struct in_addr);
- }
- }
-#endif
- if (!fromAddr || memcmp(regAddr, fromAddr, regAddrlen) != 0) {
- return;
- }
- }
- if (ConnectionAddresses.length + 1 == 256)
- return;
- newAddress = malloc(addrlen * sizeof (CARD8));
- if (!newAddress)
- return;
- if (!XdmcpReallocARRAY16 (&ConnectionTypes, ConnectionTypes.length + 1))
- {
- free(newAddress);
- return;
- }
- if (!XdmcpReallocARRAYofARRAY8 (&ConnectionAddresses,
- ConnectionAddresses.length + 1))
- {
- free(newAddress);
- return;
- }
- ConnectionTypes.data[ConnectionTypes.length - 1] = (CARD16) type;
- for (i = 0; i < addrlen; i++)
- newAddress[i] = address[i];
- ConnectionAddresses.data[ConnectionAddresses.length-1].data = newAddress;
- ConnectionAddresses.data[ConnectionAddresses.length-1].length = addrlen;
-}
-
-/*
- * Register an Authorization Name. XDMCP advertises this list
- * to the manager.
- */
-
-static ARRAYofARRAY8 AuthorizationNames;
-
-void
-XdmcpRegisterAuthorizations (void)
-{
- XdmcpDisposeARRAYofARRAY8 (&AuthorizationNames);
- RegisterAuthorizations ();
-}
-
-void
-XdmcpRegisterAuthorization (const char *name, int namelen)
-{
- ARRAY8 authName;
- int i;
-
- authName.data = malloc(namelen * sizeof (CARD8));
- if (!authName.data)
- return;
- if (!XdmcpReallocARRAYofARRAY8 (&AuthorizationNames, AuthorizationNames.length +1))
- {
- free(authName.data);
- return;
- }
- for (i = 0; i < namelen; i++)
- authName.data[i] = (CARD8) name[i];
- authName.length = namelen;
- AuthorizationNames.data[AuthorizationNames.length-1] = authName;
-}
-
-/*
- * Register the DisplayClass string
- */
-
-static ARRAY8 DisplayClass;
-
-static void
-XdmcpRegisterDisplayClass (const char *name, int length)
-{
- int i;
-
- XdmcpDisposeARRAY8 (&DisplayClass);
- if (!XdmcpAllocARRAY8 (&DisplayClass, length))
- return;
- for (i = 0; i < length; i++)
- DisplayClass.data[i] = (CARD8) name[i];
-}
-
-/*
- * initialize XDMCP; create the socket, compute the display
- * number, set up the state machine
- */
-
-void
-XdmcpInit(void)
-{
- state = XDM_INIT_STATE;
-#ifdef HASXDMAUTH
- if (xdmAuthCookie)
- XdmAuthenticationInit (xdmAuthCookie, strlen (xdmAuthCookie));
-#endif
- if (state != XDM_OFF)
- {
- XdmcpRegisterAuthorizations();
- XdmcpRegisterDisplayClass (defaultDisplayClass, strlen (defaultDisplayClass));
- AccessUsingXdmcp();
- RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler,
- (pointer) 0);
- timeOutRtx = 0;
- DisplayNumber = (CARD16) atoi(display);
- get_xdmcp_sock();
- send_packet();
- }
-}
-
-void
-XdmcpReset (void)
-{
- state = XDM_INIT_STATE;
- if (state != XDM_OFF)
- {
- RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler,
- (pointer) 0);
- timeOutRtx = 0;
- send_packet();
- }
-}
-
-/*
- * Called whenever a new connection is created; notices the
- * first connection and saves it to terminate the session
- * when it is closed
- */
-
-void
-XdmcpOpenDisplay(int sock)
-{
- if (state != XDM_AWAIT_MANAGE_RESPONSE)
- return;
- state = XDM_RUN_SESSION;
- sessionSocket = sock;
-}
-
-void
-XdmcpCloseDisplay(int sock)
-{
- if ((state != XDM_RUN_SESSION && state != XDM_AWAIT_ALIVE_RESPONSE)
- || sessionSocket != sock)
- return;
- state = XDM_INIT_STATE;
- if (OneSession)
- dispatchException |= DE_TERMINATE;
- else
- dispatchException |= DE_RESET;
- isItTimeToYield = TRUE;
-}
-
-/*
- * called before going to sleep, this routine
- * may modify the timeout value about to be sent
- * to select; in this way XDMCP can do appropriate things
- * dynamically while starting up
- */
-
-/*ARGSUSED*/
-static void
-XdmcpBlockHandler(
- pointer data, /* unused */
- struct timeval **wt,
- pointer pReadmask)
-{
- fd_set *LastSelectMask = (fd_set*)pReadmask;
- CARD32 millisToGo;
-
- if (state == XDM_OFF)
- return;
- FD_SET(xdmcpSocket, LastSelectMask);
-#if defined(IPv6) && defined(AF_INET6)
- if (xdmcpSocket6 >= 0)
- FD_SET(xdmcpSocket6, LastSelectMask);
-#endif
- if (timeOutTime == 0)
- return;
- millisToGo = timeOutTime - GetTimeInMillis();
- if ((int) millisToGo < 0)
- millisToGo = 0;
- AdjustWaitForDelay (wt, millisToGo);
-}
-
-/*
- * called after select returns; this routine will
- * recognise when XDMCP packets await and
- * process them appropriately
- */
-
-/*ARGSUSED*/
-static void
-XdmcpWakeupHandler(
- pointer data, /* unused */
- int i,
- pointer pReadmask)
-{
- fd_set* LastSelectMask = (fd_set*)pReadmask;
- fd_set devicesReadable;
-
- if (state == XDM_OFF)
- return;
- if (i > 0)
- {
- if (FD_ISSET(xdmcpSocket, LastSelectMask))
- {
- receive_packet(xdmcpSocket);
- FD_CLR(xdmcpSocket, LastSelectMask);
- }
-#if defined(IPv6) && defined(AF_INET6)
- if (xdmcpSocket6 >= 0 && FD_ISSET(xdmcpSocket6, LastSelectMask))
- {
- receive_packet(xdmcpSocket6);
- FD_CLR(xdmcpSocket6, LastSelectMask);
- }
-#endif
- XFD_ANDSET(&devicesReadable, LastSelectMask, &EnabledDevices);
- if (XFD_ANYSET(&devicesReadable))
- {
- if (state == XDM_AWAIT_USER_INPUT)
- restart();
- else if (state == XDM_RUN_SESSION)
- keepaliveDormancy = defaultKeepaliveDormancy;
- }
- if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION)
- timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000;
- }
- else if (timeOutTime && (int) (GetTimeInMillis() - timeOutTime) >= 0)
- {
- if (state == XDM_RUN_SESSION)
- {
- state = XDM_KEEPALIVE;
- send_packet();
- }
- else
- timeout();
- }
-}
-
-/*
- * This routine should be called from the routine that drives the
- * user's host menu when the user selects a host
- */
-
-static void
-XdmcpSelectHost(
- const struct sockaddr *host_sockaddr,
- int host_len,
- ARRAY8Ptr AuthenticationName)
-{
- state = XDM_START_CONNECTION;
- memmove(&req_sockaddr, host_sockaddr, host_len);
- req_socklen = host_len;
- XdmcpSetAuthentication (AuthenticationName);
- send_packet();
-}
-
-/*
- * !!! this routine should be replaced by a routine that adds
- * the host to the user's host menu. the current version just
- * selects the first host to respond with willing message.
- */
-
-/*ARGSUSED*/
-static void
-XdmcpAddHost(
- const struct sockaddr *from,
- int fromlen,
- ARRAY8Ptr AuthenticationName,
- ARRAY8Ptr hostname,
- ARRAY8Ptr status)
-{
- XdmcpSelectHost(from, fromlen, AuthenticationName);
-}
-
-/*
- * A message is queued on the socket; read it and
- * do the appropriate thing
- */
-
-static ARRAY8 UnwillingMessage = { (CARD8) 14, (CARD8 *) "Host unwilling" };
-
-static void
-receive_packet(int socketfd)
-{
-#if defined(IPv6) && defined(AF_INET6)
- struct sockaddr_storage from;
-#else
- struct sockaddr_in from;
-#endif
- int fromlen = sizeof(from);
- XdmcpHeader header;
-
- /* read message off socket */
- if (!XdmcpFill (socketfd, &buffer, (XdmcpNetaddr) &from, &fromlen))
- return;
-
- /* reset retransmission backoff */
- timeOutRtx = 0;
-
- if (!XdmcpReadHeader (&buffer, &header))
- return;
-
- if (header.version != XDM_PROTOCOL_VERSION)
- return;
-
- switch (header.opcode) {
- case WILLING:
- recv_willing_msg((struct sockaddr *) &from, fromlen, header.length);
- break;
- case UNWILLING:
- XdmcpFatal("Manager unwilling", &UnwillingMessage);
- break;
- case ACCEPT:
- recv_accept_msg(header.length);
- break;
- case DECLINE:
- recv_decline_msg(header.length);
- break;
- case REFUSE:
- recv_refuse_msg(header.length);
- break;
- case FAILED:
- recv_failed_msg(header.length);
- break;
- case ALIVE:
- recv_alive_msg(header.length);
- break;
- }
-}
-
-/*
- * send the appropriate message given the current state
- */
-
-static void
-send_packet(void)
-{
- int rtx;
- switch (state) {
- case XDM_QUERY:
- case XDM_BROADCAST:
- case XDM_INDIRECT:
-#if defined(IPv6) && defined(AF_INET6)
- case XDM_MULTICAST:
-#endif
- send_query_msg();
- break;
- case XDM_START_CONNECTION:
- send_request_msg();
- break;
- case XDM_MANAGE:
- send_manage_msg();
- break;
- case XDM_KEEPALIVE:
- send_keepalive_msg();
- break;
- default:
- break;
- }
- rtx = (XDM_MIN_RTX << timeOutRtx);
- if (rtx > XDM_MAX_RTX)
- rtx = XDM_MAX_RTX;
- timeOutTime = GetTimeInMillis() + rtx * 1000;
-}
-
-/*
- * The session is declared dead for some reason; too many
- * timeouts, or Keepalive failure.
- */
-
-static void
-XdmcpDeadSession (const char *reason)
-{
- ErrorF ("XDM: %s, declaring session dead\n", reason);
- state = XDM_INIT_STATE;
- isItTimeToYield = TRUE;
- dispatchException |= DE_RESET;
- timeOutTime = 0;
- timeOutRtx = 0;
- send_packet();
-}
-
-/*
- * Timeout waiting for an XDMCP response.
- */
-
-static void
-timeout(void)
-{
- timeOutRtx++;
- if (state == XDM_AWAIT_ALIVE_RESPONSE && timeOutRtx >= XDM_KA_RTX_LIMIT )
- {
- XdmcpDeadSession ("too many keepalive retransmissions");
- return;
- }
- else if (timeOutRtx >= XDM_RTX_LIMIT)
- {
- /* Quit if "-once" specified, otherwise reset and try again. */
- if (OneSession) {
- dispatchException |= DE_TERMINATE;
- ErrorF("XDM: too many retransmissions\n");
- } else {
- XdmcpDeadSession("too many retransmissions");
- }
- return;
- }
-
-#if defined(IPv6) && defined(AF_INET6)
- if (state == XDM_COLLECT_QUERY || state == XDM_COLLECT_INDIRECT_QUERY) {
- /* Try next address */
- for (mgrAddr = mgrAddr->ai_next; ; mgrAddr = mgrAddr->ai_next) {
- if (mgrAddr == NULL) {
- mgrAddr = mgrAddrFirst;
- }
- if (mgrAddr->ai_family == AF_INET
- || mgrAddr->ai_family == AF_INET6)
- break;
- }
-#ifndef SIN6_LEN
- ManagerAddressLen = mgrAddr->ai_addrlen;
-#endif
- memcpy(&ManagerAddress, mgrAddr->ai_addr, mgrAddr->ai_addrlen);
- }
-#endif
-
- switch (state) {
- case XDM_COLLECT_QUERY:
- state = XDM_QUERY;
- break;
- case XDM_COLLECT_BROADCAST_QUERY:
- state = XDM_BROADCAST;
- break;
-#if defined(IPv6) && defined(AF_INET6)
- case XDM_COLLECT_MULTICAST_QUERY:
- state = XDM_MULTICAST;
- break;
-#endif
- case XDM_COLLECT_INDIRECT_QUERY:
- state = XDM_INDIRECT;
- break;
- case XDM_AWAIT_REQUEST_RESPONSE:
- state = XDM_START_CONNECTION;
- break;
- case XDM_AWAIT_MANAGE_RESPONSE:
- state = XDM_MANAGE;
- break;
- case XDM_AWAIT_ALIVE_RESPONSE:
- state = XDM_KEEPALIVE;
- break;
- default:
- break;
- }
- send_packet();
-}
-
-static void
-restart(void)
-{
- state = XDM_INIT_STATE;
- timeOutRtx = 0;
- send_packet();
-}
-
-static int
-XdmcpCheckAuthentication (ARRAY8Ptr Name, ARRAY8Ptr Data, int packet_type)
-{
- return (XdmcpARRAY8Equal (Name, AuthenticationName) &&
- (AuthenticationName->length == 0 ||
- (*AuthenticationFuncs->Validator) (AuthenticationData, Data, packet_type)));
-}
-
-static int
-XdmcpAddAuthorization (ARRAY8Ptr name, ARRAY8Ptr data)
-{
- AddAuthorFunc AddAuth;
-
- if (AuthenticationFuncs && AuthenticationFuncs->AddAuth)
- AddAuth = AuthenticationFuncs->AddAuth;
- else
- AddAuth = AddAuthorization;
- return (*AddAuth) ((unsigned short)name->length,
- (char *)name->data,
- (unsigned short)data->length,
- (char *)data->data);
-}
-
-/*
- * from here to the end of this file are routines private
- * to the state machine.
- */
-
-static void
-get_xdmcp_sock(void)
-{
-#ifdef STREAMSCONN
- struct netconfig *nconf;
-
- if ((xdmcpSocket = t_open("/dev/udp", O_RDWR, 0)) < 0) {
- XdmcpWarning("t_open() of /dev/udp failed");
- return;
- }
-
- if( t_bind(xdmcpSocket,NULL,NULL) < 0 ) {
- XdmcpWarning("UDP socket creation failed");
- t_error("t_bind(xdmcpSocket) failed" );
- t_close(xdmcpSocket);
- return;
- }
-
- /*
- * This part of the code looks contrived. It will actually fit in nicely
- * when the CLTS part of Xtrans is implemented.
- */
-
- if( (nconf=getnetconfigent("udp")) == NULL ) {
- XdmcpWarning("UDP socket creation failed: getnetconfigent()");
- t_unbind(xdmcpSocket);
- t_close(xdmcpSocket);
- return;
- }
-
- if( netdir_options(nconf, ND_SET_BROADCAST, xdmcpSocket, NULL) ) {
- XdmcpWarning("UDP set broadcast option failed: netdir_options()");
- freenetconfigent(nconf);
- t_unbind(xdmcpSocket);
- t_close(xdmcpSocket);
- return;
- }
-
- freenetconfigent(nconf);
-#else
- int soopts = 1;
-
-#if defined(IPv6) && defined(AF_INET6)
- if ((xdmcpSocket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
- XdmcpWarning("INET6 UDP socket creation failed");
-#endif
- if ((xdmcpSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- XdmcpWarning("UDP socket creation failed");
-#ifdef SO_BROADCAST
- else if (setsockopt(xdmcpSocket, SOL_SOCKET, SO_BROADCAST, (char *)&soopts,
- sizeof(soopts)) < 0)
- XdmcpWarning("UDP set broadcast socket-option failed");
-#endif /* SO_BROADCAST */
- if (xdmcpSocket >= 0 && xdm_from != NULL) {
- if (bind(xdmcpSocket, (struct sockaddr *)&FromAddress,
- FromAddressLen) < 0) {
- FatalError("Xserver: failed to bind to -from address: %s\n", xdm_from);
- }
- }
-#endif /* STREAMSCONN */
-}
-
-static void
-send_query_msg(void)
-{
- XdmcpHeader header;
- Bool broadcast = FALSE;
-#if defined(IPv6) && defined(AF_INET6)
- Bool multicast = FALSE;
-#endif
- int i;
- int socketfd = xdmcpSocket;
-
- header.version = XDM_PROTOCOL_VERSION;
- switch(state){
- case XDM_QUERY:
- header.opcode = (CARD16) QUERY;
- state = XDM_COLLECT_QUERY;
- break;
- case XDM_BROADCAST:
- header.opcode = (CARD16) BROADCAST_QUERY;
- state = XDM_COLLECT_BROADCAST_QUERY;
- broadcast = TRUE;
- break;
-#if defined(IPv6) && defined(AF_INET6)
- case XDM_MULTICAST:
- header.opcode = (CARD16) BROADCAST_QUERY;
- state = XDM_COLLECT_MULTICAST_QUERY;
- multicast = TRUE;
- break;
-#endif
- case XDM_INDIRECT:
- header.opcode = (CARD16) INDIRECT_QUERY;
- state = XDM_COLLECT_INDIRECT_QUERY;
- break;
- default:
- break;
- }
- header.length = 1;
- for (i = 0; i < AuthenticationNames.length; i++)
- header.length += 2 + AuthenticationNames.data[i].length;
-
- XdmcpWriteHeader (&buffer, &header);
- XdmcpWriteARRAYofARRAY8 (&buffer, &AuthenticationNames);
- if (broadcast)
- {
- int i;
-
- for (i = 0; i < NumBroadcastAddresses; i++)
- XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &BroadcastAddresses[i],
- sizeof (struct sockaddr_in));
- }
-#if defined(IPv6) && defined(AF_INET6)
- else if (multicast)
- {
- struct multicastinfo *mcl;
- struct addrinfo *ai;
-
- for (mcl = mcastlist; mcl != NULL; mcl = mcl->next) {
- for (ai = mcl->ai ; ai != NULL; ai = ai->ai_next) {
- if (ai->ai_family == AF_INET) {
- unsigned char hopflag = (unsigned char) mcl->hops;
- socketfd = xdmcpSocket;
- setsockopt(socketfd, IPPROTO_IP, IP_MULTICAST_TTL,
- &hopflag, sizeof(hopflag));
- } else if (ai->ai_family == AF_INET6) {
- int hopflag6 = mcl->hops;
- socketfd = xdmcpSocket6;
- setsockopt(socketfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
- &hopflag6, sizeof(hopflag6));
- } else {
- continue;
- }
- XdmcpFlush (socketfd, &buffer,
- (XdmcpNetaddr) ai->ai_addr, ai->ai_addrlen);
- break;
- }
- }
- }
-#endif
- else
- {
-#if defined(IPv6) && defined(AF_INET6)
- if (SOCKADDR_FAMILY(ManagerAddress) == AF_INET6)
- socketfd = xdmcpSocket6;
-#endif
- XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &ManagerAddress,
- ManagerAddressLen);
- }
-}
-
-static void
-recv_willing_msg(
- struct sockaddr *from,
- int fromlen,
- unsigned length)
-{
- ARRAY8 authenticationName;
- ARRAY8 hostname;
- ARRAY8 status;
-
- authenticationName.data = 0;
- hostname.data = 0;
- status.data = 0;
- if (XdmcpReadARRAY8 (&buffer, &authenticationName) &&
- XdmcpReadARRAY8 (&buffer, &hostname) &&
- XdmcpReadARRAY8 (&buffer, &status))
- {
- if (length == 6 + authenticationName.length +
- hostname.length + status.length)
- {
- switch (state)
- {
- case XDM_COLLECT_QUERY:
- XdmcpSelectHost(from, fromlen, &authenticationName);
- break;
- case XDM_COLLECT_BROADCAST_QUERY:
-#if defined(IPv6) && defined(AF_INET6)
- case XDM_COLLECT_MULTICAST_QUERY:
-#endif
- case XDM_COLLECT_INDIRECT_QUERY:
- XdmcpAddHost(from, fromlen, &authenticationName, &hostname, &status);
- break;
- default:
- break;
- }
- }
- }
- XdmcpDisposeARRAY8 (&authenticationName);
- XdmcpDisposeARRAY8 (&hostname);
- XdmcpDisposeARRAY8 (&status);
-}
-
-static void
-send_request_msg(void)
-{
- XdmcpHeader header;
- int length;
- int i;
- CARD16 XdmcpConnectionType;
- ARRAY8 authenticationData;
- int socketfd = xdmcpSocket;
-
- switch (SOCKADDR_FAMILY(ManagerAddress))
- {
- case AF_INET: XdmcpConnectionType=FamilyInternet; break;
-#if defined(IPv6) && defined(AF_INET6)
- case AF_INET6: XdmcpConnectionType=FamilyInternet6; break;
-#endif
- default: XdmcpConnectionType=0xffff; break;
- }
-
- header.version = XDM_PROTOCOL_VERSION;
- header.opcode = (CARD16) REQUEST;
-
- length = 2; /* display number */
- length += 1 + 2 * ConnectionTypes.length; /* connection types */
- length += 1; /* connection addresses */
- for (i = 0; i < ConnectionAddresses.length; i++)
- length += 2 + ConnectionAddresses.data[i].length;
- authenticationData.length = 0;
- authenticationData.data = 0;
- if (AuthenticationFuncs)
- {
- (*AuthenticationFuncs->Generator) (AuthenticationData,
- &authenticationData,
- REQUEST);
- }
- length += 2 + AuthenticationName->length; /* authentication name */
- length += 2 + authenticationData.length; /* authentication data */
- length += 1; /* authorization names */
- for (i = 0; i < AuthorizationNames.length; i++)
- length += 2 + AuthorizationNames.data[i].length;
- length += 2 + ManufacturerDisplayID.length; /* display ID */
- header.length = length;
-
- if (!XdmcpWriteHeader (&buffer, &header))
- {
- XdmcpDisposeARRAY8 (&authenticationData);
- return;
- }
- XdmcpWriteCARD16 (&buffer, DisplayNumber);
- XdmcpWriteCARD8 (&buffer, ConnectionTypes.length);
-
- /* The connection array is send reordered, so that connections of */
- /* the same address type as the XDMCP manager connection are send */
- /* first. This works around a bug in xdm. mario@klebsch.de */
- for (i = 0; i < (int)ConnectionTypes.length; i++)
- if (ConnectionTypes.data[i]==XdmcpConnectionType)
- XdmcpWriteCARD16 (&buffer, ConnectionTypes.data[i]);
- for (i = 0; i < (int)ConnectionTypes.length; i++)
- if (ConnectionTypes.data[i]!=XdmcpConnectionType)
- XdmcpWriteCARD16 (&buffer, ConnectionTypes.data[i]);
-
- XdmcpWriteCARD8 (&buffer, ConnectionAddresses.length);
- for (i = 0; i < (int)ConnectionAddresses.length; i++)
- if ( (i<ConnectionTypes.length) &&
- (ConnectionTypes.data[i]==XdmcpConnectionType) )
- XdmcpWriteARRAY8 (&buffer, &ConnectionAddresses.data[i]);
- for (i = 0; i < (int)ConnectionAddresses.length; i++)
- if ( (i>=ConnectionTypes.length) ||
- (ConnectionTypes.data[i]!=XdmcpConnectionType) )
- XdmcpWriteARRAY8 (&buffer, &ConnectionAddresses.data[i]);
-
- XdmcpWriteARRAY8 (&buffer, AuthenticationName);
- XdmcpWriteARRAY8 (&buffer, &authenticationData);
- XdmcpDisposeARRAY8 (&authenticationData);
- XdmcpWriteARRAYofARRAY8 (&buffer, &AuthorizationNames);
- XdmcpWriteARRAY8 (&buffer, &ManufacturerDisplayID);
-#if defined(IPv6) && defined(AF_INET6)
- if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6)
- socketfd = xdmcpSocket6;
-#endif
- if (XdmcpFlush (socketfd, &buffer,
- (XdmcpNetaddr) &req_sockaddr, req_socklen))
- state = XDM_AWAIT_REQUEST_RESPONSE;
-}
-
-static void
-recv_accept_msg(unsigned length)
-{
- CARD32 AcceptSessionID;
- ARRAY8 AcceptAuthenticationName, AcceptAuthenticationData;
- ARRAY8 AcceptAuthorizationName, AcceptAuthorizationData;
-
- if (state != XDM_AWAIT_REQUEST_RESPONSE)
- return;
- AcceptAuthenticationName.data = 0;
- AcceptAuthenticationData.data = 0;
- AcceptAuthorizationName.data = 0;
- AcceptAuthorizationData.data = 0;
- if (XdmcpReadCARD32 (&buffer, &AcceptSessionID) &&
- XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationName) &&
- XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationData) &&
- XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationName) &&
- XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationData))
- {
- if (length == 12 + AcceptAuthenticationName.length +
- AcceptAuthenticationData.length +
- AcceptAuthorizationName.length +
- AcceptAuthorizationData.length)
- {
- if (!XdmcpCheckAuthentication (&AcceptAuthenticationName,
- &AcceptAuthenticationData, ACCEPT))
- {
- XdmcpFatal ("Authentication Failure", &AcceptAuthenticationName);
- }
- /* permit access control manipulations from this host */
- AugmentSelf (&req_sockaddr, req_socklen);
- /* if the authorization specified in the packet fails
- * to be acceptable, enable the local addresses
- */
- if (!XdmcpAddAuthorization (&AcceptAuthorizationName,
- &AcceptAuthorizationData))
- {
- AddLocalHosts ();
- }
- SessionID = AcceptSessionID;
- state = XDM_MANAGE;
- send_packet();
- }
- }
- XdmcpDisposeARRAY8 (&AcceptAuthenticationName);
- XdmcpDisposeARRAY8 (&AcceptAuthenticationData);
- XdmcpDisposeARRAY8 (&AcceptAuthorizationName);
- XdmcpDisposeARRAY8 (&AcceptAuthorizationData);
-}
-
-static void
-recv_decline_msg(unsigned length)
-{
- ARRAY8 status, DeclineAuthenticationName, DeclineAuthenticationData;
-
- status.data = 0;
- DeclineAuthenticationName.data = 0;
- DeclineAuthenticationData.data = 0;
- if (XdmcpReadARRAY8 (&buffer, &status) &&
- XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationName) &&
- XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationData))
- {
- if (length == 6 + status.length +
- DeclineAuthenticationName.length +
- DeclineAuthenticationData.length &&
- XdmcpCheckAuthentication (&DeclineAuthenticationName,
- &DeclineAuthenticationData, DECLINE))
- {
- XdmcpFatal ("Session declined", &status);
- }
- }
- XdmcpDisposeARRAY8 (&status);
- XdmcpDisposeARRAY8 (&DeclineAuthenticationName);
- XdmcpDisposeARRAY8 (&DeclineAuthenticationData);
-}
-
-static void
-send_manage_msg(void)
-{
- XdmcpHeader header;
- int socketfd = xdmcpSocket;
-
- header.version = XDM_PROTOCOL_VERSION;
- header.opcode = (CARD16) MANAGE;
- header.length = 8 + DisplayClass.length;
-
- if (!XdmcpWriteHeader (&buffer, &header))
- return;
- XdmcpWriteCARD32 (&buffer, SessionID);
- XdmcpWriteCARD16 (&buffer, DisplayNumber);
- XdmcpWriteARRAY8 (&buffer, &DisplayClass);
- state = XDM_AWAIT_MANAGE_RESPONSE;
-#if defined(IPv6) && defined(AF_INET6)
- if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6)
- socketfd = xdmcpSocket6;
-#endif
- XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen);
-}
-
-static void
-recv_refuse_msg(unsigned length)
-{
- CARD32 RefusedSessionID;
-
- if (state != XDM_AWAIT_MANAGE_RESPONSE)
- return;
- if (length != 4)
- return;
- if (XdmcpReadCARD32 (&buffer, &RefusedSessionID))
- {
- if (RefusedSessionID == SessionID)
- {
- state = XDM_START_CONNECTION;
- send_packet();
- }
- }
-}
-
-static void
-recv_failed_msg(unsigned length)
-{
- CARD32 FailedSessionID;
- ARRAY8 status;
-
- if (state != XDM_AWAIT_MANAGE_RESPONSE)
- return;
- status.data = 0;
- if (XdmcpReadCARD32 (&buffer, &FailedSessionID) &&
- XdmcpReadARRAY8 (&buffer, &status))
- {
- if (length == 6 + status.length &&
- SessionID == FailedSessionID)
- {
- XdmcpFatal ("Session failed", &status);
- }
- }
- XdmcpDisposeARRAY8 (&status);
-}
-
-static void
-send_keepalive_msg(void)
-{
- XdmcpHeader header;
- int socketfd = xdmcpSocket;
-
- header.version = XDM_PROTOCOL_VERSION;
- header.opcode = (CARD16) KEEPALIVE;
- header.length = 6;
-
- XdmcpWriteHeader (&buffer, &header);
- XdmcpWriteCARD16 (&buffer, DisplayNumber);
- XdmcpWriteCARD32 (&buffer, SessionID);
-
- state = XDM_AWAIT_ALIVE_RESPONSE;
-#if defined(IPv6) && defined(AF_INET6)
- if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6)
- socketfd = xdmcpSocket6;
-#endif
- XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen);
-}
-
-static void
-recv_alive_msg (unsigned length)
-{
- CARD8 SessionRunning;
- CARD32 AliveSessionID;
-
- if (state != XDM_AWAIT_ALIVE_RESPONSE)
- return;
- if (length != 5)
- return;
- if (XdmcpReadCARD8 (&buffer, &SessionRunning) &&
- XdmcpReadCARD32 (&buffer, &AliveSessionID))
- {
- if (SessionRunning && AliveSessionID == SessionID)
- {
- /* backoff dormancy period */
- state = XDM_RUN_SESSION;
- if ((GetTimeInMillis() - lastDeviceEventTime.milliseconds) >
- keepaliveDormancy * 1000)
- {
- keepaliveDormancy <<= 1;
- if (keepaliveDormancy > XDM_MAX_DORMANCY)
- keepaliveDormancy = XDM_MAX_DORMANCY;
- }
- timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000;
- }
- else
- {
- XdmcpDeadSession ("Alive response indicates session dead");
- }
- }
-}
-
-static void
-XdmcpFatal (
- const char *type,
- ARRAY8Ptr status)
-{
- FatalError ("XDMCP fatal error: %s %*.*s\n", type,
- status->length, status->length, status->data);
-}
-
-static void
-XdmcpWarning(const char *str)
-{
- ErrorF("XDMCP warning: %s\n", str);
-}
-
-static void
-get_addr_by_name(
- const char *argtype,
- const char *namestr,
- int port,
- int socktype,
- SOCKADDR_TYPE *addr,
- SOCKLEN_TYPE *addrlen
-#if defined(IPv6) && defined(AF_INET6)
- ,
- struct addrinfo **aip,
- struct addrinfo **aifirstp
-#endif
- )
-{
-#if defined(IPv6) && defined(AF_INET6)
- struct addrinfo *ai;
- struct addrinfo hints;
- char portstr[6];
- char *pport = portstr;
- int gaierr;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_socktype = socktype;
-
- if (port == 0) {
- pport = NULL;
- } else if (port > 0 && port < 65535) {
- sprintf(portstr, "%d", port);
- } else {
- FatalError("Xserver: port out of range: %d\n", port);
- }
-
- if (*aifirstp != NULL) {
- freeaddrinfo(*aifirstp);
- *aifirstp = NULL;
- }
-
- if ((gaierr = getaddrinfo(namestr, pport, &hints, aifirstp)) == 0) {
- for (ai = *aifirstp; ai != NULL; ai = ai->ai_next) {
- if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6)
- break;
- }
- if ((ai == NULL) || (ai->ai_addrlen > sizeof(SOCKADDR_TYPE))) {
- FatalError ("Xserver: %s host %s not on supported network type\n",
- argtype, namestr);
- } else {
- *aip = ai;
- *addrlen = ai->ai_addrlen;
- memcpy(addr, ai->ai_addr, ai->ai_addrlen);
- }
- } else {
- FatalError("Xserver: %s: %s %s\n", gai_strerror(gaierr), argtype, namestr);
- }
-#else
- struct hostent *hep;
-#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
- _Xgethostbynameparams hparams;
-#endif
-#if defined(WIN32) && defined(TCPCONN)
- _XSERVTransWSAStartup();
-#endif
- if (!(hep = _XGethostbyname(namestr, hparams)))
- {
- FatalError("Xserver: %s unknown host: %s\n", argtype, namestr);
- }
- if (hep->h_length == sizeof (struct in_addr))
- {
- memmove(&addr->sin_addr, hep->h_addr, hep->h_length);
- *addrlen = sizeof(struct sockaddr_in);
- addr->sin_family = AF_INET;
- addr->sin_port = htons (port);
- }
- else
- {
- FatalError("Xserver: %s host on strange network %s\n", argtype, namestr);
- }
-#endif
-}
-
-static void
-get_manager_by_name(
- int argc,
- char **argv,
- int i)
-{
-
- if ((i + 1) == argc)
- {
- FatalError("Xserver: missing %s host name in command line\n", argv[i]);
- }
-
- get_addr_by_name(argv[i], argv[i+1], xdm_udp_port, SOCK_DGRAM,
- &ManagerAddress, &ManagerAddressLen
-#if defined(IPv6) && defined(AF_INET6)
- , &mgrAddr, &mgrAddrFirst
-#endif
- );
-}
-
-
-static void
-get_fromaddr_by_name(
- int argc,
- char **argv,
- int i)
-{
-#if defined(IPv6) && defined(AF_INET6)
- struct addrinfo *ai = NULL;
- struct addrinfo *aifirst = NULL;
-#endif
- if (i == argc)
- {
- FatalError("Xserver: missing -from host name in command line\n");
- }
- get_addr_by_name("-from", argv[i], 0, 0, &FromAddress, &FromAddressLen
-#if defined(IPv6) && defined(AF_INET6)
- , &ai, &aifirst
-#endif
- );
-#if defined(IPv6) && defined(AF_INET6)
- if (aifirst != NULL)
- freeaddrinfo(aifirst);
-#endif
- xdm_from = argv[i];
-}
-
-
-#if defined(IPv6) && defined(AF_INET6)
-static int
-get_mcast_options(int argc, char **argv, int i)
-{
- char *address = XDM_DEFAULT_MCAST_ADDR6;
- int hopcount = 1;
- struct addrinfo hints;
- char portstr[6];
- int gaierr;
- struct addrinfo *ai, *firstai;
-
- if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) {
- address = argv[i++];
- if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) {
- hopcount = strtol(argv[i++], NULL, 10);
- if ((hopcount < 1) || (hopcount > 255)) {
- FatalError("Xserver: multicast hop count out of range: %d\n",
- hopcount);
- }
- }
- }
-
- if (xdm_udp_port > 0 && xdm_udp_port < 65535) {
- sprintf(portstr, "%d", xdm_udp_port);
- } else {
- FatalError("Xserver: port out of range: %d\n", xdm_udp_port);
- }
- memset(&hints, 0, sizeof(hints));
- hints.ai_socktype = SOCK_DGRAM;
-
- if ((gaierr = getaddrinfo(address, portstr, &hints, &firstai)) == 0) {
- for (ai = firstai; ai != NULL; ai = ai->ai_next) {
- if (((ai->ai_family == AF_INET) &&
- IN_MULTICAST(((struct sockaddr_in *) ai->ai_addr)
- ->sin_addr.s_addr))
- || ((ai->ai_family == AF_INET6) &&
- IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *) ai->ai_addr)
- ->sin6_addr)))
- break;
- }
- if (ai == NULL) {
- FatalError ("Xserver: address not supported multicast type %s\n",
- address);
- } else {
- struct multicastinfo *mcastinfo, *mcl;
-
- mcastinfo = malloc(sizeof(struct multicastinfo));
- mcastinfo->next = NULL;
- mcastinfo->ai = firstai;
- mcastinfo->hops = hopcount;
-
- if (mcastlist == NULL) {
- mcastlist = mcastinfo;
- } else {
- for (mcl = mcastlist; mcl->next != NULL; mcl = mcl->next) {
- /* Do nothing - just find end of list */
- }
- mcl->next = mcastinfo;
- }
- }
- } else {
- FatalError("Xserver: %s: %s\n", gai_strerror(gaierr), address);
- }
- return i;
-}
-#endif
-
-#else
-static int xdmcp_non_empty; /* avoid complaint by ranlib */
-#endif /* XDMCP */
+/* + * Copyright 1989 Network Computing Devices, Inc., Mountain View, California. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of N.C.D. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. N.C.D. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#ifdef WIN32 +#include <X11/Xwinsock.h> +#endif + +#include <X11/Xos.h> + +#if !defined(WIN32) +#include <sys/param.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <X11/X.h> +#include <X11/Xmd.h> +#include "misc.h" +#include <X11/Xpoll.h> +#include "osdep.h" +#include "input.h" +#include "dixstruct.h" +#include "opaque.h" +#include "site.h" + +#ifdef STREAMSCONN +#include <tiuser.h> +#include <netconfig.h> +#include <netdir.h> +#endif + +#ifdef XDMCP +#undef REQUEST + +#ifdef XDMCP_NO_IPV6 +#undef IPv6 +#endif + +#include <X11/Xdmcp.h> + +#define X_INCLUDE_NETDB_H +#include <X11/Xos_r.h> + +static char *defaultDisplayClass = COMPILEDDISPLAYCLASS; + +static int xdmcpSocket, sessionSocket; +static xdmcp_states state; +#if defined(IPv6) && defined(AF_INET6) +static int xdmcpSocket6; +static struct sockaddr_storage req_sockaddr; +#else +static struct sockaddr_in req_sockaddr; +#endif +static int req_socklen; +static CARD32 SessionID; +static CARD32 timeOutTime; +static int timeOutRtx; +static CARD32 defaultKeepaliveDormancy = XDM_DEF_DORMANCY; +static CARD32 keepaliveDormancy = XDM_DEF_DORMANCY; +static CARD16 DisplayNumber; +static xdmcp_states XDM_INIT_STATE = XDM_OFF; +#ifdef HASXDMAUTH +static char *xdmAuthCookie; +#endif + +static XdmcpBuffer buffer; + +#if defined(IPv6) && defined(AF_INET6) + +static struct addrinfo *mgrAddr; +static struct addrinfo *mgrAddrFirst; + +#define SOCKADDR_TYPE struct sockaddr_storage +#define SOCKADDR_FAMILY(s) ((struct sockaddr *)&(s))->sa_family + +#ifdef BSD44SOCKETS +#define SOCKLEN_FIELD(s) ((struct sockaddr *)&(s))->sa_len +#define SOCKLEN_TYPE unsigned char +#else +#define SOCKLEN_TYPE unsigned int +#endif + +#else + +#define SOCKADDR_TYPE struct sockaddr_in +#define SOCKADDR_FAMILY(s) (s).sin_family + +#ifdef BSD44SOCKETS +#define SOCKLEN_FIELD(s) (s).sin_len +#define SOCKLEN_TYPE unsigned char +#else +#define SOCKLEN_TYPE size_t +#endif + +#endif + +static SOCKADDR_TYPE ManagerAddress; +static SOCKADDR_TYPE FromAddress; + +#ifdef SOCKLEN_FIELD +#define ManagerAddressLen SOCKLEN_FIELD(ManagerAddress) +#define FromAddressLen SOCKLEN_FIELD(FromAddress) +#else +static SOCKLEN_TYPE ManagerAddressLen, FromAddressLen; +#endif + +#if defined(IPv6) && defined(AF_INET6) +static struct multicastinfo { + struct multicastinfo *next; + struct addrinfo *ai; + int hops; +} *mcastlist; +#endif + +static void XdmcpAddHost( + const struct sockaddr *from, + int fromlen, + ARRAY8Ptr AuthenticationName, + ARRAY8Ptr hostname, + ARRAY8Ptr status); + +static void XdmcpSelectHost( + const struct sockaddr *host_sockaddr, + int host_len, + ARRAY8Ptr AuthenticationName); + +static void get_xdmcp_sock(void); + +static void send_query_msg(void); + +static void recv_willing_msg( + struct sockaddr * /*from*/, + int /*fromlen*/, + unsigned /*length*/); + +static void send_request_msg(void); + +static void recv_accept_msg(unsigned /*length*/); + +static void recv_decline_msg(unsigned /*length*/); + +static void send_manage_msg(void); + +static void recv_refuse_msg(unsigned /*length*/); + +static void recv_failed_msg(unsigned /*length*/); + +static void send_keepalive_msg(void); + +static void recv_alive_msg(unsigned /*length*/); + +static void XdmcpFatal( + const char * /*type*/, + ARRAY8Ptr /*status*/); + +static void XdmcpWarning(const char * /*str*/); + +static void get_manager_by_name( + int /*argc*/, + char ** /*argv*/, + int /*i*/); + +static void get_fromaddr_by_name(int /*argc*/, char ** /*argv*/, int /*i*/); + +#if defined(IPv6) && defined(AF_INET6) +static int get_mcast_options(int /*argc*/, char ** /*argv*/, int /*i*/); +#endif + +static void receive_packet(int /*socketfd*/); + +static void send_packet(void); + +static void timeout(void); + +static void restart(void); + +static void XdmcpBlockHandler( + pointer /*data*/, + struct timeval ** /*wt*/, + pointer /*LastSelectMask*/); + +static void XdmcpWakeupHandler( + pointer /*data*/, + int /*i*/, + pointer /*LastSelectMask*/); + +/* + * Register the Manufacturer display ID + */ + +static ARRAY8 ManufacturerDisplayID; + +static void +XdmcpRegisterManufacturerDisplayID (const char *name, int length) +{ + int i; + + XdmcpDisposeARRAY8 (&ManufacturerDisplayID); + if (!XdmcpAllocARRAY8 (&ManufacturerDisplayID, length)) + return; + for (i = 0; i < length; i++) + ManufacturerDisplayID.data[i] = (CARD8) name[i]; +} + +static unsigned short xdm_udp_port = XDM_UDP_PORT; +static Bool OneSession = FALSE; +static const char *xdm_from = NULL; + +void +XdmcpUseMsg (void) +{ + ErrorF("-query host-name contact named host for XDMCP\n"); + ErrorF("-broadcast broadcast for XDMCP\n"); +#if defined(IPv6) && defined(AF_INET6) + ErrorF("-multicast [addr [hops]] IPv6 multicast for XDMCP\n"); +#endif + ErrorF("-indirect host-name contact named host for indirect XDMCP\n"); + ErrorF("-port port-num UDP port number to send messages to\n"); + ErrorF("-from local-address specify the local address to connect from\n"); + ErrorF("-once Terminate server after one session\n"); + ErrorF("-class display-class specify display class to send in manage\n"); +#ifdef HASXDMAUTH + ErrorF("-cookie xdm-auth-bits specify the magic cookie for XDMCP\n"); +#endif + ErrorF("-displayID display-id manufacturer display ID for request\n"); +} + +int +XdmcpOptions(int argc, char **argv, int i) +{ + if (strcmp(argv[i], "-query") == 0) { + get_manager_by_name(argc, argv, i++); + XDM_INIT_STATE = XDM_QUERY; + AccessUsingXdmcp (); + return i + 1; + } + if (strcmp(argv[i], "-broadcast") == 0) { + XDM_INIT_STATE = XDM_BROADCAST; + AccessUsingXdmcp (); + return i + 1; + } +#if defined(IPv6) && defined(AF_INET6) + if (strcmp(argv[i], "-multicast") == 0) { + i = get_mcast_options(argc, argv, ++i); + XDM_INIT_STATE = XDM_MULTICAST; + AccessUsingXdmcp (); + return i + 1; + } +#endif + if (strcmp(argv[i], "-indirect") == 0) { + get_manager_by_name(argc, argv, i++); + XDM_INIT_STATE = XDM_INDIRECT; + AccessUsingXdmcp (); + return i + 1; + } + if (strcmp(argv[i], "-port") == 0) { + if (++i == argc) { + FatalError("Xserver: missing port number in command line\n"); + } + xdm_udp_port = (unsigned short) atoi(argv[i]); + return i + 1; + } + if (strcmp(argv[i], "-from") == 0) { + get_fromaddr_by_name(argc, argv, ++i); + return i + 1; + } + if (strcmp(argv[i], "-once") == 0) { + OneSession = TRUE; + return i + 1; + } + if (strcmp(argv[i], "-class") == 0) { + if (++i == argc) { + FatalError("Xserver: missing class name in command line\n"); + } + defaultDisplayClass = argv[i]; + return i + 1; + } +#ifdef HASXDMAUTH + if (strcmp(argv[i], "-cookie") == 0) { + if (++i == argc) { + FatalError("Xserver: missing cookie data in command line\n"); + } + xdmAuthCookie = argv[i]; + return i + 1; + } +#endif + if (strcmp(argv[i], "-displayID") == 0) { + if (++i == argc) { + FatalError("Xserver: missing displayID in command line\n"); + } + XdmcpRegisterManufacturerDisplayID (argv[i], strlen (argv[i])); + return i + 1; + } + return i; +} + +/* + * This section is a collection of routines for + * registering server-specific data with the XDMCP + * state machine. + */ + + +/* + * Save all broadcast addresses away so BroadcastQuery + * packets get sent everywhere + */ + +#define MAX_BROADCAST 10 + +/* This stays sockaddr_in since IPv6 doesn't support broadcast */ +static struct sockaddr_in BroadcastAddresses[MAX_BROADCAST]; +static int NumBroadcastAddresses; + +void +XdmcpRegisterBroadcastAddress (const struct sockaddr_in *addr) +{ + struct sockaddr_in *bcast; + if (NumBroadcastAddresses >= MAX_BROADCAST) + return; + bcast = &BroadcastAddresses[NumBroadcastAddresses++]; + memset(bcast, 0, sizeof (struct sockaddr_in)); +#ifdef BSD44SOCKETS + bcast->sin_len = addr->sin_len; +#endif + bcast->sin_family = addr->sin_family; + bcast->sin_port = htons (xdm_udp_port); + bcast->sin_addr = addr->sin_addr; +} + +/* + * Each authentication type is registered here; Validator + * will be called to check all access attempts using + * the specified authentication type + */ + +static ARRAYofARRAY8 AuthenticationNames, AuthenticationDatas; +typedef struct _AuthenticationFuncs { + ValidatorFunc Validator; + GeneratorFunc Generator; + AddAuthorFunc AddAuth; +} AuthenticationFuncsRec, *AuthenticationFuncsPtr; + +static AuthenticationFuncsPtr AuthenticationFuncsList; + +void +XdmcpRegisterAuthentication ( + const char *name, + int namelen, + const char *data, + int datalen, + ValidatorFunc Validator, + GeneratorFunc Generator, + AddAuthorFunc AddAuth) +{ + int i; + ARRAY8 AuthenticationName, AuthenticationData; + static AuthenticationFuncsPtr newFuncs; + + if (!XdmcpAllocARRAY8 (&AuthenticationName, namelen)) + return; + if (!XdmcpAllocARRAY8 (&AuthenticationData, datalen)) + { + XdmcpDisposeARRAY8 (&AuthenticationName); + return; + } + for (i = 0; i < namelen; i++) + AuthenticationName.data[i] = name[i]; + for (i = 0; i < datalen; i++) + AuthenticationData.data[i] = data[i]; + if (!(XdmcpReallocARRAYofARRAY8 (&AuthenticationNames, + AuthenticationNames.length + 1) && + XdmcpReallocARRAYofARRAY8 (&AuthenticationDatas, + AuthenticationDatas.length + 1) && + (newFuncs = malloc((AuthenticationNames.length + 1) * sizeof (AuthenticationFuncsRec))))) + { + XdmcpDisposeARRAY8 (&AuthenticationName); + XdmcpDisposeARRAY8 (&AuthenticationData); + return; + } + for (i = 0; i < AuthenticationNames.length - 1; i++) + newFuncs[i] = AuthenticationFuncsList[i]; + newFuncs[AuthenticationNames.length-1].Validator = Validator; + newFuncs[AuthenticationNames.length-1].Generator = Generator; + newFuncs[AuthenticationNames.length-1].AddAuth = AddAuth; + free(AuthenticationFuncsList); + AuthenticationFuncsList = newFuncs; + AuthenticationNames.data[AuthenticationNames.length-1] = AuthenticationName; + AuthenticationDatas.data[AuthenticationDatas.length-1] = AuthenticationData; +} + +/* + * Select the authentication type to be used; this is + * set by the manager of the host to be connected to. + */ + +static ARRAY8 noAuthenticationName = {(CARD16) 0, (CARD8Ptr) 0}; +static ARRAY8 noAuthenticationData = {(CARD16) 0, (CARD8Ptr) 0}; +static ARRAY8Ptr AuthenticationName = &noAuthenticationName; +static ARRAY8Ptr AuthenticationData = &noAuthenticationData; +static AuthenticationFuncsPtr AuthenticationFuncs; + +static void +XdmcpSetAuthentication (const ARRAY8Ptr name) +{ + int i; + + for (i = 0; i < AuthenticationNames.length; i++) + if (XdmcpARRAY8Equal (&AuthenticationNames.data[i], name)) + { + AuthenticationName = &AuthenticationNames.data[i]; + AuthenticationData = &AuthenticationDatas.data[i]; + AuthenticationFuncs = &AuthenticationFuncsList[i]; + break; + } +} + +/* + * Register the host address for the display + */ + +static ARRAY16 ConnectionTypes; +static ARRAYofARRAY8 ConnectionAddresses; +static long xdmcpGeneration; + +void +XdmcpRegisterConnection ( + int type, + const char *address, + int addrlen) +{ + int i; + CARD8 *newAddress; + + if (xdmcpGeneration != serverGeneration) + { + XdmcpDisposeARRAY16 (&ConnectionTypes); + XdmcpDisposeARRAYofARRAY8 (&ConnectionAddresses); + xdmcpGeneration = serverGeneration; + } + if (xdm_from != NULL) { /* Only register the requested address */ + const void *regAddr = address; + const void *fromAddr = NULL; + int regAddrlen = addrlen; + + if (addrlen == sizeof(struct in_addr)) { + if (SOCKADDR_FAMILY(FromAddress) == AF_INET) { + fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr; + } +#if defined(IPv6) && defined(AF_INET6) + else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET6) && + IN6_IS_ADDR_V4MAPPED( + &((struct sockaddr_in6 *)&FromAddress)->sin6_addr)) { + fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr.s6_addr[12]; + } +#endif + } +#if defined(IPv6) && defined(AF_INET6) + else if (addrlen == sizeof(struct in6_addr)) { + if (SOCKADDR_FAMILY(FromAddress) == AF_INET6) { + fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr; + } else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET) && + IN6_IS_ADDR_V4MAPPED((struct in6_addr *) address)) { + fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr; + regAddr = &((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr[12]; + regAddrlen = sizeof(struct in_addr); + } + } +#endif + if (!fromAddr || memcmp(regAddr, fromAddr, regAddrlen) != 0) { + return; + } + } + if (ConnectionAddresses.length + 1 == 256) + return; + newAddress = malloc(addrlen * sizeof (CARD8)); + if (!newAddress) + return; + if (!XdmcpReallocARRAY16 (&ConnectionTypes, ConnectionTypes.length + 1)) + { + free(newAddress); + return; + } + if (!XdmcpReallocARRAYofARRAY8 (&ConnectionAddresses, + ConnectionAddresses.length + 1)) + { + free(newAddress); + return; + } + ConnectionTypes.data[ConnectionTypes.length - 1] = (CARD16) type; + for (i = 0; i < addrlen; i++) + newAddress[i] = address[i]; + ConnectionAddresses.data[ConnectionAddresses.length-1].data = newAddress; + ConnectionAddresses.data[ConnectionAddresses.length-1].length = addrlen; +} + +/* + * Register an Authorization Name. XDMCP advertises this list + * to the manager. + */ + +static ARRAYofARRAY8 AuthorizationNames; + +void +XdmcpRegisterAuthorizations (void) +{ + XdmcpDisposeARRAYofARRAY8 (&AuthorizationNames); + RegisterAuthorizations (); +} + +void +XdmcpRegisterAuthorization (const char *name, int namelen) +{ + ARRAY8 authName; + int i; + + authName.data = malloc(namelen * sizeof (CARD8)); + if (!authName.data) + return; + if (!XdmcpReallocARRAYofARRAY8 (&AuthorizationNames, AuthorizationNames.length +1)) + { + free(authName.data); + return; + } + for (i = 0; i < namelen; i++) + authName.data[i] = (CARD8) name[i]; + authName.length = namelen; + AuthorizationNames.data[AuthorizationNames.length-1] = authName; +} + +/* + * Register the DisplayClass string + */ + +static ARRAY8 DisplayClass; + +static void +XdmcpRegisterDisplayClass (const char *name, int length) +{ + int i; + + XdmcpDisposeARRAY8 (&DisplayClass); + if (!XdmcpAllocARRAY8 (&DisplayClass, length)) + return; + for (i = 0; i < length; i++) + DisplayClass.data[i] = (CARD8) name[i]; +} + +/* + * initialize XDMCP; create the socket, compute the display + * number, set up the state machine + */ + +void +XdmcpInit(void) +{ + state = XDM_INIT_STATE; +#ifdef HASXDMAUTH + if (xdmAuthCookie) + XdmAuthenticationInit (xdmAuthCookie, strlen (xdmAuthCookie)); +#endif + if (state != XDM_OFF) + { + XdmcpRegisterAuthorizations(); + XdmcpRegisterDisplayClass (defaultDisplayClass, strlen (defaultDisplayClass)); + AccessUsingXdmcp(); + RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler, + (pointer) 0); + timeOutRtx = 0; + DisplayNumber = (CARD16) atoi(display); + get_xdmcp_sock(); + send_packet(); + } +} + +void +XdmcpReset (void) +{ + state = XDM_INIT_STATE; + if (state != XDM_OFF) + { + RegisterBlockAndWakeupHandlers (XdmcpBlockHandler, XdmcpWakeupHandler, + (pointer) 0); + timeOutRtx = 0; + send_packet(); + } +} + +/* + * Called whenever a new connection is created; notices the + * first connection and saves it to terminate the session + * when it is closed + */ + +void +XdmcpOpenDisplay(int sock) +{ + if (state != XDM_AWAIT_MANAGE_RESPONSE) + return; + state = XDM_RUN_SESSION; + sessionSocket = sock; +} + +void +XdmcpCloseDisplay(int sock) +{ + if ((state != XDM_RUN_SESSION && state != XDM_AWAIT_ALIVE_RESPONSE) + || sessionSocket != sock) + return; + state = XDM_INIT_STATE; + if (OneSession) + dispatchException |= DE_TERMINATE; + else + dispatchException |= DE_RESET; + isItTimeToYield = TRUE; +} + +/* + * called before going to sleep, this routine + * may modify the timeout value about to be sent + * to select; in this way XDMCP can do appropriate things + * dynamically while starting up + */ + +/*ARGSUSED*/ +static void +XdmcpBlockHandler( + pointer data, /* unused */ + struct timeval **wt, + pointer pReadmask) +{ + fd_set *LastSelectMask = (fd_set*)pReadmask; + CARD32 millisToGo; + + if (state == XDM_OFF) + return; + FD_SET(xdmcpSocket, LastSelectMask); +#if defined(IPv6) && defined(AF_INET6) + if (xdmcpSocket6 >= 0) + FD_SET(xdmcpSocket6, LastSelectMask); +#endif + if (timeOutTime == 0) + return; + millisToGo = timeOutTime - GetTimeInMillis(); + if ((int) millisToGo < 0) + millisToGo = 0; + AdjustWaitForDelay (wt, millisToGo); +} + +/* + * called after select returns; this routine will + * recognise when XDMCP packets await and + * process them appropriately + */ + +/*ARGSUSED*/ +static void +XdmcpWakeupHandler( + pointer data, /* unused */ + int i, + pointer pReadmask) +{ + fd_set* LastSelectMask = (fd_set*)pReadmask; + fd_set devicesReadable; + + if (state == XDM_OFF) + return; + if (i > 0) + { + if (FD_ISSET(xdmcpSocket, LastSelectMask)) + { + receive_packet(xdmcpSocket); + FD_CLR(xdmcpSocket, LastSelectMask); + } +#if defined(IPv6) && defined(AF_INET6) + if (xdmcpSocket6 >= 0 && FD_ISSET(xdmcpSocket6, LastSelectMask)) + { + receive_packet(xdmcpSocket6); + FD_CLR(xdmcpSocket6, LastSelectMask); + } +#endif + XFD_ANDSET(&devicesReadable, LastSelectMask, &EnabledDevices); + if (XFD_ANYSET(&devicesReadable)) + { + if (state == XDM_AWAIT_USER_INPUT) + restart(); + else if (state == XDM_RUN_SESSION) + keepaliveDormancy = defaultKeepaliveDormancy; + } + if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION) + timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; + } + else if (timeOutTime && (int) (GetTimeInMillis() - timeOutTime) >= 0) + { + if (state == XDM_RUN_SESSION) + { + state = XDM_KEEPALIVE; + send_packet(); + } + else + timeout(); + } +} + +/* + * This routine should be called from the routine that drives the + * user's host menu when the user selects a host + */ + +static void +XdmcpSelectHost( + const struct sockaddr *host_sockaddr, + int host_len, + ARRAY8Ptr AuthenticationName) +{ + state = XDM_START_CONNECTION; + memmove(&req_sockaddr, host_sockaddr, host_len); + req_socklen = host_len; + XdmcpSetAuthentication (AuthenticationName); + send_packet(); +} + +/* + * !!! this routine should be replaced by a routine that adds + * the host to the user's host menu. the current version just + * selects the first host to respond with willing message. + */ + +/*ARGSUSED*/ +static void +XdmcpAddHost( + const struct sockaddr *from, + int fromlen, + ARRAY8Ptr AuthenticationName, + ARRAY8Ptr hostname, + ARRAY8Ptr status) +{ + XdmcpSelectHost(from, fromlen, AuthenticationName); +} + +/* + * A message is queued on the socket; read it and + * do the appropriate thing + */ + +static ARRAY8 UnwillingMessage = { (CARD8) 14, (CARD8 *) "Host unwilling" }; + +static void +receive_packet(int socketfd) +{ +#if defined(IPv6) && defined(AF_INET6) + struct sockaddr_storage from; +#else + struct sockaddr_in from; +#endif + int fromlen = sizeof(from); + XdmcpHeader header; + + /* read message off socket */ + if (!XdmcpFill (socketfd, &buffer, (XdmcpNetaddr) &from, &fromlen)) + return; + + /* reset retransmission backoff */ + timeOutRtx = 0; + + if (!XdmcpReadHeader (&buffer, &header)) + return; + + if (header.version != XDM_PROTOCOL_VERSION) + return; + + switch (header.opcode) { + case WILLING: + recv_willing_msg((struct sockaddr *) &from, fromlen, header.length); + break; + case UNWILLING: + XdmcpFatal("Manager unwilling", &UnwillingMessage); + break; + case ACCEPT: + recv_accept_msg(header.length); + break; + case DECLINE: + recv_decline_msg(header.length); + break; + case REFUSE: + recv_refuse_msg(header.length); + break; + case FAILED: + recv_failed_msg(header.length); + break; + case ALIVE: + recv_alive_msg(header.length); + break; + } +} + +/* + * send the appropriate message given the current state + */ + +static void +send_packet(void) +{ + int rtx; + switch (state) { + case XDM_QUERY: + case XDM_BROADCAST: + case XDM_INDIRECT: +#if defined(IPv6) && defined(AF_INET6) + case XDM_MULTICAST: +#endif + send_query_msg(); + break; + case XDM_START_CONNECTION: + send_request_msg(); + break; + case XDM_MANAGE: + send_manage_msg(); + break; + case XDM_KEEPALIVE: + send_keepalive_msg(); + break; + default: + break; + } + rtx = (XDM_MIN_RTX << timeOutRtx); + if (rtx > XDM_MAX_RTX) + rtx = XDM_MAX_RTX; + timeOutTime = GetTimeInMillis() + rtx * 1000; +} + +/* + * The session is declared dead for some reason; too many + * timeouts, or Keepalive failure. + */ + +static void +XdmcpDeadSession (const char *reason) +{ + ErrorF ("XDM: %s, declaring session dead\n", reason); + state = XDM_INIT_STATE; + isItTimeToYield = TRUE; + dispatchException |= DE_RESET; + timeOutTime = 0; + timeOutRtx = 0; + send_packet(); +} + +/* + * Timeout waiting for an XDMCP response. + */ + +static void +timeout(void) +{ + timeOutRtx++; + if (state == XDM_AWAIT_ALIVE_RESPONSE && timeOutRtx >= XDM_KA_RTX_LIMIT ) + { + XdmcpDeadSession ("too many keepalive retransmissions"); + return; + } + else if (timeOutRtx >= XDM_RTX_LIMIT) + { + /* Quit if "-once" specified, otherwise reset and try again. */ + if (OneSession) { + dispatchException |= DE_TERMINATE; + ErrorF("XDM: too many retransmissions\n"); + } else { + XdmcpDeadSession("too many retransmissions"); + } + return; + } + +#if defined(IPv6) && defined(AF_INET6) + if (state == XDM_COLLECT_QUERY || state == XDM_COLLECT_INDIRECT_QUERY) { + /* Try next address */ + for (mgrAddr = mgrAddr->ai_next; ; mgrAddr = mgrAddr->ai_next) { + if (mgrAddr == NULL) { + mgrAddr = mgrAddrFirst; + } + if (mgrAddr->ai_family == AF_INET + || mgrAddr->ai_family == AF_INET6) + break; + } +#ifndef SIN6_LEN + ManagerAddressLen = mgrAddr->ai_addrlen; +#endif + memcpy(&ManagerAddress, mgrAddr->ai_addr, mgrAddr->ai_addrlen); + } +#endif + + switch (state) { + case XDM_COLLECT_QUERY: + state = XDM_QUERY; + break; + case XDM_COLLECT_BROADCAST_QUERY: + state = XDM_BROADCAST; + break; +#if defined(IPv6) && defined(AF_INET6) + case XDM_COLLECT_MULTICAST_QUERY: + state = XDM_MULTICAST; + break; +#endif + case XDM_COLLECT_INDIRECT_QUERY: + state = XDM_INDIRECT; + break; + case XDM_AWAIT_REQUEST_RESPONSE: + state = XDM_START_CONNECTION; + break; + case XDM_AWAIT_MANAGE_RESPONSE: + state = XDM_MANAGE; + break; + case XDM_AWAIT_ALIVE_RESPONSE: + state = XDM_KEEPALIVE; + break; + default: + break; + } + send_packet(); +} + +static void +restart(void) +{ + state = XDM_INIT_STATE; + timeOutRtx = 0; + send_packet(); +} + +static int +XdmcpCheckAuthentication (ARRAY8Ptr Name, ARRAY8Ptr Data, int packet_type) +{ + return (XdmcpARRAY8Equal (Name, AuthenticationName) && + (AuthenticationName->length == 0 || + (*AuthenticationFuncs->Validator) (AuthenticationData, Data, packet_type))); +} + +static int +XdmcpAddAuthorization (ARRAY8Ptr name, ARRAY8Ptr data) +{ + AddAuthorFunc AddAuth; + + if (AuthenticationFuncs && AuthenticationFuncs->AddAuth) + AddAuth = AuthenticationFuncs->AddAuth; + else + AddAuth = AddAuthorization; + return (*AddAuth) ((unsigned short)name->length, + (char *)name->data, + (unsigned short)data->length, + (char *)data->data); +} + +/* + * from here to the end of this file are routines private + * to the state machine. + */ + +static void +get_xdmcp_sock(void) +{ +#ifdef STREAMSCONN + struct netconfig *nconf; + + if ((xdmcpSocket = t_open("/dev/udp", O_RDWR, 0)) < 0) { + XdmcpWarning("t_open() of /dev/udp failed"); + return; + } + + if( t_bind(xdmcpSocket,NULL,NULL) < 0 ) { + XdmcpWarning("UDP socket creation failed"); + t_error("t_bind(xdmcpSocket) failed" ); + t_close(xdmcpSocket); + return; + } + + /* + * This part of the code looks contrived. It will actually fit in nicely + * when the CLTS part of Xtrans is implemented. + */ + + if( (nconf=getnetconfigent("udp")) == NULL ) { + XdmcpWarning("UDP socket creation failed: getnetconfigent()"); + t_unbind(xdmcpSocket); + t_close(xdmcpSocket); + return; + } + + if( netdir_options(nconf, ND_SET_BROADCAST, xdmcpSocket, NULL) ) { + XdmcpWarning("UDP set broadcast option failed: netdir_options()"); + freenetconfigent(nconf); + t_unbind(xdmcpSocket); + t_close(xdmcpSocket); + return; + } + + freenetconfigent(nconf); +#else + int soopts = 1; + +#if defined(IPv6) && defined(AF_INET6) + if ((xdmcpSocket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + XdmcpWarning("INET6 UDP socket creation failed"); +#endif + if ((xdmcpSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + XdmcpWarning("UDP socket creation failed"); +#ifdef SO_BROADCAST + else if (setsockopt(xdmcpSocket, SOL_SOCKET, SO_BROADCAST, (char *)&soopts, + sizeof(soopts)) < 0) + XdmcpWarning("UDP set broadcast socket-option failed"); +#endif /* SO_BROADCAST */ + if (xdmcpSocket >= 0 && xdm_from != NULL) { + if (bind(xdmcpSocket, (struct sockaddr *)&FromAddress, + FromAddressLen) < 0) { + FatalError("Xserver: failed to bind to -from address: %s\n", xdm_from); + } + } +#endif /* STREAMSCONN */ +} + +static void +send_query_msg(void) +{ + XdmcpHeader header; + Bool broadcast = FALSE; +#if defined(IPv6) && defined(AF_INET6) + Bool multicast = FALSE; +#endif + int i; + int socketfd = xdmcpSocket; + + header.version = XDM_PROTOCOL_VERSION; + switch(state){ + case XDM_QUERY: + header.opcode = (CARD16) QUERY; + state = XDM_COLLECT_QUERY; + break; + case XDM_BROADCAST: + header.opcode = (CARD16) BROADCAST_QUERY; + state = XDM_COLLECT_BROADCAST_QUERY; + broadcast = TRUE; + break; +#if defined(IPv6) && defined(AF_INET6) + case XDM_MULTICAST: + header.opcode = (CARD16) BROADCAST_QUERY; + state = XDM_COLLECT_MULTICAST_QUERY; + multicast = TRUE; + break; +#endif + case XDM_INDIRECT: + header.opcode = (CARD16) INDIRECT_QUERY; + state = XDM_COLLECT_INDIRECT_QUERY; + break; + default: + break; + } + header.length = 1; + for (i = 0; i < AuthenticationNames.length; i++) + header.length += 2 + AuthenticationNames.data[i].length; + + XdmcpWriteHeader (&buffer, &header); + XdmcpWriteARRAYofARRAY8 (&buffer, &AuthenticationNames); + if (broadcast) + { + int i; + + for (i = 0; i < NumBroadcastAddresses; i++) + XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &BroadcastAddresses[i], + sizeof (struct sockaddr_in)); + } +#if defined(IPv6) && defined(AF_INET6) + else if (multicast) + { + struct multicastinfo *mcl; + struct addrinfo *ai; + + for (mcl = mcastlist; mcl != NULL; mcl = mcl->next) { + for (ai = mcl->ai ; ai != NULL; ai = ai->ai_next) { + if (ai->ai_family == AF_INET) { + unsigned char hopflag = (unsigned char) mcl->hops; + socketfd = xdmcpSocket; + setsockopt(socketfd, IPPROTO_IP, IP_MULTICAST_TTL, + &hopflag, sizeof(hopflag)); + } else if (ai->ai_family == AF_INET6) { + int hopflag6 = mcl->hops; + socketfd = xdmcpSocket6; + setsockopt(socketfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, + &hopflag6, sizeof(hopflag6)); + } else { + continue; + } + XdmcpFlush (socketfd, &buffer, + (XdmcpNetaddr) ai->ai_addr, ai->ai_addrlen); + break; + } + } + } +#endif + else + { +#if defined(IPv6) && defined(AF_INET6) + if (SOCKADDR_FAMILY(ManagerAddress) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &ManagerAddress, + ManagerAddressLen); + } +} + +static void +recv_willing_msg( + struct sockaddr *from, + int fromlen, + unsigned length) +{ + ARRAY8 authenticationName; + ARRAY8 hostname; + ARRAY8 status; + + authenticationName.data = 0; + hostname.data = 0; + status.data = 0; + if (XdmcpReadARRAY8 (&buffer, &authenticationName) && + XdmcpReadARRAY8 (&buffer, &hostname) && + XdmcpReadARRAY8 (&buffer, &status)) + { + if (length == 6 + authenticationName.length + + hostname.length + status.length) + { + switch (state) + { + case XDM_COLLECT_QUERY: + XdmcpSelectHost(from, fromlen, &authenticationName); + break; + case XDM_COLLECT_BROADCAST_QUERY: +#if defined(IPv6) && defined(AF_INET6) + case XDM_COLLECT_MULTICAST_QUERY: +#endif + case XDM_COLLECT_INDIRECT_QUERY: + XdmcpAddHost(from, fromlen, &authenticationName, &hostname, &status); + break; + default: + break; + } + } + } + XdmcpDisposeARRAY8 (&authenticationName); + XdmcpDisposeARRAY8 (&hostname); + XdmcpDisposeARRAY8 (&status); +} + +static void +send_request_msg(void) +{ + XdmcpHeader header; + int length; + int i; + CARD16 XdmcpConnectionType; + ARRAY8 authenticationData; + int socketfd = xdmcpSocket; + + switch (SOCKADDR_FAMILY(ManagerAddress)) + { + case AF_INET: XdmcpConnectionType=FamilyInternet; break; +#if defined(IPv6) && defined(AF_INET6) + case AF_INET6: XdmcpConnectionType=FamilyInternet6; break; +#endif + default: XdmcpConnectionType=0xffff; break; + } + + header.version = XDM_PROTOCOL_VERSION; + header.opcode = (CARD16) REQUEST; + + length = 2; /* display number */ + length += 1 + 2 * ConnectionTypes.length; /* connection types */ + length += 1; /* connection addresses */ + for (i = 0; i < ConnectionAddresses.length; i++) + length += 2 + ConnectionAddresses.data[i].length; + authenticationData.length = 0; + authenticationData.data = 0; + if (AuthenticationFuncs) + { + (*AuthenticationFuncs->Generator) (AuthenticationData, + &authenticationData, + REQUEST); + } + length += 2 + AuthenticationName->length; /* authentication name */ + length += 2 + authenticationData.length; /* authentication data */ + length += 1; /* authorization names */ + for (i = 0; i < AuthorizationNames.length; i++) + length += 2 + AuthorizationNames.data[i].length; + length += 2 + ManufacturerDisplayID.length; /* display ID */ + header.length = length; + + if (!XdmcpWriteHeader (&buffer, &header)) + { + XdmcpDisposeARRAY8 (&authenticationData); + return; + } + XdmcpWriteCARD16 (&buffer, DisplayNumber); + XdmcpWriteCARD8 (&buffer, ConnectionTypes.length); + + /* The connection array is send reordered, so that connections of */ + /* the same address type as the XDMCP manager connection are send */ + /* first. This works around a bug in xdm. mario@klebsch.de */ + for (i = 0; i < (int)ConnectionTypes.length; i++) + if (ConnectionTypes.data[i]==XdmcpConnectionType) + XdmcpWriteCARD16 (&buffer, ConnectionTypes.data[i]); + for (i = 0; i < (int)ConnectionTypes.length; i++) + if (ConnectionTypes.data[i]!=XdmcpConnectionType) + XdmcpWriteCARD16 (&buffer, ConnectionTypes.data[i]); + + XdmcpWriteCARD8 (&buffer, ConnectionAddresses.length); + for (i = 0; i < (int)ConnectionAddresses.length; i++) + if ( (i<ConnectionTypes.length) && + (ConnectionTypes.data[i]==XdmcpConnectionType) ) + XdmcpWriteARRAY8 (&buffer, &ConnectionAddresses.data[i]); + for (i = 0; i < (int)ConnectionAddresses.length; i++) + if ( (i>=ConnectionTypes.length) || + (ConnectionTypes.data[i]!=XdmcpConnectionType) ) + XdmcpWriteARRAY8 (&buffer, &ConnectionAddresses.data[i]); + + XdmcpWriteARRAY8 (&buffer, AuthenticationName); + XdmcpWriteARRAY8 (&buffer, &authenticationData); + XdmcpDisposeARRAY8 (&authenticationData); + XdmcpWriteARRAYofARRAY8 (&buffer, &AuthorizationNames); + XdmcpWriteARRAY8 (&buffer, &ManufacturerDisplayID); +#if defined(IPv6) && defined(AF_INET6) + if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + if (XdmcpFlush (socketfd, &buffer, + (XdmcpNetaddr) &req_sockaddr, req_socklen)) + state = XDM_AWAIT_REQUEST_RESPONSE; +} + +static void +recv_accept_msg(unsigned length) +{ + CARD32 AcceptSessionID; + ARRAY8 AcceptAuthenticationName, AcceptAuthenticationData; + ARRAY8 AcceptAuthorizationName, AcceptAuthorizationData; + + if (state != XDM_AWAIT_REQUEST_RESPONSE) + return; + AcceptAuthenticationName.data = 0; + AcceptAuthenticationData.data = 0; + AcceptAuthorizationName.data = 0; + AcceptAuthorizationData.data = 0; + if (XdmcpReadCARD32 (&buffer, &AcceptSessionID) && + XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationName) && + XdmcpReadARRAY8 (&buffer, &AcceptAuthenticationData) && + XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationName) && + XdmcpReadARRAY8 (&buffer, &AcceptAuthorizationData)) + { + if (length == 12 + AcceptAuthenticationName.length + + AcceptAuthenticationData.length + + AcceptAuthorizationName.length + + AcceptAuthorizationData.length) + { + if (!XdmcpCheckAuthentication (&AcceptAuthenticationName, + &AcceptAuthenticationData, ACCEPT)) + { + XdmcpFatal ("Authentication Failure", &AcceptAuthenticationName); + } + /* permit access control manipulations from this host */ + AugmentSelf (&req_sockaddr, req_socklen); + /* if the authorization specified in the packet fails + * to be acceptable, enable the local addresses + */ + if (!XdmcpAddAuthorization (&AcceptAuthorizationName, + &AcceptAuthorizationData)) + { + AddLocalHosts (); + } + SessionID = AcceptSessionID; + state = XDM_MANAGE; + send_packet(); + } + } + XdmcpDisposeARRAY8 (&AcceptAuthenticationName); + XdmcpDisposeARRAY8 (&AcceptAuthenticationData); + XdmcpDisposeARRAY8 (&AcceptAuthorizationName); + XdmcpDisposeARRAY8 (&AcceptAuthorizationData); +} + +static void +recv_decline_msg(unsigned length) +{ + ARRAY8 status, DeclineAuthenticationName, DeclineAuthenticationData; + + status.data = 0; + DeclineAuthenticationName.data = 0; + DeclineAuthenticationData.data = 0; + if (XdmcpReadARRAY8 (&buffer, &status) && + XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationName) && + XdmcpReadARRAY8 (&buffer, &DeclineAuthenticationData)) + { + if (length == 6 + status.length + + DeclineAuthenticationName.length + + DeclineAuthenticationData.length && + XdmcpCheckAuthentication (&DeclineAuthenticationName, + &DeclineAuthenticationData, DECLINE)) + { + XdmcpFatal ("Session declined", &status); + } + } + XdmcpDisposeARRAY8 (&status); + XdmcpDisposeARRAY8 (&DeclineAuthenticationName); + XdmcpDisposeARRAY8 (&DeclineAuthenticationData); +} + +static void +send_manage_msg(void) +{ + XdmcpHeader header; + int socketfd = xdmcpSocket; + + header.version = XDM_PROTOCOL_VERSION; + header.opcode = (CARD16) MANAGE; + header.length = 8 + DisplayClass.length; + + if (!XdmcpWriteHeader (&buffer, &header)) + return; + XdmcpWriteCARD32 (&buffer, SessionID); + XdmcpWriteCARD16 (&buffer, DisplayNumber); + XdmcpWriteARRAY8 (&buffer, &DisplayClass); + state = XDM_AWAIT_MANAGE_RESPONSE; +#if defined(IPv6) && defined(AF_INET6) + if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); +} + +static void +recv_refuse_msg(unsigned length) +{ + CARD32 RefusedSessionID; + + if (state != XDM_AWAIT_MANAGE_RESPONSE) + return; + if (length != 4) + return; + if (XdmcpReadCARD32 (&buffer, &RefusedSessionID)) + { + if (RefusedSessionID == SessionID) + { + state = XDM_START_CONNECTION; + send_packet(); + } + } +} + +static void +recv_failed_msg(unsigned length) +{ + CARD32 FailedSessionID; + ARRAY8 status; + + if (state != XDM_AWAIT_MANAGE_RESPONSE) + return; + status.data = 0; + if (XdmcpReadCARD32 (&buffer, &FailedSessionID) && + XdmcpReadARRAY8 (&buffer, &status)) + { + if (length == 6 + status.length && + SessionID == FailedSessionID) + { + XdmcpFatal ("Session failed", &status); + } + } + XdmcpDisposeARRAY8 (&status); +} + +static void +send_keepalive_msg(void) +{ + XdmcpHeader header; + int socketfd = xdmcpSocket; + + header.version = XDM_PROTOCOL_VERSION; + header.opcode = (CARD16) KEEPALIVE; + header.length = 6; + + XdmcpWriteHeader (&buffer, &header); + XdmcpWriteCARD16 (&buffer, DisplayNumber); + XdmcpWriteCARD32 (&buffer, SessionID); + + state = XDM_AWAIT_ALIVE_RESPONSE; +#if defined(IPv6) && defined(AF_INET6) + if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); +} + +static void +recv_alive_msg (unsigned length) +{ + CARD8 SessionRunning; + CARD32 AliveSessionID; + + if (state != XDM_AWAIT_ALIVE_RESPONSE) + return; + if (length != 5) + return; + if (XdmcpReadCARD8 (&buffer, &SessionRunning) && + XdmcpReadCARD32 (&buffer, &AliveSessionID)) + { + if (SessionRunning && AliveSessionID == SessionID) + { + /* backoff dormancy period */ + state = XDM_RUN_SESSION; + if ((GetTimeInMillis() - lastDeviceEventTime.milliseconds) > + keepaliveDormancy * 1000) + { + keepaliveDormancy <<= 1; + if (keepaliveDormancy > XDM_MAX_DORMANCY) + keepaliveDormancy = XDM_MAX_DORMANCY; + } + timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; + } + else + { + XdmcpDeadSession ("Alive response indicates session dead"); + } + } +} + +static void +XdmcpFatal ( + const char *type, + ARRAY8Ptr status) +{ + FatalError ("XDMCP fatal error: %s %*.*s\n", type, + status->length, status->length, status->data); +} + +static void +XdmcpWarning(const char *str) +{ + ErrorF("XDMCP warning: %s\n", str); +} + +static void +get_addr_by_name( + const char *argtype, + const char *namestr, + int port, + int socktype, + SOCKADDR_TYPE *addr, + SOCKLEN_TYPE *addrlen +#if defined(IPv6) && defined(AF_INET6) + , + struct addrinfo **aip, + struct addrinfo **aifirstp +#endif + ) +{ +#if defined(IPv6) && defined(AF_INET6) + struct addrinfo *ai; + struct addrinfo hints; + char portstr[6]; + char *pport = portstr; + int gaierr; + + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = socktype; + + if (port == 0) { + pport = NULL; + } else if (port > 0 && port < 65535) { + snprintf(portstr, sizeof(portstr), "%d", port); + } else { + FatalError("Xserver: port out of range: %d\n", port); + } + + if (*aifirstp != NULL) { + freeaddrinfo(*aifirstp); + *aifirstp = NULL; + } + + if ((gaierr = getaddrinfo(namestr, pport, &hints, aifirstp)) == 0) { + for (ai = *aifirstp; ai != NULL; ai = ai->ai_next) { + if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6) + break; + } + if ((ai == NULL) || (ai->ai_addrlen > sizeof(SOCKADDR_TYPE))) { + FatalError ("Xserver: %s host %s not on supported network type\n", + argtype, namestr); + } else { + *aip = ai; + *addrlen = ai->ai_addrlen; + memcpy(addr, ai->ai_addr, ai->ai_addrlen); + } + } else { + FatalError("Xserver: %s: %s %s\n", gai_strerror(gaierr), argtype, namestr); + } +#else + struct hostent *hep; +#ifdef XTHREADS_NEEDS_BYNAMEPARAMS + _Xgethostbynameparams hparams; +#endif +#if defined(WIN32) && defined(TCPCONN) + _XSERVTransWSAStartup(); +#endif + if (!(hep = _XGethostbyname(namestr, hparams))) + { + FatalError("Xserver: %s unknown host: %s\n", argtype, namestr); + } + if (hep->h_length == sizeof (struct in_addr)) + { + memmove(&addr->sin_addr, hep->h_addr, hep->h_length); + *addrlen = sizeof(struct sockaddr_in); + addr->sin_family = AF_INET; + addr->sin_port = htons (port); + } + else + { + FatalError("Xserver: %s host on strange network %s\n", argtype, namestr); + } +#endif +} + +static void +get_manager_by_name( + int argc, + char **argv, + int i) +{ + + if ((i + 1) == argc) + { + FatalError("Xserver: missing %s host name in command line\n", argv[i]); + } + + get_addr_by_name(argv[i], argv[i+1], xdm_udp_port, SOCK_DGRAM, + &ManagerAddress, &ManagerAddressLen +#if defined(IPv6) && defined(AF_INET6) + , &mgrAddr, &mgrAddrFirst +#endif + ); +} + + +static void +get_fromaddr_by_name( + int argc, + char **argv, + int i) +{ +#if defined(IPv6) && defined(AF_INET6) + struct addrinfo *ai = NULL; + struct addrinfo *aifirst = NULL; +#endif + if (i == argc) + { + FatalError("Xserver: missing -from host name in command line\n"); + } + get_addr_by_name("-from", argv[i], 0, 0, &FromAddress, &FromAddressLen +#if defined(IPv6) && defined(AF_INET6) + , &ai, &aifirst +#endif + ); +#if defined(IPv6) && defined(AF_INET6) + if (aifirst != NULL) + freeaddrinfo(aifirst); +#endif + xdm_from = argv[i]; +} + + +#if defined(IPv6) && defined(AF_INET6) +static int +get_mcast_options(int argc, char **argv, int i) +{ + char *address = XDM_DEFAULT_MCAST_ADDR6; + int hopcount = 1; + struct addrinfo hints; + char portstr[6]; + int gaierr; + struct addrinfo *ai, *firstai; + + if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) { + address = argv[i++]; + if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) { + hopcount = strtol(argv[i++], NULL, 10); + if ((hopcount < 1) || (hopcount > 255)) { + FatalError("Xserver: multicast hop count out of range: %d\n", + hopcount); + } + } + } + + if (xdm_udp_port > 0 && xdm_udp_port < 65535) { + snprintf(portstr, sizeof(portstr), "%d", xdm_udp_port); + } else { + FatalError("Xserver: port out of range: %d\n", xdm_udp_port); + } + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_DGRAM; + + if ((gaierr = getaddrinfo(address, portstr, &hints, &firstai)) == 0) { + for (ai = firstai; ai != NULL; ai = ai->ai_next) { + if (((ai->ai_family == AF_INET) && + IN_MULTICAST(((struct sockaddr_in *) ai->ai_addr) + ->sin_addr.s_addr)) + || ((ai->ai_family == AF_INET6) && + IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *) ai->ai_addr) + ->sin6_addr))) + break; + } + if (ai == NULL) { + FatalError ("Xserver: address not supported multicast type %s\n", + address); + } else { + struct multicastinfo *mcastinfo, *mcl; + + mcastinfo = malloc(sizeof(struct multicastinfo)); + mcastinfo->next = NULL; + mcastinfo->ai = firstai; + mcastinfo->hops = hopcount; + + if (mcastlist == NULL) { + mcastlist = mcastinfo; + } else { + for (mcl = mcastlist; mcl->next != NULL; mcl = mcl->next) { + /* Do nothing - just find end of list */ + } + mcl->next = mcastinfo; + } + } + } else { + FatalError("Xserver: %s: %s\n", gai_strerror(gaierr), address); + } + return i; +} +#endif + +#else +static int xdmcp_non_empty; /* avoid complaint by ranlib */ +#endif /* XDMCP */ diff --git a/xorg-server/randr/randrstr.h b/xorg-server/randr/randrstr.h index 262a16420..842e0e05b 100644 --- a/xorg-server/randr/randrstr.h +++ b/xorg-server/randr/randrstr.h @@ -1,974 +1,969 @@ -/*
- * Copyright © 2000 Compaq Computer Corporation
- * Copyright © 2002 Hewlett-Packard Company
- * Copyright © 2006 Intel Corporation
- * Copyright © 2008 Red Hat, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting documentation, and
- * that the name of the copyright holders not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no representations
- * about the suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
- * OF THIS SOFTWARE.
- *
- * Author: Jim Gettys, Hewlett-Packard Company, Inc.
- * Keith Packard, Intel Corporation
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef _RANDRSTR_H_
-#define _RANDRSTR_H_
-
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "os.h"
-#include "dixstruct.h"
-#include "resource.h"
-#include "scrnintstr.h"
-#include "windowstr.h"
-#include "pixmapstr.h"
-#include "extnsionst.h"
-#include "servermd.h"
-#include "rrtransform.h"
-#include <X11/extensions/randr.h>
-#include <X11/extensions/randrproto.h>
-#include <X11/extensions/render.h> /* we share subpixel order information */
-#include "picturestr.h"
-#include <X11/Xfuncproto.h>
-
-/* required for ABI compatibility for now */
-#define RANDR_10_INTERFACE 1
-#define RANDR_12_INTERFACE 1
-#define RANDR_13_INTERFACE 1 /* requires RANDR_12_INTERFACE */
-#define RANDR_GET_CRTC_INTERFACE 1
-
-#define RANDR_INTERFACE_VERSION 0x0103
-
-typedef XID RRMode;
-typedef XID RROutput;
-typedef XID RRCrtc;
-
-extern _X_EXPORT int RREventBase, RRErrorBase;
-
-extern _X_EXPORT int (*ProcRandrVector[RRNumberRequests])(ClientPtr);
-extern _X_EXPORT int (*SProcRandrVector[RRNumberRequests])(ClientPtr);
-
-/*
- * Modeline for a monitor. Name follows directly after this struct
- */
-
-#define RRModeName(pMode) ((char *) (pMode + 1))
-typedef struct _rrMode RRModeRec, *RRModePtr;
-typedef struct _rrPropertyValue RRPropertyValueRec, *RRPropertyValuePtr;
-typedef struct _rrProperty RRPropertyRec, *RRPropertyPtr;
-typedef struct _rrCrtc RRCrtcRec, *RRCrtcPtr;
-typedef struct _rrOutput RROutputRec, *RROutputPtr;
-
-struct _rrMode {
- int refcnt;
- xRRModeInfo mode;
- char *name;
- ScreenPtr userScreen;
-};
-
-struct _rrPropertyValue {
- Atom type; /* ignored by server */
- short format; /* format of data for swapping - 8,16,32 */
- long size; /* size of data in (format/8) bytes */
- pointer data; /* private to client */
-};
-
-struct _rrProperty {
- RRPropertyPtr next;
- ATOM propertyName;
- Bool is_pending;
- Bool range;
- Bool immutable;
- int num_valid;
- INT32 *valid_values;
- RRPropertyValueRec current, pending;
-};
-
-struct _rrCrtc {
- RRCrtc id;
- ScreenPtr pScreen;
- RRModePtr mode;
- int x, y;
- Rotation rotation;
- Rotation rotations;
- Bool changed;
- int numOutputs;
- RROutputPtr *outputs;
- int gammaSize;
- CARD16 *gammaRed;
- CARD16 *gammaBlue;
- CARD16 *gammaGreen;
- void *devPrivate;
- Bool transforms;
- RRTransformRec client_pending_transform;
- RRTransformRec client_current_transform;
- PictTransform transform;
- struct pict_f_transform f_transform;
- struct pict_f_transform f_inverse;
-};
-
-struct _rrOutput {
- RROutput id;
- ScreenPtr pScreen;
- char *name;
- int nameLength;
- CARD8 connection;
- CARD8 subpixelOrder;
- int mmWidth;
- int mmHeight;
- RRCrtcPtr crtc;
- int numCrtcs;
- RRCrtcPtr *crtcs;
- int numClones;
- RROutputPtr *clones;
- int numModes;
- int numPreferred;
- RRModePtr *modes;
- int numUserModes;
- RRModePtr *userModes;
- Bool changed;
- RRPropertyPtr properties;
- Bool pendingProperties;
- void *devPrivate;
-};
-
-#if RANDR_12_INTERFACE
-typedef Bool (*RRScreenSetSizeProcPtr) (ScreenPtr pScreen,
- CARD16 width,
- CARD16 height,
- CARD32 mmWidth,
- CARD32 mmHeight);
-
-typedef Bool (*RRCrtcSetProcPtr) (ScreenPtr pScreen,
- RRCrtcPtr crtc,
- RRModePtr mode,
- int x,
- int y,
- Rotation rotation,
- int numOutputs,
- RROutputPtr *outputs);
-
-typedef Bool (*RRCrtcSetGammaProcPtr) (ScreenPtr pScreen,
- RRCrtcPtr crtc);
-
-typedef Bool (*RRCrtcGetGammaProcPtr) (ScreenPtr pScreen,
- RRCrtcPtr crtc);
-
-typedef Bool (*RROutputSetPropertyProcPtr) (ScreenPtr pScreen,
- RROutputPtr output,
- Atom property,
- RRPropertyValuePtr value);
-
-typedef Bool (*RROutputValidateModeProcPtr) (ScreenPtr pScreen,
- RROutputPtr output,
- RRModePtr mode);
-
-typedef void (*RRModeDestroyProcPtr) (ScreenPtr pScreen,
- RRModePtr mode);
-
-#endif
-
-#if RANDR_13_INTERFACE
-typedef Bool (*RROutputGetPropertyProcPtr) (ScreenPtr pScreen,
- RROutputPtr output,
- Atom property);
-typedef Bool (*RRGetPanningProcPtr) (ScreenPtr pScrn,
- RRCrtcPtr crtc,
- BoxPtr totalArea,
- BoxPtr trackingArea,
- INT16 *border);
-typedef Bool (*RRSetPanningProcPtr) (ScreenPtr pScrn,
- RRCrtcPtr crtc,
- BoxPtr totalArea,
- BoxPtr trackingArea,
- INT16 *border);
-
-#endif /* RANDR_13_INTERFACE */
-
-typedef Bool (*RRGetInfoProcPtr) (ScreenPtr pScreen, Rotation *rotations);
-typedef Bool (*RRCloseScreenProcPtr) ( int i, ScreenPtr pscreen);
-
-/* These are for 1.0 compatibility */
-
-typedef struct _rrRefresh {
- CARD16 rate;
- RRModePtr mode;
-} RRScreenRate, *RRScreenRatePtr;
-
-typedef struct _rrScreenSize {
- int id;
- short width, height;
- short mmWidth, mmHeight;
- int nRates;
- RRScreenRatePtr pRates;
-} RRScreenSize, *RRScreenSizePtr;
-
-#ifdef RANDR_10_INTERFACE
-
-typedef Bool (*RRSetConfigProcPtr) (ScreenPtr pScreen,
- Rotation rotation,
- int rate,
- RRScreenSizePtr pSize);
-
-#endif
-
-
-typedef struct _rrScrPriv {
- /*
- * 'public' part of the structure; DDXen fill this in
- * as they initialize
- */
-#if RANDR_10_INTERFACE
- RRSetConfigProcPtr rrSetConfig;
-#endif
- RRGetInfoProcPtr rrGetInfo;
-#if RANDR_12_INTERFACE
- RRScreenSetSizeProcPtr rrScreenSetSize;
- RRCrtcSetProcPtr rrCrtcSet;
- RRCrtcSetGammaProcPtr rrCrtcSetGamma;
- RRCrtcGetGammaProcPtr rrCrtcGetGamma;
- RROutputSetPropertyProcPtr rrOutputSetProperty;
- RROutputValidateModeProcPtr rrOutputValidateMode;
- RRModeDestroyProcPtr rrModeDestroy;
-#endif
-#if RANDR_13_INTERFACE
- RROutputGetPropertyProcPtr rrOutputGetProperty;
- RRGetPanningProcPtr rrGetPanning;
- RRSetPanningProcPtr rrSetPanning;
-#endif
-
- /*
- * Private part of the structure; not considered part of the ABI
- */
- TimeStamp lastSetTime; /* last changed by client */
- TimeStamp lastConfigTime; /* possible configs changed */
- RRCloseScreenProcPtr CloseScreen;
-
- Bool changed; /* some config changed */
- Bool configChanged; /* configuration changed */
- Bool layoutChanged; /* screen layout changed */
-
- CARD16 minWidth, minHeight;
- CARD16 maxWidth, maxHeight;
- CARD16 width, height; /* last known screen size */
- CARD16 mmWidth, mmHeight; /* last known screen size */
-
- int numOutputs;
- RROutputPtr *outputs;
- RROutputPtr primaryOutput;
-
- int numCrtcs;
- RRCrtcPtr *crtcs;
-
- /* Last known pointer position */
- RRCrtcPtr pointerCrtc;
-
-#ifdef RANDR_10_INTERFACE
- /*
- * Configuration information
- */
- Rotation rotations;
- CARD16 reqWidth, reqHeight;
-
- int nSizes;
- RRScreenSizePtr pSizes;
-
- Rotation rotation;
- int rate;
- int size;
-#endif
- Bool discontiguous;
-} rrScrPrivRec, *rrScrPrivPtr;
-
-extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec;
-#define rrPrivKey (&rrPrivKeyRec)
-
-#define rrGetScrPriv(pScr) ((rrScrPrivPtr)dixLookupPrivate(&(pScr)->devPrivates, rrPrivKey))
-#define rrScrPriv(pScr) rrScrPrivPtr pScrPriv = rrGetScrPriv(pScr)
-#define SetRRScreen(s,p) dixSetPrivate(&(s)->devPrivates, rrPrivKey, p)
-
-/*
- * each window has a list of clients requesting
- * RRNotify events. Each client has a resource
- * for each window it selects RRNotify input for,
- * this resource is used to delete the RRNotifyRec
- * entry from the per-window queue.
- */
-
-typedef struct _RREvent *RREventPtr;
-
-typedef struct _RREvent {
- RREventPtr next;
- ClientPtr client;
- WindowPtr window;
- XID clientResource;
- int mask;
-} RREventRec;
-
-typedef struct _RRTimes {
- TimeStamp setTime;
- TimeStamp configTime;
-} RRTimesRec, *RRTimesPtr;
-
-typedef struct _RRClient {
- int major_version;
- int minor_version;
-/* RRTimesRec times[0]; */
-} RRClientRec, *RRClientPtr;
-
-extern _X_EXPORT RESTYPE RRClientType, RREventType; /* resource types for event masks */
-extern _X_EXPORT DevPrivateKeyRec RRClientPrivateKeyRec;
-#define RRClientPrivateKey (&RRClientPrivateKeyRec)
-extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType;
-
-#define VERIFY_RR_OUTPUT(id, ptr, a)\
- {\
- int rc = dixLookupResourceByType((pointer *)&(ptr), id,\
- RROutputType, client, a);\
- if (rc != Success) {\
- client->errorValue = id;\
- return rc;\
- }\
- }
-
-#define VERIFY_RR_CRTC(id, ptr, a)\
- {\
- int rc = dixLookupResourceByType((pointer *)&(ptr), id,\
- RRCrtcType, client, a);\
- if (rc != Success) {\
- client->errorValue = id;\
- return rc;\
- }\
- }
-
-#define VERIFY_RR_MODE(id, ptr, a)\
- {\
- int rc = dixLookupResourceByType((pointer *)&(ptr), id,\
- RRModeType, client, a);\
- if (rc != Success) {\
- client->errorValue = id;\
- return rc;\
- }\
- }
-
-#define GetRRClient(pClient) ((RRClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RRClientPrivateKey))
-#define rrClientPriv(pClient) RRClientPtr pRRClient = GetRRClient(pClient)
-
-/* Initialize the extension */
-extern _X_EXPORT void
-RRExtensionInit (void);
-
-#ifdef RANDR_12_INTERFACE
-/*
- * Set the range of sizes for the screen
- */
-extern _X_EXPORT void
-RRScreenSetSizeRange (ScreenPtr pScreen,
- CARD16 minWidth,
- CARD16 minHeight,
- CARD16 maxWidth,
- CARD16 maxHeight);
-#endif
-
-/* rrscreen.c */
-/*
- * Notify the extension that the screen size has been changed.
- * The driver is responsible for calling this whenever it has changed
- * the size of the screen
- */
-extern _X_EXPORT void
-RRScreenSizeNotify (ScreenPtr pScreen);
-
-/*
- * Request that the screen be resized
- */
-extern _X_EXPORT Bool
-RRScreenSizeSet (ScreenPtr pScreen,
- CARD16 width,
- CARD16 height,
- CARD32 mmWidth,
- CARD32 mmHeight);
-
-/*
- * Send ConfigureNotify event to root window when 'something' happens
- */
-extern _X_EXPORT void
-RRSendConfigNotify (ScreenPtr pScreen);
-
-/*
- * screen dispatch
- */
-extern _X_EXPORT int
-ProcRRGetScreenSizeRange (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRSetScreenSize (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRGetScreenResources (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRGetScreenResourcesCurrent (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRSetScreenConfig (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRGetScreenInfo (ClientPtr client);
-
-/*
- * Deliver a ScreenNotify event
- */
-extern _X_EXPORT void
-RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen);
-
-/* randr.c */
-/*
- * Send all pending events
- */
-extern _X_EXPORT void
-RRTellChanged (ScreenPtr pScreen);
-
-/*
- * Poll the driver for changed information
- */
-extern _X_EXPORT Bool
-RRGetInfo (ScreenPtr pScreen, Bool force_query);
-
-extern _X_EXPORT Bool RRInit (void);
-
-extern _X_EXPORT Bool RRScreenInit(ScreenPtr pScreen);
-
-extern _X_EXPORT RROutputPtr
-RRFirstOutput (ScreenPtr pScreen);
-
-extern _X_EXPORT Rotation
-RRGetRotation (ScreenPtr pScreen);
-
-extern _X_EXPORT CARD16
-RRVerticalRefresh (xRRModeInfo *mode);
-
-#ifdef RANDR_10_INTERFACE
-/*
- * This is the old interface, deprecated but left
- * around for compatibility
- */
-
-/*
- * Then, register the specific size with the screen
- */
-
-extern _X_EXPORT RRScreenSizePtr
-RRRegisterSize (ScreenPtr pScreen,
- short width,
- short height,
- short mmWidth,
- short mmHeight);
-
-extern _X_EXPORT Bool
-RRRegisterRate (ScreenPtr pScreen,
- RRScreenSizePtr pSize,
- int rate);
-
-/*
- * Finally, set the current configuration of the screen
- */
-
-extern _X_EXPORT void
-RRSetCurrentConfig (ScreenPtr pScreen,
- Rotation rotation,
- int rate,
- RRScreenSizePtr pSize);
-
-extern _X_EXPORT Bool RRScreenInit (ScreenPtr pScreen);
-
-extern _X_EXPORT Rotation
-RRGetRotation (ScreenPtr pScreen);
-
-#endif
-
-/* rrcrtc.c */
-
-/*
- * Notify the CRTC of some change; layoutChanged indicates that
- * some position or size element changed
- */
-extern _X_EXPORT void
-RRCrtcChanged (RRCrtcPtr crtc, Bool layoutChanged);
-
-/*
- * Create a CRTC
- */
-extern _X_EXPORT RRCrtcPtr
-RRCrtcCreate (ScreenPtr pScreen, void *devPrivate);
-
-/*
- * Set the allowed rotations on a CRTC
- */
-extern _X_EXPORT void
-RRCrtcSetRotations (RRCrtcPtr crtc, Rotation rotations);
-
-/*
- * Set whether transforms are allowed on a CRTC
- */
-extern _X_EXPORT void
-RRCrtcSetTransformSupport (RRCrtcPtr crtc, Bool transforms);
-
-/*
- * Notify the extension that the Crtc has been reconfigured,
- * the driver calls this whenever it has updated the mode
- */
-extern _X_EXPORT Bool
-RRCrtcNotify (RRCrtcPtr crtc,
- RRModePtr mode,
- int x,
- int y,
- Rotation rotation,
- RRTransformPtr transform,
- int numOutputs,
- RROutputPtr *outputs);
-
-extern _X_EXPORT void
-RRDeliverCrtcEvent (ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc);
-
-/*
- * Request that the Crtc be reconfigured
- */
-extern _X_EXPORT Bool
-RRCrtcSet (RRCrtcPtr crtc,
- RRModePtr mode,
- int x,
- int y,
- Rotation rotation,
- int numOutput,
- RROutputPtr *outputs);
-
-/*
- * Request that the Crtc gamma be changed
- */
-
-extern _X_EXPORT Bool
-RRCrtcGammaSet (RRCrtcPtr crtc,
- CARD16 *red,
- CARD16 *green,
- CARD16 *blue);
-
-/*
- * Request current gamma back from the DDX (if possible).
- * This includes gamma size.
- */
-
-extern _X_EXPORT Bool
-RRCrtcGammaGet(RRCrtcPtr crtc);
-
-/*
- * Notify the extension that the Crtc gamma has been changed
- * The driver calls this whenever it has changed the gamma values
- * in the RRCrtcRec
- */
-
-extern _X_EXPORT Bool
-RRCrtcGammaNotify (RRCrtcPtr crtc);
-
-/*
- * Set the size of the gamma table at server startup time
- */
-
-extern _X_EXPORT Bool
-RRCrtcGammaSetSize (RRCrtcPtr crtc,
- int size);
-
-/*
- * Return the area of the frame buffer scanned out by the crtc,
- * taking into account the current mode and rotation
- */
-
-extern _X_EXPORT void
-RRCrtcGetScanoutSize(RRCrtcPtr crtc, int *width, int *height);
-
-/*
- * Compute the complete transformation matrix including
- * client-specified transform, rotation/reflection values and the crtc
- * offset.
- *
- * Return TRUE if the resulting transform is not a simple translation.
- */
-extern _X_EXPORT Bool
-RRTransformCompute (int x,
- int y,
- int width,
- int height,
- Rotation rotation,
- RRTransformPtr rr_transform,
-
- PictTransformPtr transform,
- struct pict_f_transform *f_transform,
- struct pict_f_transform *f_inverse);
-
-/*
- * Return crtc transform
- */
-extern _X_EXPORT RRTransformPtr
-RRCrtcGetTransform (RRCrtcPtr crtc);
-
-/*
- * Check whether the pending and current transforms are the same
- */
-extern _X_EXPORT Bool
-RRCrtcPendingTransform (RRCrtcPtr crtc);
-
-/*
- * Destroy a Crtc at shutdown
- */
-extern _X_EXPORT void
-RRCrtcDestroy (RRCrtcPtr crtc);
-
-
-/*
- * Set the pending CRTC transformation
- */
-
-extern _X_EXPORT int
-RRCrtcTransformSet (RRCrtcPtr crtc,
- PictTransformPtr transform,
- struct pict_f_transform *f_transform,
- struct pict_f_transform *f_inverse,
- char *filter,
- int filter_len,
- xFixed *params,
- int nparams);
-
-/*
- * Initialize crtc type
- */
-extern _X_EXPORT Bool
-RRCrtcInit (void);
-
-/*
- * Initialize crtc type error value
- */
-extern _X_EXPORT void
-RRCrtcInitErrorValue (void);
-
-/*
- * Crtc dispatch
- */
-
-extern _X_EXPORT int
-ProcRRGetCrtcInfo (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRSetCrtcConfig (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRGetCrtcGammaSize (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRGetCrtcGamma (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRSetCrtcGamma (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRSetCrtcTransform (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRGetCrtcTransform (ClientPtr client);
-
-int
-ProcRRGetPanning (ClientPtr client);
-
-int
-ProcRRSetPanning (ClientPtr client);
-
-void
-RRConstrainCursorHarder (DeviceIntPtr, ScreenPtr, int, int *, int *);
-
-/* rrdispatch.c */
-extern _X_EXPORT Bool
-RRClientKnowsRates (ClientPtr pClient);
-
-/* rrmode.c */
-/*
- * Find, and if necessary, create a mode
- */
-
-extern _X_EXPORT RRModePtr
-RRModeGet (xRRModeInfo *modeInfo,
- const char *name);
-
-/*
- * Destroy a mode.
- */
-
-extern _X_EXPORT void
-RRModeDestroy (RRModePtr mode);
-
-/*
- * Return a list of modes that are valid for some output in pScreen
- */
-extern _X_EXPORT RRModePtr *
-RRModesForScreen (ScreenPtr pScreen, int *num_ret);
-
-/*
- * Initialize mode type
- */
-extern _X_EXPORT Bool
-RRModeInit (void);
-
-/*
- * Initialize mode type error value
- */
-extern _X_EXPORT void
-RRModeInitErrorValue (void);
-
-extern _X_EXPORT int
-ProcRRCreateMode (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRDestroyMode (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRAddOutputMode (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRDeleteOutputMode (ClientPtr client);
-
-/* rroutput.c */
-
-/*
- * Notify the output of some change. configChanged indicates whether
- * any external configuration (mode list, clones, connected status)
- * has changed, or whether the change was strictly internal
- * (which crtc is in use)
- */
-extern _X_EXPORT void
-RROutputChanged (RROutputPtr output, Bool configChanged);
-
-/*
- * Create an output
- */
-
-extern _X_EXPORT RROutputPtr
-RROutputCreate (ScreenPtr pScreen,
- const char *name,
- int nameLength,
- void *devPrivate);
-
-/*
- * Notify extension that output parameters have been changed
- */
-extern _X_EXPORT Bool
-RROutputSetClones (RROutputPtr output,
- RROutputPtr *clones,
- int numClones);
-
-extern _X_EXPORT Bool
-RROutputSetModes (RROutputPtr output,
- RRModePtr *modes,
- int numModes,
- int numPreferred);
-
-extern _X_EXPORT int
-RROutputAddUserMode (RROutputPtr output,
- RRModePtr mode);
-
-extern _X_EXPORT int
-RROutputDeleteUserMode (RROutputPtr output,
- RRModePtr mode);
-
-extern _X_EXPORT Bool
-RROutputSetCrtcs (RROutputPtr output,
- RRCrtcPtr *crtcs,
- int numCrtcs);
-
-extern _X_EXPORT Bool
-RROutputSetConnection (RROutputPtr output,
- CARD8 connection);
-
-extern _X_EXPORT Bool
-RROutputSetSubpixelOrder (RROutputPtr output,
- int subpixelOrder);
-
-extern _X_EXPORT Bool
-RROutputSetPhysicalSize (RROutputPtr output,
- int mmWidth,
- int mmHeight);
-
-extern _X_EXPORT void
-RRDeliverOutputEvent(ClientPtr client, WindowPtr pWin, RROutputPtr output);
-
-extern _X_EXPORT void
-RROutputDestroy (RROutputPtr output);
-
-extern _X_EXPORT int
-ProcRRGetOutputInfo (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRSetOutputPrimary (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRGetOutputPrimary (ClientPtr client);
-
-/*
- * Initialize output type
- */
-extern _X_EXPORT Bool
-RROutputInit (void);
-
-/*
- * Initialize output type error value
- */
-extern _X_EXPORT void
-RROutputInitErrorValue (void);
-
-/* rrpointer.c */
-extern _X_EXPORT void
-RRPointerMoved (ScreenPtr pScreen, int x, int y);
-
-extern _X_EXPORT void
-RRPointerScreenConfigured (ScreenPtr pScreen);
-
-/* rrproperty.c */
-
-extern _X_EXPORT void
-RRDeleteAllOutputProperties (RROutputPtr output);
-
-extern _X_EXPORT RRPropertyValuePtr
-RRGetOutputProperty (RROutputPtr output, Atom property, Bool pending);
-
-extern _X_EXPORT RRPropertyPtr
-RRQueryOutputProperty (RROutputPtr output, Atom property);
-
-extern _X_EXPORT void
-RRDeleteOutputProperty (RROutputPtr output, Atom property);
-
-extern _X_EXPORT Bool
-RRPostPendingProperties (RROutputPtr output);
-
-extern _X_EXPORT int
-RRChangeOutputProperty (RROutputPtr output, Atom property, Atom type,
- int format, int mode, unsigned long len,
- pointer value, Bool sendevent, Bool pending);
-
-extern _X_EXPORT int
-RRConfigureOutputProperty (RROutputPtr output, Atom property,
- Bool pending, Bool range, Bool immutable,
- int num_values, INT32 *values);
-extern _X_EXPORT int
-ProcRRChangeOutputProperty (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRGetOutputProperty (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRListOutputProperties (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRQueryOutputProperty (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRConfigureOutputProperty (ClientPtr client);
-
-extern _X_EXPORT int
-ProcRRDeleteOutputProperty (ClientPtr client);
-
-/* rrxinerama.c */
-#ifdef XINERAMA
-extern _X_EXPORT void
-RRXineramaExtensionInit(void);
-#endif
-
-#endif /* _RANDRSTR_H_ */
-
-/*
-
-randr extension implementation structure
-
-Query state:
- ProcRRGetScreenInfo/ProcRRGetScreenResources
- RRGetInfo
-
- • Request configuration from driver, either 1.0 or 1.2 style
- • These functions only record state changes, all
- other actions are pended until RRTellChanged is called
-
- ->rrGetInfo
- 1.0:
- RRRegisterSize
- RRRegisterRate
- RRSetCurrentConfig
- 1.2:
- RRScreenSetSizeRange
- RROutputSetCrtcs
- RRModeGet
- RROutputSetModes
- RROutputSetConnection
- RROutputSetSubpixelOrder
- RROutputSetClones
- RRCrtcNotify
-
- • Must delay scanning configuration until after ->rrGetInfo returns
- because some drivers will call SetCurrentConfig in the middle
- of the ->rrGetInfo operation.
-
- 1.0:
-
- • Scan old configuration, mirror to new structures
-
- RRScanOldConfig
- RRCrtcCreate
- RROutputCreate
- RROutputSetCrtcs
- RROutputSetConnection
- RROutputSetSubpixelOrder
- RROldModeAdd • This adds modes one-at-a-time
- RRModeGet
- RRCrtcNotify
-
- • send events, reset pointer if necessary
-
- RRTellChanged
- WalkTree (sending events)
-
- • when layout has changed:
- RRPointerScreenConfigured
- RRSendConfigNotify
-
-Asynchronous state setting (1.2 only)
- When setting state asynchronously, the driver invokes the
- ->rrGetInfo function and then calls RRTellChanged to flush
- the changes to the clients and reset pointer if necessary
-
-Set state
-
- ProcRRSetScreenConfig
- RRCrtcSet
- 1.2:
- ->rrCrtcSet
- RRCrtcNotify
- 1.0:
- ->rrSetConfig
- RRCrtcNotify
- RRTellChanged
- */
+/* + * Copyright © 2000 Compaq Computer Corporation + * Copyright © 2002 Hewlett-Packard Company + * Copyright © 2006 Intel Corporation + * Copyright © 2008 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + * + * Author: Jim Gettys, Hewlett-Packard Company, Inc. + * Keith Packard, Intel Corporation + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#ifndef _RANDRSTR_H_ +#define _RANDRSTR_H_ + +#include <X11/X.h> +#include <X11/Xproto.h> +#include "misc.h" +#include "os.h" +#include "dixstruct.h" +#include "resource.h" +#include "scrnintstr.h" +#include "windowstr.h" +#include "pixmapstr.h" +#include "extnsionst.h" +#include "servermd.h" +#include "rrtransform.h" +#include <X11/extensions/randr.h> +#include <X11/extensions/randrproto.h> +#include <X11/extensions/render.h> /* we share subpixel order information */ +#include "picturestr.h" +#include <X11/Xfuncproto.h> + +/* required for ABI compatibility for now */ +#define RANDR_10_INTERFACE 1 +#define RANDR_12_INTERFACE 1 +#define RANDR_13_INTERFACE 1 /* requires RANDR_12_INTERFACE */ +#define RANDR_GET_CRTC_INTERFACE 1 + +#define RANDR_INTERFACE_VERSION 0x0103 + +typedef XID RRMode; +typedef XID RROutput; +typedef XID RRCrtc; + +extern _X_EXPORT int RREventBase, RRErrorBase; + +extern _X_EXPORT int (*ProcRandrVector[RRNumberRequests])(ClientPtr); +extern _X_EXPORT int (*SProcRandrVector[RRNumberRequests])(ClientPtr); + +/* + * Modeline for a monitor. Name follows directly after this struct + */ + +#define RRModeName(pMode) ((char *) (pMode + 1)) +typedef struct _rrMode RRModeRec, *RRModePtr; +typedef struct _rrPropertyValue RRPropertyValueRec, *RRPropertyValuePtr; +typedef struct _rrProperty RRPropertyRec, *RRPropertyPtr; +typedef struct _rrCrtc RRCrtcRec, *RRCrtcPtr; +typedef struct _rrOutput RROutputRec, *RROutputPtr; + +struct _rrMode { + int refcnt; + xRRModeInfo mode; + char *name; + ScreenPtr userScreen; +}; + +struct _rrPropertyValue { + Atom type; /* ignored by server */ + short format; /* format of data for swapping - 8,16,32 */ + long size; /* size of data in (format/8) bytes */ + pointer data; /* private to client */ +}; + +struct _rrProperty { + RRPropertyPtr next; + ATOM propertyName; + Bool is_pending; + Bool range; + Bool immutable; + int num_valid; + INT32 *valid_values; + RRPropertyValueRec current, pending; +}; + +struct _rrCrtc { + RRCrtc id; + ScreenPtr pScreen; + RRModePtr mode; + int x, y; + Rotation rotation; + Rotation rotations; + Bool changed; + int numOutputs; + RROutputPtr *outputs; + int gammaSize; + CARD16 *gammaRed; + CARD16 *gammaBlue; + CARD16 *gammaGreen; + void *devPrivate; + Bool transforms; + RRTransformRec client_pending_transform; + RRTransformRec client_current_transform; + PictTransform transform; + struct pict_f_transform f_transform; + struct pict_f_transform f_inverse; +}; + +struct _rrOutput { + RROutput id; + ScreenPtr pScreen; + char *name; + int nameLength; + CARD8 connection; + CARD8 subpixelOrder; + int mmWidth; + int mmHeight; + RRCrtcPtr crtc; + int numCrtcs; + RRCrtcPtr *crtcs; + int numClones; + RROutputPtr *clones; + int numModes; + int numPreferred; + RRModePtr *modes; + int numUserModes; + RRModePtr *userModes; + Bool changed; + RRPropertyPtr properties; + Bool pendingProperties; + void *devPrivate; +}; + +#if RANDR_12_INTERFACE +typedef Bool (*RRScreenSetSizeProcPtr) (ScreenPtr pScreen, + CARD16 width, + CARD16 height, + CARD32 mmWidth, + CARD32 mmHeight); + +typedef Bool (*RRCrtcSetProcPtr) (ScreenPtr pScreen, + RRCrtcPtr crtc, + RRModePtr mode, + int x, + int y, + Rotation rotation, + int numOutputs, + RROutputPtr *outputs); + +typedef Bool (*RRCrtcSetGammaProcPtr) (ScreenPtr pScreen, + RRCrtcPtr crtc); + +typedef Bool (*RRCrtcGetGammaProcPtr) (ScreenPtr pScreen, + RRCrtcPtr crtc); + +typedef Bool (*RROutputSetPropertyProcPtr) (ScreenPtr pScreen, + RROutputPtr output, + Atom property, + RRPropertyValuePtr value); + +typedef Bool (*RROutputValidateModeProcPtr) (ScreenPtr pScreen, + RROutputPtr output, + RRModePtr mode); + +typedef void (*RRModeDestroyProcPtr) (ScreenPtr pScreen, + RRModePtr mode); + +#endif + +#if RANDR_13_INTERFACE +typedef Bool (*RROutputGetPropertyProcPtr) (ScreenPtr pScreen, + RROutputPtr output, + Atom property); +typedef Bool (*RRGetPanningProcPtr) (ScreenPtr pScrn, + RRCrtcPtr crtc, + BoxPtr totalArea, + BoxPtr trackingArea, + INT16 *border); +typedef Bool (*RRSetPanningProcPtr) (ScreenPtr pScrn, + RRCrtcPtr crtc, + BoxPtr totalArea, + BoxPtr trackingArea, + INT16 *border); + +#endif /* RANDR_13_INTERFACE */ + +typedef Bool (*RRGetInfoProcPtr) (ScreenPtr pScreen, Rotation *rotations); +typedef Bool (*RRCloseScreenProcPtr) ( int i, ScreenPtr pscreen); + +/* These are for 1.0 compatibility */ + +typedef struct _rrRefresh { + CARD16 rate; + RRModePtr mode; +} RRScreenRate, *RRScreenRatePtr; + +typedef struct _rrScreenSize { + int id; + short width, height; + short mmWidth, mmHeight; + int nRates; + RRScreenRatePtr pRates; +} RRScreenSize, *RRScreenSizePtr; + +#ifdef RANDR_10_INTERFACE + +typedef Bool (*RRSetConfigProcPtr) (ScreenPtr pScreen, + Rotation rotation, + int rate, + RRScreenSizePtr pSize); + +#endif + + +typedef struct _rrScrPriv { + /* + * 'public' part of the structure; DDXen fill this in + * as they initialize + */ +#if RANDR_10_INTERFACE + RRSetConfigProcPtr rrSetConfig; +#endif + RRGetInfoProcPtr rrGetInfo; +#if RANDR_12_INTERFACE + RRScreenSetSizeProcPtr rrScreenSetSize; + RRCrtcSetProcPtr rrCrtcSet; + RRCrtcSetGammaProcPtr rrCrtcSetGamma; + RRCrtcGetGammaProcPtr rrCrtcGetGamma; + RROutputSetPropertyProcPtr rrOutputSetProperty; + RROutputValidateModeProcPtr rrOutputValidateMode; + RRModeDestroyProcPtr rrModeDestroy; +#endif +#if RANDR_13_INTERFACE + RROutputGetPropertyProcPtr rrOutputGetProperty; + RRGetPanningProcPtr rrGetPanning; + RRSetPanningProcPtr rrSetPanning; +#endif + + /* + * Private part of the structure; not considered part of the ABI + */ + TimeStamp lastSetTime; /* last changed by client */ + TimeStamp lastConfigTime; /* possible configs changed */ + RRCloseScreenProcPtr CloseScreen; + + Bool changed; /* some config changed */ + Bool configChanged; /* configuration changed */ + Bool layoutChanged; /* screen layout changed */ + + CARD16 minWidth, minHeight; + CARD16 maxWidth, maxHeight; + CARD16 width, height; /* last known screen size */ + CARD16 mmWidth, mmHeight; /* last known screen size */ + + int numOutputs; + RROutputPtr *outputs; + RROutputPtr primaryOutput; + + int numCrtcs; + RRCrtcPtr *crtcs; + + /* Last known pointer position */ + RRCrtcPtr pointerCrtc; + +#ifdef RANDR_10_INTERFACE + /* + * Configuration information + */ + Rotation rotations; + CARD16 reqWidth, reqHeight; + + int nSizes; + RRScreenSizePtr pSizes; + + Rotation rotation; + int rate; + int size; +#endif + Bool discontiguous; +} rrScrPrivRec, *rrScrPrivPtr; + +extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec; +#define rrPrivKey (&rrPrivKeyRec) + +#define rrGetScrPriv(pScr) ((rrScrPrivPtr)dixLookupPrivate(&(pScr)->devPrivates, rrPrivKey)) +#define rrScrPriv(pScr) rrScrPrivPtr pScrPriv = rrGetScrPriv(pScr) +#define SetRRScreen(s,p) dixSetPrivate(&(s)->devPrivates, rrPrivKey, p) + +/* + * each window has a list of clients requesting + * RRNotify events. Each client has a resource + * for each window it selects RRNotify input for, + * this resource is used to delete the RRNotifyRec + * entry from the per-window queue. + */ + +typedef struct _RREvent *RREventPtr; + +typedef struct _RREvent { + RREventPtr next; + ClientPtr client; + WindowPtr window; + XID clientResource; + int mask; +} RREventRec; + +typedef struct _RRTimes { + TimeStamp setTime; + TimeStamp configTime; +} RRTimesRec, *RRTimesPtr; + +typedef struct _RRClient { + int major_version; + int minor_version; +/* RRTimesRec times[0]; */ +} RRClientRec, *RRClientPtr; + +extern _X_EXPORT RESTYPE RRClientType, RREventType; /* resource types for event masks */ +extern _X_EXPORT DevPrivateKeyRec RRClientPrivateKeyRec; +#define RRClientPrivateKey (&RRClientPrivateKeyRec) +extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType; + +#define VERIFY_RR_OUTPUT(id, ptr, a)\ + {\ + int rc = dixLookupResourceByType((pointer *)&(ptr), id,\ + RROutputType, client, a);\ + if (rc != Success) {\ + client->errorValue = id;\ + return rc;\ + }\ + } + +#define VERIFY_RR_CRTC(id, ptr, a)\ + {\ + int rc = dixLookupResourceByType((pointer *)&(ptr), id,\ + RRCrtcType, client, a);\ + if (rc != Success) {\ + client->errorValue = id;\ + return rc;\ + }\ + } + +#define VERIFY_RR_MODE(id, ptr, a)\ + {\ + int rc = dixLookupResourceByType((pointer *)&(ptr), id,\ + RRModeType, client, a);\ + if (rc != Success) {\ + client->errorValue = id;\ + return rc;\ + }\ + } + +#define GetRRClient(pClient) ((RRClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RRClientPrivateKey)) +#define rrClientPriv(pClient) RRClientPtr pRRClient = GetRRClient(pClient) + +/* Initialize the extension */ +extern _X_EXPORT void +RRExtensionInit (void); + +#ifdef RANDR_12_INTERFACE +/* + * Set the range of sizes for the screen + */ +extern _X_EXPORT void +RRScreenSetSizeRange (ScreenPtr pScreen, + CARD16 minWidth, + CARD16 minHeight, + CARD16 maxWidth, + CARD16 maxHeight); +#endif + +/* rrscreen.c */ +/* + * Notify the extension that the screen size has been changed. + * The driver is responsible for calling this whenever it has changed + * the size of the screen + */ +extern _X_EXPORT void +RRScreenSizeNotify (ScreenPtr pScreen); + +/* + * Request that the screen be resized + */ +extern _X_EXPORT Bool +RRScreenSizeSet (ScreenPtr pScreen, + CARD16 width, + CARD16 height, + CARD32 mmWidth, + CARD32 mmHeight); + +/* + * Send ConfigureNotify event to root window when 'something' happens + */ +extern _X_EXPORT void +RRSendConfigNotify (ScreenPtr pScreen); + +/* + * screen dispatch + */ +extern _X_EXPORT int +ProcRRGetScreenSizeRange (ClientPtr client); + +extern _X_EXPORT int +ProcRRSetScreenSize (ClientPtr client); + +extern _X_EXPORT int +ProcRRGetScreenResources (ClientPtr client); + +extern _X_EXPORT int +ProcRRGetScreenResourcesCurrent (ClientPtr client); + +extern _X_EXPORT int +ProcRRSetScreenConfig (ClientPtr client); + +extern _X_EXPORT int +ProcRRGetScreenInfo (ClientPtr client); + +/* + * Deliver a ScreenNotify event + */ +extern _X_EXPORT void +RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen); + +/* randr.c */ +/* + * Send all pending events + */ +extern _X_EXPORT void +RRTellChanged (ScreenPtr pScreen); + +/* + * Poll the driver for changed information + */ +extern _X_EXPORT Bool +RRGetInfo (ScreenPtr pScreen, Bool force_query); + +extern _X_EXPORT Bool RRInit (void); + +extern _X_EXPORT Bool RRScreenInit(ScreenPtr pScreen); + +extern _X_EXPORT RROutputPtr +RRFirstOutput (ScreenPtr pScreen); + +extern _X_EXPORT CARD16 +RRVerticalRefresh (xRRModeInfo *mode); + +#ifdef RANDR_10_INTERFACE +/* + * This is the old interface, deprecated but left + * around for compatibility + */ + +/* + * Then, register the specific size with the screen + */ + +extern _X_EXPORT RRScreenSizePtr +RRRegisterSize (ScreenPtr pScreen, + short width, + short height, + short mmWidth, + short mmHeight); + +extern _X_EXPORT Bool +RRRegisterRate (ScreenPtr pScreen, + RRScreenSizePtr pSize, + int rate); + +/* + * Finally, set the current configuration of the screen + */ + +extern _X_EXPORT void +RRSetCurrentConfig (ScreenPtr pScreen, + Rotation rotation, + int rate, + RRScreenSizePtr pSize); + +extern _X_EXPORT Rotation +RRGetRotation (ScreenPtr pScreen); + +#endif + +/* rrcrtc.c */ + +/* + * Notify the CRTC of some change; layoutChanged indicates that + * some position or size element changed + */ +extern _X_EXPORT void +RRCrtcChanged (RRCrtcPtr crtc, Bool layoutChanged); + +/* + * Create a CRTC + */ +extern _X_EXPORT RRCrtcPtr +RRCrtcCreate (ScreenPtr pScreen, void *devPrivate); + +/* + * Set the allowed rotations on a CRTC + */ +extern _X_EXPORT void +RRCrtcSetRotations (RRCrtcPtr crtc, Rotation rotations); + +/* + * Set whether transforms are allowed on a CRTC + */ +extern _X_EXPORT void +RRCrtcSetTransformSupport (RRCrtcPtr crtc, Bool transforms); + +/* + * Notify the extension that the Crtc has been reconfigured, + * the driver calls this whenever it has updated the mode + */ +extern _X_EXPORT Bool +RRCrtcNotify (RRCrtcPtr crtc, + RRModePtr mode, + int x, + int y, + Rotation rotation, + RRTransformPtr transform, + int numOutputs, + RROutputPtr *outputs); + +extern _X_EXPORT void +RRDeliverCrtcEvent (ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc); + +/* + * Request that the Crtc be reconfigured + */ +extern _X_EXPORT Bool +RRCrtcSet (RRCrtcPtr crtc, + RRModePtr mode, + int x, + int y, + Rotation rotation, + int numOutput, + RROutputPtr *outputs); + +/* + * Request that the Crtc gamma be changed + */ + +extern _X_EXPORT Bool +RRCrtcGammaSet (RRCrtcPtr crtc, + CARD16 *red, + CARD16 *green, + CARD16 *blue); + +/* + * Request current gamma back from the DDX (if possible). + * This includes gamma size. + */ + +extern _X_EXPORT Bool +RRCrtcGammaGet(RRCrtcPtr crtc); + +/* + * Notify the extension that the Crtc gamma has been changed + * The driver calls this whenever it has changed the gamma values + * in the RRCrtcRec + */ + +extern _X_EXPORT Bool +RRCrtcGammaNotify (RRCrtcPtr crtc); + +/* + * Set the size of the gamma table at server startup time + */ + +extern _X_EXPORT Bool +RRCrtcGammaSetSize (RRCrtcPtr crtc, + int size); + +/* + * Return the area of the frame buffer scanned out by the crtc, + * taking into account the current mode and rotation + */ + +extern _X_EXPORT void +RRCrtcGetScanoutSize(RRCrtcPtr crtc, int *width, int *height); + +/* + * Compute the complete transformation matrix including + * client-specified transform, rotation/reflection values and the crtc + * offset. + * + * Return TRUE if the resulting transform is not a simple translation. + */ +extern _X_EXPORT Bool +RRTransformCompute (int x, + int y, + int width, + int height, + Rotation rotation, + RRTransformPtr rr_transform, + + PictTransformPtr transform, + struct pict_f_transform *f_transform, + struct pict_f_transform *f_inverse); + +/* + * Return crtc transform + */ +extern _X_EXPORT RRTransformPtr +RRCrtcGetTransform (RRCrtcPtr crtc); + +/* + * Check whether the pending and current transforms are the same + */ +extern _X_EXPORT Bool +RRCrtcPendingTransform (RRCrtcPtr crtc); + +/* + * Destroy a Crtc at shutdown + */ +extern _X_EXPORT void +RRCrtcDestroy (RRCrtcPtr crtc); + + +/* + * Set the pending CRTC transformation + */ + +extern _X_EXPORT int +RRCrtcTransformSet (RRCrtcPtr crtc, + PictTransformPtr transform, + struct pict_f_transform *f_transform, + struct pict_f_transform *f_inverse, + char *filter, + int filter_len, + xFixed *params, + int nparams); + +/* + * Initialize crtc type + */ +extern _X_EXPORT Bool +RRCrtcInit (void); + +/* + * Initialize crtc type error value + */ +extern _X_EXPORT void +RRCrtcInitErrorValue (void); + +/* + * Crtc dispatch + */ + +extern _X_EXPORT int +ProcRRGetCrtcInfo (ClientPtr client); + +extern _X_EXPORT int +ProcRRSetCrtcConfig (ClientPtr client); + +extern _X_EXPORT int +ProcRRGetCrtcGammaSize (ClientPtr client); + +extern _X_EXPORT int +ProcRRGetCrtcGamma (ClientPtr client); + +extern _X_EXPORT int +ProcRRSetCrtcGamma (ClientPtr client); + +extern _X_EXPORT int +ProcRRSetCrtcTransform (ClientPtr client); + +extern _X_EXPORT int +ProcRRGetCrtcTransform (ClientPtr client); + +int +ProcRRGetPanning (ClientPtr client); + +int +ProcRRSetPanning (ClientPtr client); + +void +RRConstrainCursorHarder (DeviceIntPtr, ScreenPtr, int, int *, int *); + +/* rrdispatch.c */ +extern _X_EXPORT Bool +RRClientKnowsRates (ClientPtr pClient); + +/* rrmode.c */ +/* + * Find, and if necessary, create a mode + */ + +extern _X_EXPORT RRModePtr +RRModeGet (xRRModeInfo *modeInfo, + const char *name); + +/* + * Destroy a mode. + */ + +extern _X_EXPORT void +RRModeDestroy (RRModePtr mode); + +/* + * Return a list of modes that are valid for some output in pScreen + */ +extern _X_EXPORT RRModePtr * +RRModesForScreen (ScreenPtr pScreen, int *num_ret); + +/* + * Initialize mode type + */ +extern _X_EXPORT Bool +RRModeInit (void); + +/* + * Initialize mode type error value + */ +extern _X_EXPORT void +RRModeInitErrorValue (void); + +extern _X_EXPORT int +ProcRRCreateMode (ClientPtr client); + +extern _X_EXPORT int +ProcRRDestroyMode (ClientPtr client); + +extern _X_EXPORT int +ProcRRAddOutputMode (ClientPtr client); + +extern _X_EXPORT int +ProcRRDeleteOutputMode (ClientPtr client); + +/* rroutput.c */ + +/* + * Notify the output of some change. configChanged indicates whether + * any external configuration (mode list, clones, connected status) + * has changed, or whether the change was strictly internal + * (which crtc is in use) + */ +extern _X_EXPORT void +RROutputChanged (RROutputPtr output, Bool configChanged); + +/* + * Create an output + */ + +extern _X_EXPORT RROutputPtr +RROutputCreate (ScreenPtr pScreen, + const char *name, + int nameLength, + void *devPrivate); + +/* + * Notify extension that output parameters have been changed + */ +extern _X_EXPORT Bool +RROutputSetClones (RROutputPtr output, + RROutputPtr *clones, + int numClones); + +extern _X_EXPORT Bool +RROutputSetModes (RROutputPtr output, + RRModePtr *modes, + int numModes, + int numPreferred); + +extern _X_EXPORT int +RROutputAddUserMode (RROutputPtr output, + RRModePtr mode); + +extern _X_EXPORT int +RROutputDeleteUserMode (RROutputPtr output, + RRModePtr mode); + +extern _X_EXPORT Bool +RROutputSetCrtcs (RROutputPtr output, + RRCrtcPtr *crtcs, + int numCrtcs); + +extern _X_EXPORT Bool +RROutputSetConnection (RROutputPtr output, + CARD8 connection); + +extern _X_EXPORT Bool +RROutputSetSubpixelOrder (RROutputPtr output, + int subpixelOrder); + +extern _X_EXPORT Bool +RROutputSetPhysicalSize (RROutputPtr output, + int mmWidth, + int mmHeight); + +extern _X_EXPORT void +RRDeliverOutputEvent(ClientPtr client, WindowPtr pWin, RROutputPtr output); + +extern _X_EXPORT void +RROutputDestroy (RROutputPtr output); + +extern _X_EXPORT int +ProcRRGetOutputInfo (ClientPtr client); + +extern _X_EXPORT int +ProcRRSetOutputPrimary (ClientPtr client); + +extern _X_EXPORT int +ProcRRGetOutputPrimary (ClientPtr client); + +/* + * Initialize output type + */ +extern _X_EXPORT Bool +RROutputInit (void); + +/* + * Initialize output type error value + */ +extern _X_EXPORT void +RROutputInitErrorValue (void); + +/* rrpointer.c */ +extern _X_EXPORT void +RRPointerMoved (ScreenPtr pScreen, int x, int y); + +extern _X_EXPORT void +RRPointerScreenConfigured (ScreenPtr pScreen); + +/* rrproperty.c */ + +extern _X_EXPORT void +RRDeleteAllOutputProperties (RROutputPtr output); + +extern _X_EXPORT RRPropertyValuePtr +RRGetOutputProperty (RROutputPtr output, Atom property, Bool pending); + +extern _X_EXPORT RRPropertyPtr +RRQueryOutputProperty (RROutputPtr output, Atom property); + +extern _X_EXPORT void +RRDeleteOutputProperty (RROutputPtr output, Atom property); + +extern _X_EXPORT Bool +RRPostPendingProperties (RROutputPtr output); + +extern _X_EXPORT int +RRChangeOutputProperty (RROutputPtr output, Atom property, Atom type, + int format, int mode, unsigned long len, + pointer value, Bool sendevent, Bool pending); + +extern _X_EXPORT int +RRConfigureOutputProperty (RROutputPtr output, Atom property, + Bool pending, Bool range, Bool immutable, + int num_values, INT32 *values); +extern _X_EXPORT int +ProcRRChangeOutputProperty (ClientPtr client); + +extern _X_EXPORT int +ProcRRGetOutputProperty (ClientPtr client); + +extern _X_EXPORT int +ProcRRListOutputProperties (ClientPtr client); + +extern _X_EXPORT int +ProcRRQueryOutputProperty (ClientPtr client); + +extern _X_EXPORT int +ProcRRConfigureOutputProperty (ClientPtr client); + +extern _X_EXPORT int +ProcRRDeleteOutputProperty (ClientPtr client); + +/* rrxinerama.c */ +#ifdef XINERAMA +extern _X_EXPORT void +RRXineramaExtensionInit(void); +#endif + +#endif /* _RANDRSTR_H_ */ + +/* + +randr extension implementation structure + +Query state: + ProcRRGetScreenInfo/ProcRRGetScreenResources + RRGetInfo + + • Request configuration from driver, either 1.0 or 1.2 style + • These functions only record state changes, all + other actions are pended until RRTellChanged is called + + ->rrGetInfo + 1.0: + RRRegisterSize + RRRegisterRate + RRSetCurrentConfig + 1.2: + RRScreenSetSizeRange + RROutputSetCrtcs + RRModeGet + RROutputSetModes + RROutputSetConnection + RROutputSetSubpixelOrder + RROutputSetClones + RRCrtcNotify + + • Must delay scanning configuration until after ->rrGetInfo returns + because some drivers will call SetCurrentConfig in the middle + of the ->rrGetInfo operation. + + 1.0: + + • Scan old configuration, mirror to new structures + + RRScanOldConfig + RRCrtcCreate + RROutputCreate + RROutputSetCrtcs + RROutputSetConnection + RROutputSetSubpixelOrder + RROldModeAdd • This adds modes one-at-a-time + RRModeGet + RRCrtcNotify + + • send events, reset pointer if necessary + + RRTellChanged + WalkTree (sending events) + + • when layout has changed: + RRPointerScreenConfigured + RRSendConfigNotify + +Asynchronous state setting (1.2 only) + When setting state asynchronously, the driver invokes the + ->rrGetInfo function and then calls RRTellChanged to flush + the changes to the clients and reset pointer if necessary + +Set state + + ProcRRSetScreenConfig + RRCrtcSet + 1.2: + ->rrCrtcSet + RRCrtcNotify + 1.0: + ->rrSetConfig + RRCrtcNotify + RRTellChanged + */ diff --git a/xorg-server/randr/rrinfo.c b/xorg-server/randr/rrinfo.c index fdf372607..02aea5245 100644 --- a/xorg-server/randr/rrinfo.c +++ b/xorg-server/randr/rrinfo.c @@ -35,7 +35,7 @@ RROldModeAdd (RROutputPtr output, RRScreenSizePtr size, int refresh) RRModePtr *modes; memset (&modeInfo, '\0', sizeof (modeInfo)); - sprintf (name, "%dx%d", size->width, size->height); + snprintf (name, sizeof(name), "%dx%d", size->width, size->height); modeInfo.width = size->width; modeInfo.height = size->height; diff --git a/xorg-server/render/filter.c b/xorg-server/render/filter.c index 53fb86f3d..0cbd47bd2 100644 --- a/xorg-server/render/filter.c +++ b/xorg-server/render/filter.c @@ -1,359 +1,359 @@ -/*
- * Copyright © 2002 Keith Packard
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. Keith Packard makes no
- * representations about the suitability of this software for any purpose. It
- * is provided "as is" without express or implied warranty.
- *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "misc.h"
-#include "scrnintstr.h"
-#include "os.h"
-#include "regionstr.h"
-#include "validate.h"
-#include "windowstr.h"
-#include "input.h"
-#include "resource.h"
-#include "colormapst.h"
-#include "cursorstr.h"
-#include "dixstruct.h"
-#include "gcstruct.h"
-#include "servermd.h"
-#include "picturestr.h"
-
-static char **filterNames;
-static int nfilterNames;
-
-/*
- * standard but not required filters don't have constant indices
- */
-
-int
-PictureGetFilterId (char *filter, int len, Bool makeit)
-{
- int i;
- char *name;
- char **names;
-
- if (len < 0)
- len = strlen (filter);
- for (i = 0; i < nfilterNames; i++)
- if (!CompareISOLatin1Lowered ((unsigned char *) filterNames[i], -1, (unsigned char *) filter, len))
- return i;
- if (!makeit)
- return -1;
- name = malloc(len + 1);
- if (!name)
- return -1;
- memcpy (name, filter, len);
- name[len] = '\0';
- if (filterNames)
- names = realloc(filterNames, (nfilterNames + 1) * sizeof (char *));
- else
- names = malloc(sizeof (char *));
- if (!names)
- {
- free(name);
- return -1;
- }
- filterNames = names;
- i = nfilterNames++;
- filterNames[i] = name;
- return i;
-}
-
-static Bool
-PictureSetDefaultIds (void)
-{
- /* careful here -- this list must match the #define values */
-
- if (PictureGetFilterId (FilterNearest, -1, TRUE) != PictFilterNearest)
- return FALSE;
- if (PictureGetFilterId (FilterBilinear, -1, TRUE) != PictFilterBilinear)
- return FALSE;
-
- if (PictureGetFilterId (FilterFast, -1, TRUE) != PictFilterFast)
- return FALSE;
- if (PictureGetFilterId (FilterGood, -1, TRUE) != PictFilterGood)
- return FALSE;
- if (PictureGetFilterId (FilterBest, -1, TRUE) != PictFilterBest)
- return FALSE;
-
- if (PictureGetFilterId (FilterConvolution, -1, TRUE) != PictFilterConvolution)
- return FALSE;
- return TRUE;
-}
-
-char *
-PictureGetFilterName (int id)
-{
- if (0 <= id && id < nfilterNames)
- return filterNames[id];
- else
- return 0;
-}
-
-static void
-PictureFreeFilterIds (void)
-{
- int i;
-
- for (i = 0; i < nfilterNames; i++)
- free(filterNames[i]);
- free(filterNames);
- nfilterNames = 0;
- filterNames = 0;
-}
-
-int
-PictureAddFilter (ScreenPtr pScreen,
- char *filter,
- PictFilterValidateParamsProcPtr ValidateParams,
- int width,
- int height)
-{
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- int id = PictureGetFilterId (filter, -1, TRUE);
- int i;
- PictFilterPtr filters;
-
- if (id < 0)
- return -1;
- /*
- * It's an error to attempt to reregister a filter
- */
- for (i = 0; i < ps->nfilters; i++)
- if (ps->filters[i].id == id)
- return -1;
- if (ps->filters)
- filters = realloc(ps->filters, (ps->nfilters + 1) * sizeof (PictFilterRec));
- else
- filters = malloc(sizeof (PictFilterRec));
- if (!filters)
- return -1;
- ps->filters = filters;
- i = ps->nfilters++;
- ps->filters[i].name = PictureGetFilterName (id);
- ps->filters[i].id = id;
- ps->filters[i].ValidateParams = ValidateParams;
- ps->filters[i].width = width;
- ps->filters[i].height = height;
- return id;
-}
-
-Bool
-PictureSetFilterAlias (ScreenPtr pScreen, char *filter, char *alias)
-{
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- int filter_id = PictureGetFilterId (filter, -1, FALSE);
- int alias_id = PictureGetFilterId (alias, -1, TRUE);
- int i;
-
- if (filter_id < 0 || alias_id < 0)
- return FALSE;
- for (i = 0; i < ps->nfilterAliases; i++)
- if (ps->filterAliases[i].alias_id == alias_id)
- break;
- if (i == ps->nfilterAliases)
- {
- PictFilterAliasPtr aliases;
-
- if (ps->filterAliases)
- aliases = realloc(ps->filterAliases,
- (ps->nfilterAliases + 1) *
- sizeof (PictFilterAliasRec));
- else
- aliases = malloc(sizeof (PictFilterAliasRec));
- if (!aliases)
- return FALSE;
- ps->filterAliases = aliases;
- ps->filterAliases[i].alias = PictureGetFilterName (alias_id);
- ps->filterAliases[i].alias_id = alias_id;
- ps->nfilterAliases++;
- }
- ps->filterAliases[i].filter_id = filter_id;
- return TRUE;
-}
-
-PictFilterPtr
-PictureFindFilter (ScreenPtr pScreen, char *name, int len)
-{
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- int id = PictureGetFilterId (name, len, FALSE);
- int i;
-
- if (id < 0)
- return 0;
- /* Check for an alias, allow them to recurse */
- for (i = 0; i < ps->nfilterAliases; i++)
- if (ps->filterAliases[i].alias_id == id)
- {
- id = ps->filterAliases[i].filter_id;
- i = 0;
- }
- /* find the filter */
- for (i = 0; i < ps->nfilters; i++)
- if (ps->filters[i].id == id)
- return &ps->filters[i];
- return 0;
-}
-
-static Bool
-convolutionFilterValidateParams (ScreenPtr pScreen,
- int filter,
- xFixed *params,
- int nparams,
- int *width,
- int *height)
-{
- int w, h;
- if (nparams < 3)
- return FALSE;
-
- if (xFixedFrac (params[0]) || xFixedFrac (params[1]))
- return FALSE;
-
- w = xFixedToInt (params[0]);
- h = xFixedToInt (params[1]);
-
- nparams -= 2;
- if (w * h > nparams)
- return FALSE;
-
- *width = w;
- *height = h;
- return TRUE;
-}
-
-
-Bool
-PictureSetDefaultFilters (ScreenPtr pScreen)
-{
- if (!filterNames)
- if (!PictureSetDefaultIds ())
- return FALSE;
- if (PictureAddFilter (pScreen, FilterNearest, 0, 1, 1) < 0)
- return FALSE;
- if (PictureAddFilter (pScreen, FilterBilinear, 0, 2, 2) < 0)
- return FALSE;
-
- if (!PictureSetFilterAlias (pScreen, FilterNearest, FilterFast))
- return FALSE;
- if (!PictureSetFilterAlias (pScreen, FilterBilinear, FilterGood))
- return FALSE;
- if (!PictureSetFilterAlias (pScreen, FilterBilinear, FilterBest))
- return FALSE;
-
- if (PictureAddFilter (pScreen, FilterConvolution, convolutionFilterValidateParams, 0, 0) < 0)
- return FALSE;
-
- return TRUE;
-}
-
-void
-PictureResetFilters (ScreenPtr pScreen)
-{
- PictureScreenPtr ps = GetPictureScreen(pScreen);
-
- free(ps->filters);
- free(ps->filterAliases);
- PictureFreeFilterIds ();
-}
-
-int
-SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int nparams)
-{
- PictFilterPtr pFilter;
- ScreenPtr pScreen;
-
- if (pPicture->pDrawable != NULL)
- pScreen = pPicture->pDrawable->pScreen;
- else
- pScreen = screenInfo.screens[0];
-
- pFilter = PictureFindFilter (pScreen, name, len);
-
- if (!pFilter)
- return BadName;
-
- if (pPicture->pDrawable == NULL)
- {
- int s;
- /* For source pictures, the picture isn't tied to a screen. So, ensure
- * that all screens can handle a filter we set for the picture.
- */
- for (s = 1; s < screenInfo.numScreens; s++)
- {
- PictFilterPtr pScreenFilter;
- pScreenFilter = PictureFindFilter (screenInfo.screens[s],
- name, len);
- if (!pScreenFilter || pScreenFilter->id != pFilter->id)
- return BadMatch;
- }
- }
- return SetPicturePictFilter (pPicture, pFilter, params, nparams);
-}
-
-int
-SetPicturePictFilter (PicturePtr pPicture, PictFilterPtr pFilter,
- xFixed *params, int nparams)
-{
- ScreenPtr pScreen;
- int i;
-
- if (pPicture->pDrawable)
- pScreen = pPicture->pDrawable->pScreen;
- else
- pScreen = screenInfo.screens[0];
-
- if (pFilter->ValidateParams)
- {
- int width, height;
- if (!(*pFilter->ValidateParams) (pScreen, pFilter->id, params, nparams, &width, &height))
- return BadMatch;
- }
- else if (nparams)
- return BadMatch;
-
- if (nparams != pPicture->filter_nparams)
- {
- xFixed *new_params = malloc(nparams * sizeof (xFixed));
- if (!new_params && nparams)
- return BadAlloc;
- free(pPicture->filter_params);
- pPicture->filter_params = new_params;
- pPicture->filter_nparams = nparams;
- }
- for (i = 0; i < nparams; i++)
- pPicture->filter_params[i] = params[i];
- pPicture->filter = pFilter->id;
-
- if (pPicture->pDrawable)
- {
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- int result;
-
- result = (*ps->ChangePictureFilter) (pPicture, pPicture->filter,
- params, nparams);
- return result;
- }
- return Success;
-}
+/* + * Copyright © 2002 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "misc.h" +#include "scrnintstr.h" +#include "os.h" +#include "regionstr.h" +#include "validate.h" +#include "windowstr.h" +#include "input.h" +#include "resource.h" +#include "colormapst.h" +#include "cursorstr.h" +#include "dixstruct.h" +#include "gcstruct.h" +#include "servermd.h" +#include "picturestr.h" + +static char **filterNames; +static int nfilterNames; + +/* + * standard but not required filters don't have constant indices + */ + +int +PictureGetFilterId (const char *filter, int len, Bool makeit) +{ + int i; + char *name; + char **names; + + if (len < 0) + len = strlen (filter); + for (i = 0; i < nfilterNames; i++) + if (!CompareISOLatin1Lowered ((unsigned char *) filterNames[i], -1, (unsigned char *) filter, len)) + return i; + if (!makeit) + return -1; + name = malloc(len + 1); + if (!name) + return -1; + memcpy (name, filter, len); + name[len] = '\0'; + if (filterNames) + names = realloc(filterNames, (nfilterNames + 1) * sizeof (char *)); + else + names = malloc(sizeof (char *)); + if (!names) + { + free(name); + return -1; + } + filterNames = names; + i = nfilterNames++; + filterNames[i] = name; + return i; +} + +static Bool +PictureSetDefaultIds (void) +{ + /* careful here -- this list must match the #define values */ + + if (PictureGetFilterId (FilterNearest, -1, TRUE) != PictFilterNearest) + return FALSE; + if (PictureGetFilterId (FilterBilinear, -1, TRUE) != PictFilterBilinear) + return FALSE; + + if (PictureGetFilterId (FilterFast, -1, TRUE) != PictFilterFast) + return FALSE; + if (PictureGetFilterId (FilterGood, -1, TRUE) != PictFilterGood) + return FALSE; + if (PictureGetFilterId (FilterBest, -1, TRUE) != PictFilterBest) + return FALSE; + + if (PictureGetFilterId (FilterConvolution, -1, TRUE) != PictFilterConvolution) + return FALSE; + return TRUE; +} + +char * +PictureGetFilterName (int id) +{ + if (0 <= id && id < nfilterNames) + return filterNames[id]; + else + return 0; +} + +static void +PictureFreeFilterIds (void) +{ + int i; + + for (i = 0; i < nfilterNames; i++) + free(filterNames[i]); + free(filterNames); + nfilterNames = 0; + filterNames = 0; +} + +int +PictureAddFilter (ScreenPtr pScreen, + const char *filter, + PictFilterValidateParamsProcPtr ValidateParams, + int width, + int height) +{ + PictureScreenPtr ps = GetPictureScreen(pScreen); + int id = PictureGetFilterId (filter, -1, TRUE); + int i; + PictFilterPtr filters; + + if (id < 0) + return -1; + /* + * It's an error to attempt to reregister a filter + */ + for (i = 0; i < ps->nfilters; i++) + if (ps->filters[i].id == id) + return -1; + if (ps->filters) + filters = realloc(ps->filters, (ps->nfilters + 1) * sizeof (PictFilterRec)); + else + filters = malloc(sizeof (PictFilterRec)); + if (!filters) + return -1; + ps->filters = filters; + i = ps->nfilters++; + ps->filters[i].name = PictureGetFilterName (id); + ps->filters[i].id = id; + ps->filters[i].ValidateParams = ValidateParams; + ps->filters[i].width = width; + ps->filters[i].height = height; + return id; +} + +Bool +PictureSetFilterAlias (ScreenPtr pScreen, const char *filter, const char *alias) +{ + PictureScreenPtr ps = GetPictureScreen(pScreen); + int filter_id = PictureGetFilterId (filter, -1, FALSE); + int alias_id = PictureGetFilterId (alias, -1, TRUE); + int i; + + if (filter_id < 0 || alias_id < 0) + return FALSE; + for (i = 0; i < ps->nfilterAliases; i++) + if (ps->filterAliases[i].alias_id == alias_id) + break; + if (i == ps->nfilterAliases) + { + PictFilterAliasPtr aliases; + + if (ps->filterAliases) + aliases = realloc(ps->filterAliases, + (ps->nfilterAliases + 1) * + sizeof (PictFilterAliasRec)); + else + aliases = malloc(sizeof (PictFilterAliasRec)); + if (!aliases) + return FALSE; + ps->filterAliases = aliases; + ps->filterAliases[i].alias = PictureGetFilterName (alias_id); + ps->filterAliases[i].alias_id = alias_id; + ps->nfilterAliases++; + } + ps->filterAliases[i].filter_id = filter_id; + return TRUE; +} + +PictFilterPtr +PictureFindFilter (ScreenPtr pScreen, char *name, int len) +{ + PictureScreenPtr ps = GetPictureScreen(pScreen); + int id = PictureGetFilterId (name, len, FALSE); + int i; + + if (id < 0) + return 0; + /* Check for an alias, allow them to recurse */ + for (i = 0; i < ps->nfilterAliases; i++) + if (ps->filterAliases[i].alias_id == id) + { + id = ps->filterAliases[i].filter_id; + i = 0; + } + /* find the filter */ + for (i = 0; i < ps->nfilters; i++) + if (ps->filters[i].id == id) + return &ps->filters[i]; + return 0; +} + +static Bool +convolutionFilterValidateParams (ScreenPtr pScreen, + int filter, + xFixed *params, + int nparams, + int *width, + int *height) +{ + int w, h; + if (nparams < 3) + return FALSE; + + if (xFixedFrac (params[0]) || xFixedFrac (params[1])) + return FALSE; + + w = xFixedToInt (params[0]); + h = xFixedToInt (params[1]); + + nparams -= 2; + if (w * h > nparams) + return FALSE; + + *width = w; + *height = h; + return TRUE; +} + + +Bool +PictureSetDefaultFilters (ScreenPtr pScreen) +{ + if (!filterNames) + if (!PictureSetDefaultIds ()) + return FALSE; + if (PictureAddFilter (pScreen, FilterNearest, 0, 1, 1) < 0) + return FALSE; + if (PictureAddFilter (pScreen, FilterBilinear, 0, 2, 2) < 0) + return FALSE; + + if (!PictureSetFilterAlias (pScreen, FilterNearest, FilterFast)) + return FALSE; + if (!PictureSetFilterAlias (pScreen, FilterBilinear, FilterGood)) + return FALSE; + if (!PictureSetFilterAlias (pScreen, FilterBilinear, FilterBest)) + return FALSE; + + if (PictureAddFilter (pScreen, FilterConvolution, convolutionFilterValidateParams, 0, 0) < 0) + return FALSE; + + return TRUE; +} + +void +PictureResetFilters (ScreenPtr pScreen) +{ + PictureScreenPtr ps = GetPictureScreen(pScreen); + + free(ps->filters); + free(ps->filterAliases); + PictureFreeFilterIds (); +} + +int +SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int nparams) +{ + PictFilterPtr pFilter; + ScreenPtr pScreen; + + if (pPicture->pDrawable != NULL) + pScreen = pPicture->pDrawable->pScreen; + else + pScreen = screenInfo.screens[0]; + + pFilter = PictureFindFilter (pScreen, name, len); + + if (!pFilter) + return BadName; + + if (pPicture->pDrawable == NULL) + { + int s; + /* For source pictures, the picture isn't tied to a screen. So, ensure + * that all screens can handle a filter we set for the picture. + */ + for (s = 1; s < screenInfo.numScreens; s++) + { + PictFilterPtr pScreenFilter; + pScreenFilter = PictureFindFilter (screenInfo.screens[s], + name, len); + if (!pScreenFilter || pScreenFilter->id != pFilter->id) + return BadMatch; + } + } + return SetPicturePictFilter (pPicture, pFilter, params, nparams); +} + +int +SetPicturePictFilter (PicturePtr pPicture, PictFilterPtr pFilter, + xFixed *params, int nparams) +{ + ScreenPtr pScreen; + int i; + + if (pPicture->pDrawable) + pScreen = pPicture->pDrawable->pScreen; + else + pScreen = screenInfo.screens[0]; + + if (pFilter->ValidateParams) + { + int width, height; + if (!(*pFilter->ValidateParams) (pScreen, pFilter->id, params, nparams, &width, &height)) + return BadMatch; + } + else if (nparams) + return BadMatch; + + if (nparams != pPicture->filter_nparams) + { + xFixed *new_params = malloc(nparams * sizeof (xFixed)); + if (!new_params && nparams) + return BadAlloc; + free(pPicture->filter_params); + pPicture->filter_params = new_params; + pPicture->filter_nparams = nparams; + } + for (i = 0; i < nparams; i++) + pPicture->filter_params[i] = params[i]; + pPicture->filter = pFilter->id; + + if (pPicture->pDrawable) + { + PictureScreenPtr ps = GetPictureScreen(pScreen); + int result; + + result = (*ps->ChangePictureFilter) (pPicture, pPicture->filter, + params, nparams); + return result; + } + return Success; +} diff --git a/xorg-server/render/glyphstr.h b/xorg-server/render/glyphstr.h index ba9a28d16..49b4b54dd 100644 --- a/xorg-server/render/glyphstr.h +++ b/xorg-server/render/glyphstr.h @@ -1,150 +1,147 @@ -/*
- *
- * Copyright © 2000 SuSE, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of SuSE not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. SuSE makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Keith Packard, SuSE, Inc.
- */
-
-#ifndef _GLYPHSTR_H_
-#define _GLYPHSTR_H_
-
-#include <X11/extensions/renderproto.h>
-#include "picture.h"
-#include "screenint.h"
-#include "regionstr.h"
-#include "miscstruct.h"
-#include "privates.h"
-
-#define GlyphFormat1 0
-#define GlyphFormat4 1
-#define GlyphFormat8 2
-#define GlyphFormat16 3
-#define GlyphFormat32 4
-#define GlyphFormatNum 5
-
-typedef struct _Glyph {
- CARD32 refcnt;
- PrivateRec *devPrivates;
- unsigned char sha1[20];
- CARD32 size; /* info + bitmap */
- xGlyphInfo info;
- /* per-screen pixmaps follow */
-} GlyphRec, *GlyphPtr;
-
-#define GlyphPicture(glyph) ((PicturePtr *) ((glyph) + 1))
-
-typedef struct _GlyphRef {
- CARD32 signature;
- GlyphPtr glyph;
-} GlyphRefRec, *GlyphRefPtr;
-
-#define DeletedGlyph ((GlyphPtr) 1)
-
-typedef struct _GlyphHashSet {
- CARD32 entries;
- CARD32 size;
- CARD32 rehash;
-} GlyphHashSetRec, *GlyphHashSetPtr;
-
-typedef struct _GlyphHash {
- GlyphRefPtr table;
- GlyphHashSetPtr hashSet;
- CARD32 tableEntries;
-} GlyphHashRec, *GlyphHashPtr;
-
-typedef struct _GlyphSet {
- CARD32 refcnt;
- int fdepth;
- PictFormatPtr format;
- GlyphHashRec hash;
- PrivateRec *devPrivates;
-} GlyphSetRec, *GlyphSetPtr;
-
-#define GlyphSetGetPrivate(pGlyphSet,k) \
- dixLookupPrivate(&(pGlyphSet)->devPrivates, k)
-
-#define GlyphSetSetPrivate(pGlyphSet,k,ptr) \
- dixSetPrivate(&(pGlyphSet)->devPrivates, k, ptr)
-
-typedef struct _GlyphList {
- INT16 xOff;
- INT16 yOff;
- CARD8 len;
- PictFormatPtr format;
-} GlyphListRec, *GlyphListPtr;
-
-extern _X_EXPORT GlyphHashSetPtr
-FindGlyphHashSet (CARD32 filled);
-
-extern _X_EXPORT void
-GlyphUninit (ScreenPtr pScreen);
-
-extern _X_EXPORT GlyphHashSetPtr
-FindGlyphHashSet (CARD32 filled);
-
-extern _X_EXPORT GlyphRefPtr
-FindGlyphRef (GlyphHashPtr hash,
- CARD32 signature,
- Bool match,
- unsigned char sha1[20]);
-
-extern _X_EXPORT GlyphPtr
-FindGlyphByHash (unsigned char sha1[20], int format);
-
-extern _X_EXPORT int
-HashGlyph (xGlyphInfo *gi,
- CARD8 *bits,
- unsigned long size,
- unsigned char sha1[20]);
-
-extern _X_EXPORT void
-FreeGlyph (GlyphPtr glyph, int format);
-
-extern _X_EXPORT void
-AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id);
-
-extern _X_EXPORT Bool
-DeleteGlyph (GlyphSetPtr glyphSet, Glyph id);
-
-extern _X_EXPORT GlyphPtr
-FindGlyph (GlyphSetPtr glyphSet, Glyph id);
-
-extern _X_EXPORT GlyphPtr
-AllocateGlyph (xGlyphInfo *gi, int format);
-
-extern _X_EXPORT Bool
-AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet);
-
-extern _X_EXPORT Bool
-ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global);
-
-extern _X_EXPORT Bool
-ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change);
-
-extern _X_EXPORT GlyphSetPtr
-AllocateGlyphSet (int fdepth, PictFormatPtr format);
-
-extern _X_EXPORT int
-FreeGlyphSet (pointer value,
- XID gid);
-
-
-
-#endif /* _GLYPHSTR_H_ */
+/* + * + * Copyright © 2000 SuSE, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of SuSE not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. SuSE makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Keith Packard, SuSE, Inc. + */ + +#ifndef _GLYPHSTR_H_ +#define _GLYPHSTR_H_ + +#include <X11/extensions/renderproto.h> +#include "picture.h" +#include "screenint.h" +#include "regionstr.h" +#include "miscstruct.h" +#include "privates.h" + +#define GlyphFormat1 0 +#define GlyphFormat4 1 +#define GlyphFormat8 2 +#define GlyphFormat16 3 +#define GlyphFormat32 4 +#define GlyphFormatNum 5 + +typedef struct _Glyph { + CARD32 refcnt; + PrivateRec *devPrivates; + unsigned char sha1[20]; + CARD32 size; /* info + bitmap */ + xGlyphInfo info; + /* per-screen pixmaps follow */ +} GlyphRec, *GlyphPtr; + +#define GlyphPicture(glyph) ((PicturePtr *) ((glyph) + 1)) + +typedef struct _GlyphRef { + CARD32 signature; + GlyphPtr glyph; +} GlyphRefRec, *GlyphRefPtr; + +#define DeletedGlyph ((GlyphPtr) 1) + +typedef struct _GlyphHashSet { + CARD32 entries; + CARD32 size; + CARD32 rehash; +} GlyphHashSetRec, *GlyphHashSetPtr; + +typedef struct _GlyphHash { + GlyphRefPtr table; + GlyphHashSetPtr hashSet; + CARD32 tableEntries; +} GlyphHashRec, *GlyphHashPtr; + +typedef struct _GlyphSet { + CARD32 refcnt; + int fdepth; + PictFormatPtr format; + GlyphHashRec hash; + PrivateRec *devPrivates; +} GlyphSetRec, *GlyphSetPtr; + +#define GlyphSetGetPrivate(pGlyphSet,k) \ + dixLookupPrivate(&(pGlyphSet)->devPrivates, k) + +#define GlyphSetSetPrivate(pGlyphSet,k,ptr) \ + dixSetPrivate(&(pGlyphSet)->devPrivates, k, ptr) + +typedef struct _GlyphList { + INT16 xOff; + INT16 yOff; + CARD8 len; + PictFormatPtr format; +} GlyphListRec, *GlyphListPtr; + +extern _X_EXPORT void +GlyphUninit (ScreenPtr pScreen); + +extern _X_EXPORT GlyphHashSetPtr +FindGlyphHashSet (CARD32 filled); + +extern _X_EXPORT GlyphRefPtr +FindGlyphRef (GlyphHashPtr hash, + CARD32 signature, + Bool match, + unsigned char sha1[20]); + +extern _X_EXPORT GlyphPtr +FindGlyphByHash (unsigned char sha1[20], int format); + +extern _X_EXPORT int +HashGlyph (xGlyphInfo *gi, + CARD8 *bits, + unsigned long size, + unsigned char sha1[20]); + +extern _X_EXPORT void +FreeGlyph (GlyphPtr glyph, int format); + +extern _X_EXPORT void +AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id); + +extern _X_EXPORT Bool +DeleteGlyph (GlyphSetPtr glyphSet, Glyph id); + +extern _X_EXPORT GlyphPtr +FindGlyph (GlyphSetPtr glyphSet, Glyph id); + +extern _X_EXPORT GlyphPtr +AllocateGlyph (xGlyphInfo *gi, int format); + +extern _X_EXPORT Bool +AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet); + +extern _X_EXPORT Bool +ResizeGlyphHash (GlyphHashPtr hash, CARD32 change, Bool global); + +extern _X_EXPORT Bool +ResizeGlyphSet (GlyphSetPtr glyphSet, CARD32 change); + +extern _X_EXPORT GlyphSetPtr +AllocateGlyphSet (int fdepth, PictFormatPtr format); + +extern _X_EXPORT int +FreeGlyphSet (pointer value, + XID gid); + + + +#endif /* _GLYPHSTR_H_ */ diff --git a/xorg-server/render/picturestr.h b/xorg-server/render/picturestr.h index 1f3f5a433..9b376710e 100644 --- a/xorg-server/render/picturestr.h +++ b/xorg-server/render/picturestr.h @@ -433,20 +433,20 @@ extern _X_EXPORT Bool PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats); extern _X_EXPORT int -PictureGetFilterId (char *filter, int len, Bool makeit); +PictureGetFilterId (const char *filter, int len, Bool makeit); extern _X_EXPORT char * PictureGetFilterName (int id); extern _X_EXPORT int PictureAddFilter (ScreenPtr pScreen, - char *filter, + const char *filter, PictFilterValidateParamsProcPtr ValidateParams, int width, int height); extern _X_EXPORT Bool -PictureSetFilterAlias (ScreenPtr pScreen, char *filter, char *alias); +PictureSetFilterAlias (ScreenPtr pScreen, const char *filter, const char *alias); extern _X_EXPORT Bool PictureSetDefaultFilters (ScreenPtr pScreen); diff --git a/xorg-server/render/render.c b/xorg-server/render/render.c index ff75409cb..d82e09959 100644 --- a/xorg-server/render/render.c +++ b/xorg-server/render/render.c @@ -1800,7 +1800,7 @@ ProcRenderQueryFilters (ClientPtr client) { j = strlen (ps->filters[i].name); *names++ = j; - strncpy (names, ps->filters[i].name, j); + memcpy (names, ps->filters[i].name, j); names += j; } @@ -1809,7 +1809,7 @@ ProcRenderQueryFilters (ClientPtr client) { j = strlen (ps->filterAliases[i].alias); *names++ = j; - strncpy (names, ps->filterAliases[i].alias, j); + memcpy (names, ps->filterAliases[i].alias, j); names += j; } } diff --git a/xorg-server/test/Makefile.am b/xorg-server/test/Makefile.am index 689dd7f60..62c398c18 100644 --- a/xorg-server/test/Makefile.am +++ b/xorg-server/test/Makefile.am @@ -1,10 +1,10 @@ if ENABLE_UNIT_TESTS -if HAVE_LD_WRAP SUBDIRS= . xi2 -noinst_PROGRAMS = xkb input xtest list misc fixes xfree86 +noinst_PROGRAMS = xkb input xtest list misc fixes xfree86 string check_LTLIBRARIES = libxservertest.la TESTS=$(noinst_PROGRAMS) +TESTS_ENVIRONMENT = $(XORG_MALLOC_DEBUG_ENV) AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@ INCLUDES = $(XORG_INCS) -I$(top_srcdir)/hw/xfree86/parser \ @@ -43,4 +43,3 @@ libxservertest_la_LIBADD = \ @XORG_LIBS@ libxservertest_la_DEPENDENCIES = $(libxservertest_la_LIBADD) endif -endif diff --git a/xorg-server/test/string.c b/xorg-server/test/string.c new file mode 100644 index 000000000..e3a5adb6d --- /dev/null +++ b/xorg-server/test/string.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * Tests for fallback implementations of string handling routines + * provided in os/ subdirectory for some platforms. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <assert.h> +#include "os.h" + +/* Ensure we're testing our functions, even on platforms with libc versions */ +#include <string.h> +#undef strndup +#define strndup my_strndup +char * +strndup(const char *str, size_t n); + +#include "../os/strndup.c" + +static void strndup_checks(void) +{ + const char *sample="0123456789abcdef"; + char *allofit; + + char *firsthalf = strndup(sample, 8); + char *secondhalf = strndup(sample + 8, 8); + + assert(strcmp(firsthalf, "01234567") == 0); + assert(strcmp(secondhalf, "89abcdef") == 0); + + free(firsthalf); + free(secondhalf); + + allofit = strndup(sample, 20); + assert(strcmp(allofit, sample) == 0); + free(allofit); +} + +int main(int argc, char** argv) +{ + strndup_checks(); + + return 0; +} diff --git a/xorg-server/test/xi2/Makefile.am b/xorg-server/test/xi2/Makefile.am index b15d8ba02..c6e93e78f 100644 --- a/xorg-server/test/xi2/Makefile.am +++ b/xorg-server/test/xi2/Makefile.am @@ -13,6 +13,7 @@ noinst_PROGRAMS = \ protocol-eventconvert TESTS=$(noinst_PROGRAMS) +TESTS_ENVIRONMENT = $(XORG_MALLOC_DEBUG_ENV) AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@ INCLUDES = @XORG_INCS@ @@ -53,5 +54,14 @@ protocol_xigetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xigetclientpointe protocol_xiquerypointer_SOURCES=$(COMMON_SOURCES) protocol-xiquerypointer.c protocol_xipassivegrabdevice_SOURCES=$(COMMON_SOURCES) protocol-xipassivegrabdevice.c protocol_xiwarppointer_SOURCES=$(COMMON_SOURCES) protocol-xiwarppointer.c +else +# Print that xi2-tests were skipped (exit code 77 for automake test harness) +TESTS = xi2-tests +CLEANFILES = $(TESTS) + +xi2-tests: + @echo 'echo "ld -wrap support required for xi2 unit tests, skipping"' > $@ + @echo 'exit 77' >> $@ + $(AM_V_GEN)chmod +x $@ endif endif diff --git a/xorg-server/xkb/ddxList.c b/xorg-server/xkb/ddxList.c index e599f9169..db34c8df5 100644 --- a/xorg-server/xkb/ddxList.c +++ b/xorg-server/xkb/ddxList.c @@ -60,7 +60,7 @@ extern int Win32System(const char *cmdline); /***====================================================================***/ -static char *componentDirs[_XkbListNumComponents] = { +static const char *componentDirs[_XkbListNumComponents] = { "keycodes", "types", "compat", "symbols", "geometry" }; diff --git a/xorg-server/xkb/ddxLoad.c b/xorg-server/xkb/ddxLoad.c index 219d39c9a..196142318 100644 --- a/xorg-server/xkb/ddxLoad.c +++ b/xorg-server/xkb/ddxLoad.c @@ -263,8 +263,7 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, if (xkbDebugFlags) DebugF("[xkb] xkb executes: %s\n",buf); if (nameRtrn) { - strncpy(nameRtrn,keymap,nameRtrnLen); - nameRtrn[nameRtrnLen-1]= '\0'; + strlcpy(nameRtrn,keymap,nameRtrnLen); } free(buf); #ifdef WIN32 @@ -322,8 +321,7 @@ FILE * file; } else file= NULL; if ((fileNameRtrn!=NULL)&&(fileNameRtrnLen>0)) { - strncpy(fileNameRtrn,buf,fileNameRtrnLen); - buf[fileNameRtrnLen-1]= '\0'; + strlcpy(fileNameRtrn,buf,fileNameRtrnLen); } return file; } diff --git a/xorg-server/xkb/maprules.c b/xorg-server/xkb/maprules.c index f94089982..66800478c 100644 --- a/xorg-server/xkb/maprules.c +++ b/xorg-server/xkb/maprules.c @@ -200,7 +200,7 @@ Bool endOfFile,spacePending,slashPending,inComment; #define PART_MASK 0x000F #define COMPONENT_MASK 0x03F0 -static char * cname[MAX_WORDS] = { +static const char * cname[MAX_WORDS] = { "model", "layout", "variant", "option", "keycodes", "symbols", "types", "compat", "geometry" }; @@ -250,8 +250,7 @@ get_index(char *str, int *ndx) *ndx = -1; return end + 1; } - strncpy(ndx_buf, str, end - str); - ndx_buf[end - str] = '\0'; + strlcpy(ndx_buf, str, 1 + end - str); *ndx = atoi(ndx_buf); return end + 1; } diff --git a/xorg-server/xkb/xkbInit.c b/xorg-server/xkb/xkbInit.c index 3d3febb4f..f578f1679 100644 --- a/xorg-server/xkb/xkbInit.c +++ b/xorg-server/xkb/xkbInit.c @@ -88,8 +88,8 @@ typedef struct _SrvXkmInfo { #define XKB_DFLT_RULES_PROP TRUE #endif -char * XkbBaseDirectory= XKB_BASE_DIRECTORY; -char * XkbBinDirectory= XKB_BIN_DIRECTORY; +const char * XkbBaseDirectory= XKB_BASE_DIRECTORY; +const char * XkbBinDirectory= XKB_BIN_DIRECTORY; static int XkbWantAccessX= 0; static char * XkbRulesDflt= NULL; @@ -117,22 +117,11 @@ static Bool XkbWantRulesProp= XKB_DFLT_RULES_PROP; void XkbGetRulesDflts(XkbRMLVOSet *rmlvo) { - if (XkbRulesDflt) rmlvo->rules = XkbRulesDflt; - else rmlvo->rules = XKB_DFLT_RULES; - if (XkbModelDflt) rmlvo->model= XkbModelDflt; - else rmlvo->model= XKB_DFLT_MODEL; - if (XkbLayoutDflt) rmlvo->layout= XkbLayoutDflt; - else rmlvo->layout= XKB_DFLT_LAYOUT; - if (XkbVariantDflt) rmlvo->variant= XkbVariantDflt; - else rmlvo->variant= XKB_DFLT_VARIANT; - if (XkbOptionsDflt) rmlvo->options= XkbOptionsDflt; - else rmlvo->options= XKB_DFLT_OPTIONS; - - rmlvo->rules = strdup(rmlvo->rules); - rmlvo->model = strdup(rmlvo->model); - rmlvo->layout = strdup(rmlvo->layout); - rmlvo->variant = strdup(rmlvo->variant); - rmlvo->options = strdup(rmlvo->options); + rmlvo->rules = strdup(XkbRulesDflt ? XkbRulesDflt : XKB_DFLT_RULES); + rmlvo->model = strdup(XkbModelDflt ? XkbModelDflt : XKB_DFLT_MODEL); + rmlvo->layout = strdup(XkbLayoutDflt ? XkbLayoutDflt : XKB_DFLT_LAYOUT); + rmlvo->variant= strdup(XkbVariantDflt ? XkbVariantDflt : XKB_DFLT_VARIANT); + rmlvo->options= strdup(XkbOptionsDflt ? XkbOptionsDflt : XKB_DFLT_OPTIONS); } void diff --git a/xorg-server/xkb/xkbfmisc.c b/xorg-server/xkb/xkbfmisc.c index d8202b496..782b823bb 100644 --- a/xorg-server/xkb/xkbfmisc.c +++ b/xorg-server/xkb/xkbfmisc.c @@ -146,7 +146,7 @@ unsigned set,rtrn; /***===================================================================***/ static Bool -XkbWriteSectionFromName(FILE *file,char *sectionName,char *name) +XkbWriteSectionFromName(FILE *file,const char *sectionName,const char *name) { fprintf(file," xkb_%-20s { include \"%s\" };\n",sectionName,name); return TRUE; diff --git a/xorg-server/xkb/xkbout.c b/xorg-server/xkb/xkbout.c index 082c85ee9..889d5cc39 100644 --- a/xorg-server/xkb/xkbout.c +++ b/xorg-server/xkb/xkbout.c @@ -108,7 +108,7 @@ XkbWriteXKBKeycodes( FILE * file, { Atom kcName; register unsigned i; -char * alternate; +const char * alternate; if ((!xkb)||(!xkb->names)||(!xkb->names->keys)) { _XkbLibError(_XkbErrMissingNames,"XkbWriteXKBKeycodes",0); @@ -133,7 +133,7 @@ char * alternate; } if (xkb->indicators!=NULL) { for (i=0;i<XkbNumIndicators;i++) { - char *type; + const char *type; if (xkb->indicators->phys_indicators&(1<<i)) type= " "; else type= " virtual "; @@ -395,7 +395,7 @@ Bool showActions; (showImplicit)) { int typeNdx,g; Bool multi; - char * comment=" "; + const char * comment=" "; if ((srv->explicit[i]&XkbExplicitKeyTypesMask)==0) comment= "//"; diff --git a/xorg-server/xkb/xkbtext.c b/xorg-server/xkb/xkbtext.c index 9f49d59ff..8ef2b05b0 100644 --- a/xorg-server/xkb/xkbtext.c +++ b/xorg-server/xkb/xkbtext.c @@ -81,8 +81,7 @@ char *rtrn,*tmp; if (len>BUFFER_SIZE) len= BUFFER_SIZE-2; rtrn= tbGetBuffer(len); - strncpy(rtrn,atmstr,len); - rtrn[len]= '\0'; + strlcpy(rtrn,atmstr,len); } else { rtrn= tbGetBuffer(1); @@ -120,7 +119,7 @@ char numBuf[20]; else if (vmodNames&&(vmodNames[ndx]!=None)) tmp= NameForAtom(vmodNames[ndx]); if (tmp==NULL) { - sprintf(numBuf,"%d",ndx); + snprintf(numBuf,sizeof(numBuf),"%d",ndx); tmp = numBuf; } @@ -216,7 +215,7 @@ char *str,buf[BUFFER_SIZE]; return rtrn; } -static char *modNames[XkbNumModifiers] = { +static const char *modNames[XkbNumModifiers] = { "Shift", "Lock", "Control", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5" }; @@ -228,17 +227,17 @@ char buf[100]; if (format==XkbCFile) { if (ndx<XkbNumModifiers) - sprintf(buf,"%sMapIndex",modNames[ndx]); + snprintf(buf,sizeof(buf),"%sMapIndex",modNames[ndx]); else if (ndx==XkbNoModifier) - sprintf(buf,"XkbNoModifier"); - else sprintf(buf,"0x%02x",ndx); + snprintf(buf,sizeof(buf),"XkbNoModifier"); + else snprintf(buf,sizeof(buf),"0x%02x",ndx); } else { if (ndx<XkbNumModifiers) strcpy(buf,modNames[ndx]); else if (ndx==XkbNoModifier) strcpy(buf,"none"); - else sprintf(buf,"ILLEGAL_%02x",ndx); + else snprintf(buf,sizeof(buf),"ILLEGAL_%02x",ndx); } rtrn= tbGetBuffer(strlen(buf)+1); strcpy(rtrn,buf); @@ -335,12 +334,12 @@ static char *buf; char * XkbKeysymText(KeySym sym,unsigned format) { -static char buf[32],*rtrn; +static char buf[32]; if (sym==NoSymbol) - strcpy(rtrn=buf,"NoSymbol"); - else sprintf(rtrn=buf, "0x%lx", (long)sym); - return rtrn; + strcpy(buf,"NoSymbol"); + else snprintf(buf, sizeof(buf), "0x%lx", (long)sym); + return buf; } char * @@ -368,15 +367,15 @@ char *buf; /***====================================================================***/ -static char *siMatchText[5] = { +static const char *siMatchText[5] = { "NoneOf", "AnyOfOrNone", "AnyOf", "AllOf", "Exactly" }; -char * +const char * XkbSIMatchText(unsigned type,unsigned format) { static char buf[40]; -char *rtrn; +const char *rtrn; switch (type&XkbSI_OpMask) { case XkbSI_NoneOf: rtrn= siMatchText[0]; break; @@ -384,13 +383,13 @@ char *rtrn; case XkbSI_AnyOf: rtrn= siMatchText[2]; break; case XkbSI_AllOf: rtrn= siMatchText[3]; break; case XkbSI_Exactly: rtrn= siMatchText[4]; break; - default: sprintf(buf,"0x%x",type&XkbSI_OpMask); + default: snprintf(buf,sizeof(buf),"0x%x",type&XkbSI_OpMask); return buf; } if (format==XkbCFile) { if (type&XkbSI_LevelOneOnly) - sprintf(buf,"XkbSI_LevelOneOnly|XkbSI_%s",rtrn); - else sprintf(buf,"XkbSI_%s",rtrn); + snprintf(buf,sizeof(buf),"XkbSI_LevelOneOnly|XkbSI_%s",rtrn); + else snprintf(buf,sizeof(buf),"XkbSI_%s",rtrn); rtrn= buf; } return rtrn; @@ -398,7 +397,7 @@ char *rtrn; /***====================================================================***/ -static char *imWhichNames[]= { +static const char *imWhichNames[]= { "base", "latched", "locked", @@ -449,7 +448,7 @@ char * buf; return buf; } -static char *ctrlNames[] = { +static const char *ctrlNames[] = { "repeatKeys", "slowKeys", "bounceKeys", @@ -617,7 +616,7 @@ char * buf; return buf; } -static char *actionTypeNames[XkbSA_NumActions]= { +static const char *actionTypeNames[XkbSA_NumActions]= { "NoAction", "SetMods", "LatchMods", "LockMods", "SetGroup", "LatchGroup", "LockGroup", @@ -632,28 +631,28 @@ static char *actionTypeNames[XkbSA_NumActions]= { "DeviceBtn", "LockDeviceBtn" }; -char * +const char * XkbActionTypeText(unsigned type,unsigned format) { static char buf[32]; -char *rtrn; +const char *rtrn; if (type<=XkbSA_LastAction) { rtrn= actionTypeNames[type]; if (format==XkbCFile) { - sprintf(buf,"XkbSA_%s",rtrn); + snprintf(buf,sizeof(buf),"XkbSA_%s",rtrn); return buf; } return rtrn; } - sprintf(buf,"Private"); + snprintf(buf,sizeof(buf),"Private"); return buf; } /***====================================================================***/ static int -TryCopyStr(char *to,char *from,int *pLeft) +TryCopyStr(char *to,const char *from,int *pLeft) { register int len; if (*pLeft>0) { @@ -713,10 +712,10 @@ char tbuf[32]; act= &action->group; TryCopyStr(buf,"group=",sz); if (act->flags&XkbSA_GroupAbsolute) - sprintf(tbuf,"%d",XkbSAGroup(act)+1); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAGroup(act)+1); else if (XkbSAGroup(act)<0) - sprintf(tbuf,"%d",XkbSAGroup(act)); - else sprintf(tbuf,"+%d",XkbSAGroup(act)); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAGroup(act)); + else snprintf(tbuf,sizeof(tbuf),"+%d",XkbSAGroup(act)); TryCopyStr(buf,tbuf,sz); if (act->type==XkbSA_LockGroup) return TRUE; @@ -739,13 +738,13 @@ char tbuf[32]; x= XkbPtrActionX(act); y= XkbPtrActionY(act); if ((act->flags&XkbSA_MoveAbsoluteX)||(x<0)) - sprintf(tbuf,"x=%d",x); - else sprintf(tbuf,"x=+%d",x); + snprintf(tbuf,sizeof(tbuf),"x=%d",x); + else snprintf(tbuf,sizeof(tbuf),"x=+%d",x); TryCopyStr(buf,tbuf,sz); if ((act->flags&XkbSA_MoveAbsoluteY)||(y<0)) - sprintf(tbuf,",y=%d",y); - else sprintf(tbuf,",y=+%d",y); + snprintf(tbuf,sizeof(tbuf),",y=%d",y); + else snprintf(tbuf,sizeof(tbuf),",y=+%d",y); TryCopyStr(buf,tbuf,sz); if (act->flags&XkbSA_NoAcceleration) TryCopyStr(buf,",!accel",sz); @@ -762,26 +761,25 @@ char tbuf[32]; act= &action->btn; TryCopyStr(buf,"button=",sz); if ((act->button>0)&&(act->button<6)) { - sprintf(tbuf,"%d",act->button); + snprintf(tbuf,sizeof(tbuf),"%d",act->button); TryCopyStr(buf,tbuf,sz); } else TryCopyStr(buf,"default",sz); if (act->count>0) { - sprintf(tbuf,",count=%d",act->count); + snprintf(tbuf,sizeof(tbuf),",count=%d",act->count); TryCopyStr(buf,tbuf,sz); } if (action->type==XkbSA_LockPtrBtn) { switch (act->flags&(XkbSA_LockNoUnlock|XkbSA_LockNoLock)) { case XkbSA_LockNoLock: - sprintf(tbuf,",affect=unlock"); break; + TryCopyStr(buf,",affect=unlock",sz); break; case XkbSA_LockNoUnlock: - sprintf(tbuf,",affect=lock"); break; + TryCopyStr(buf,",affect=lock",sz); break; case XkbSA_LockNoUnlock|XkbSA_LockNoLock: - sprintf(tbuf,",affect=neither"); break; + TryCopyStr(buf,",affect=neither",sz); break; default: - sprintf(tbuf,",affect=both"); break; + TryCopyStr(buf,",affect=both",sz); break; } - TryCopyStr(buf,tbuf,sz); } return TRUE; } @@ -798,8 +796,8 @@ char tbuf[32]; if (act->affect==XkbSA_AffectDfltBtn) { TryCopyStr(buf,"affect=button,button=",sz); if ((act->flags&XkbSA_DfltBtnAbsolute)||(XkbSAPtrDfltValue(act)<0)) - sprintf(tbuf,"%d",XkbSAPtrDfltValue(act)); - else sprintf(tbuf,"+%d",XkbSAPtrDfltValue(act)); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAPtrDfltValue(act)); + else snprintf(tbuf,sizeof(tbuf),"+%d",XkbSAPtrDfltValue(act)); TryCopyStr(buf,tbuf,sz); } return TRUE; @@ -815,10 +813,10 @@ char tbuf[64]; if (act->flags&XkbSA_ISODfltIsGroup) { TryCopyStr(tbuf,"group=",sz); if (act->flags&XkbSA_GroupAbsolute) - sprintf(tbuf,"%d",XkbSAGroup(act)+1); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAGroup(act)+1); else if (XkbSAGroup(act)<0) - sprintf(tbuf,"%d",XkbSAGroup(act)); - else sprintf(tbuf,"+%d",XkbSAGroup(act)); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAGroup(act)); + else snprintf(tbuf,sizeof(tbuf),"+%d",XkbSAGroup(act)); TryCopyStr(buf,tbuf,sz); } else { @@ -848,17 +846,17 @@ char tbuf[64]; nOut++; } if ((act->affect&XkbSA_ISONoAffectGroup)==0) { - sprintf(tbuf,"%sgroups",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sgroups",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if ((act->affect&XkbSA_ISONoAffectPtr)==0) { - sprintf(tbuf,"%spointer",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%spointer",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if ((act->affect&XkbSA_ISONoAffectCtrls)==0) { - sprintf(tbuf,"%scontrols",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%scontrols",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } @@ -876,8 +874,8 @@ char tbuf[32]; act= &action->screen; if ((act->flags&XkbSA_SwitchAbsolute)||(XkbSAScreen(act)<0)) - sprintf(tbuf,"screen=%d",XkbSAScreen(act)); - else sprintf(tbuf,"screen=+%d",XkbSAScreen(act)); + snprintf(tbuf,sizeof(tbuf),"screen=%d",XkbSAScreen(act)); + else snprintf(tbuf,sizeof(tbuf),"screen=+%d",XkbSAScreen(act)); TryCopyStr(buf,tbuf,sz); if (act->flags&XkbSA_SwitchApplication) TryCopyStr(buf,",!same",sz); @@ -904,67 +902,67 @@ char tbuf[32]; else { int nOut= 0; if (tmp&XkbRepeatKeysMask) { - sprintf(tbuf,"%sRepeatKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sRepeatKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbSlowKeysMask) { - sprintf(tbuf,"%sSlowKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sSlowKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbBounceKeysMask) { - sprintf(tbuf,"%sBounceKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sBounceKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbStickyKeysMask) { - sprintf(tbuf,"%sStickyKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sStickyKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbMouseKeysMask) { - sprintf(tbuf,"%sMouseKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sMouseKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbMouseKeysAccelMask) { - sprintf(tbuf,"%sMouseKeysAccel",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sMouseKeysAccel",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXKeysMask) { - sprintf(tbuf,"%sAccessXKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sAccessXKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXTimeoutMask) { - sprintf(tbuf,"%sAccessXTimeout",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sAccessXTimeout",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXFeedbackMask) { - sprintf(tbuf,"%sAccessXFeedback",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sAccessXFeedback",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAudibleBellMask) { - sprintf(tbuf,"%sAudibleBell",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sAudibleBell",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbOverlay1Mask) { - sprintf(tbuf,"%sOverlay1",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sOverlay1",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbOverlay2Mask) { - sprintf(tbuf,"%sOverlay2",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sOverlay2",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbIgnoreGroupLockMask) { - sprintf(tbuf,"%sIgnoreGroupLock",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sIgnoreGroupLock",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } @@ -991,12 +989,12 @@ char tbuf[32]; else if (act->flags&XkbSA_MessageOnPress) TryCopyStr(buf,"KeyPress",sz); else TryCopyStr(buf,"KeyRelease",sz); - sprintf(tbuf,",data[0]=0x%02x",act->message[0]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[1]=0x%02x",act->message[1]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[2]=0x%02x",act->message[2]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[3]=0x%02x",act->message[3]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[4]=0x%02x",act->message[4]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[5]=0x%02x",act->message[5]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[0]=0x%02x",act->message[0]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[1]=0x%02x",act->message[1]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[2]=0x%02x",act->message[2]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[3]=0x%02x",act->message[3]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[4]=0x%02x",act->message[4]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[5]=0x%02x",act->message[5]); TryCopyStr(buf,tbuf,sz); return TRUE; } @@ -1017,9 +1015,9 @@ unsigned vmods,vmods_mask; (xkb->names->keys[kc].name[0]!='\0')) { char *kn; kn= XkbKeyNameText(xkb->names->keys[kc].name,XkbXKBFile); - sprintf(tbuf,"key=%s",kn); + snprintf(tbuf,sizeof(tbuf),"key=%s",kn); } - else sprintf(tbuf,"key=%d",kc); + else snprintf(tbuf,sizeof(tbuf),"key=%d",kc); TryCopyStr(buf,tbuf,sz); if ((act->mods_mask==0)&&(vmods_mask==0)) return TRUE; @@ -1055,26 +1053,25 @@ XkbDeviceBtnAction * act; char tbuf[32]; act= &action->devbtn; - sprintf(tbuf,"device= %d",act->device); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),"device= %d",act->device); TryCopyStr(buf,tbuf,sz); TryCopyStr(buf,",button=",sz); - sprintf(tbuf,"%d",act->button); + snprintf(tbuf,sizeof(tbuf),"%d",act->button); TryCopyStr(buf,tbuf,sz); if (act->count>0) { - sprintf(tbuf,",count=%d",act->count); + snprintf(tbuf,sizeof(tbuf),",count=%d",act->count); TryCopyStr(buf,tbuf,sz); } if (action->type==XkbSA_LockDeviceBtn) { switch (act->flags&(XkbSA_LockNoUnlock|XkbSA_LockNoLock)) { case XkbSA_LockNoLock: - sprintf(tbuf,",affect=unlock"); break; + TryCopyStr(buf,",affect=unlock",sz); break; case XkbSA_LockNoUnlock: - sprintf(tbuf,",affect=lock"); break; + TryCopyStr(buf,",affect=lock",sz); break; case XkbSA_LockNoUnlock|XkbSA_LockNoLock: - sprintf(tbuf,",affect=neither"); break; + TryCopyStr(buf,",affect=neither",sz); break; default: - sprintf(tbuf,",affect=both"); break; + TryCopyStr(buf,",affect=both",sz); break; } - TryCopyStr(buf,tbuf,sz); } return TRUE; } @@ -1087,14 +1084,14 @@ XkbAnyAction * act; char tbuf[32]; act= &action->any; - sprintf(tbuf,"type=0x%02x",act->type); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[0]=0x%02x",act->data[0]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[1]=0x%02x",act->data[1]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[2]=0x%02x",act->data[2]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[3]=0x%02x",act->data[3]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[4]=0x%02x",act->data[4]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[5]=0x%02x",act->data[5]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[6]=0x%02x",act->data[6]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),"type=0x%02x",act->type); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[0]=0x%02x",act->data[0]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[1]=0x%02x",act->data[1]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[2]=0x%02x",act->data[2]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[3]=0x%02x",act->data[3]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[4]=0x%02x",act->data[4]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[5]=0x%02x",act->data[5]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[6]=0x%02x",act->data[6]); TryCopyStr(buf,tbuf,sz); return TRUE; } @@ -1136,7 +1133,7 @@ char buf[ACTION_SZ],*tmp; int sz; if (format==XkbCFile) { - sprintf(buf, + snprintf(buf,sizeof(buf), "{ %20s, { 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x } }", XkbActionTypeText(action->type,XkbCFile), action->any.data[0],action->any.data[1],action->any.data[2], @@ -1144,7 +1141,7 @@ int sz; action->any.data[6]); } else { - sprintf(buf,"%s(",XkbActionTypeText(action->type,XkbXKBFile)); + snprintf(buf,sizeof(buf),"%s(",XkbActionTypeText(action->type,XkbXKBFile)); sz= ACTION_SZ-strlen(buf)+2; /* room for close paren and NULL */ if (action->type<(unsigned)XkbSA_NumActions) (*copyActionArgs[action->type])(xkb,action,buf,&sz); @@ -1164,8 +1161,8 @@ char buf[256],*tmp; if (format==XkbCFile) { if (behavior->type==XkbKB_Default) - sprintf(buf,"{ 0, 0 }"); - else sprintf(buf,"{ %3d, 0x%02x }",behavior->type,behavior->data); + snprintf(buf,sizeof(buf),"{ 0, 0 }"); + else snprintf(buf,sizeof(buf),"{ %3d, 0x%02x }",behavior->type,behavior->data); } else { unsigned type,permanent; @@ -1173,14 +1170,14 @@ char buf[256],*tmp; permanent=((behavior->type&XkbKB_Permanent)!=0); if (type==XkbKB_Lock) { - sprintf(buf,"lock= %s",(permanent?"Permanent":"TRUE")); + snprintf(buf,sizeof(buf),"lock= %s",(permanent?"Permanent":"TRUE")); } else if (type==XkbKB_RadioGroup) { int g; char *tmp; g= ((behavior->data)&(~XkbKB_RGAllowNone))+1; if (XkbKB_RGAllowNone&behavior->data) { - sprintf(buf,"allowNone,"); + snprintf(buf,sizeof(buf),"allowNone,"); tmp= &buf[strlen(buf)]; } else tmp= buf; @@ -1198,12 +1195,12 @@ char buf[256],*tmp; kn= XkbKeyNameText(xkb->names->keys[kc].name,XkbXKBFile); else { static char tbuf[8]; - sprintf(tbuf,"%d",kc); + snprintf(tbuf,sizeof(tbuf),"%d",kc); kn= tbuf; } if (permanent) - sprintf(buf,"permanentOverlay%d= %s",ndx,kn); - else sprintf(buf,"overlay%d= %s",ndx,kn); + snprintf(buf,sizeof(buf),"permanentOverlay%d= %s",ndx,kn); + else snprintf(buf,sizeof(buf),"overlay%d= %s",ndx,kn); } } tmp= tbGetBuffer(strlen(buf)+1); |