53 #include <private/qfontengine_ft_p.h> 54 #include <private/qt_x11_p.h> 55 #include <private/qpixmap_x11_p.h> 56 #include <private/qimagepixmapcleanuphooks_p.h> 57 #include <private/qunicodetables_p.h> 60 #include <private/qglpixelbuffer_p.h> 65 #define GLX_EXT_texture_from_pixmap 1 67 #define INT8 dummy_INT8 68 #define INT32 dummy_INT32 74 #include <X11/Xutil.h> 83 #endif // Q_OS_VXWORKS 84 #include <X11/Xatom.h> 86 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) 95 #ifndef GLX_ARB_multisample 96 #define GLX_SAMPLE_BUFFERS_ARB 100000 97 #define GLX_SAMPLES_ARB 100001 100 #ifndef GLX_TEXTURE_2D_BIT_EXT 101 #define GLX_TEXTURE_2D_BIT_EXT 0x00000002 102 #define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004 103 #define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0 104 #define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1 105 #define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2 106 #define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3 107 #define GLX_Y_INVERTED_EXT 0x20D4 108 #define GLX_TEXTURE_FORMAT_EXT 0x20D5 109 #define GLX_TEXTURE_TARGET_EXT 0x20D6 110 #define GLX_MIPMAP_TEXTURE_EXT 0x20D7 111 #define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8 112 #define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9 113 #define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA 114 #define GLX_TEXTURE_2D_EXT 0x20DC 115 #define GLX_TEXTURE_RECTANGLE_EXT 0x20DD 116 #define GLX_FRONT_LEFT_EXT 0x20DE 119 #ifndef GLX_ARB_create_context 120 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 121 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 122 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 123 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 124 #define GLX_CONTEXT_FLAGS_ARB 0x2094 127 #ifndef GLX_ARB_create_context_profile 128 #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 129 #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 130 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 160 XFreeColormap(
X11->display,
cmap);
193 cmap_handler()->qglcmap_hash->clear();
199 const char *v = glXQueryServerString(dpy, vi->screen, GLX_VERSION);
201 mesa_gl = (strstr(v,
"Mesa") != 0);
208 return it.
value()->cmap;
218 XStandardColormap *
c;
224 Atom hp_cmaps = XInternAtom(dpy,
"_HP_RGB_SMOOTH_MAP_LIST",
true);
225 if (hp_cmaps && vi->visual->c_class == TrueColor && vi->depth == 8) {
226 if (XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
229 while (i < n && x->
cmap == 0) {
230 if (c[i].visualid == vi->visual->visualid) {
231 x->
cmap = c[i].colormap;
243 if (XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
244 XA_RGB_DEFAULT_MAP)) {
245 for (
int i = 0; i < n && x->
cmap == 0; ++i) {
253 if (c[i].visualid == vi->visualid) {
254 x->
cmap = c[i].colormap;
263 x->
cmap = XCreateColormap(dpy, RootWindow(dpy,vi->screen), vi->visual,
274 hash->
insert((
long) vi->visualid + (vi->screen * 256), x);
303 for (scr = 0; scr < ScreenCount(appDisplay); scr++) {
307 Atom overlayVisualsAtom = XInternAtom(appDisplay,
308 "SERVER_OVERLAY_VISUALS", True);
309 if (overlayVisualsAtom ==
XNone)
316 unsigned char *retval = 0;
317 int res = XGetWindowProperty(appDisplay, rootWin->
winId(),
318 overlayVisualsAtom, 0, 10000, False,
319 overlayVisualsAtom, &actualType,
320 &actualFormat, &nItems, &bytesAfter,
323 if (res !=
Success || actualType != overlayVisualsAtom
324 || actualFormat != 32 || nItems < 4 || !retval)
327 OverlayProp *overlayProps = (OverlayProp *)retval;
329 int numProps = nItems / 4;
330 trans_colors.
resize(lastsize + numProps);
332 for (
int i = 0; i < numProps; i++) {
333 if (overlayProps[i].
type == 1) {
334 trans_colors[j].vis = (VisualID)overlayProps[i].visual;
335 trans_colors[j].screen = scr;
336 trans_colors[j].color = (int)overlayProps[i].value;
342 trans_colors.
resize(lastsize);
356 typedef void* (*qt_glXGetProcAddressARB)(
const char *);
357 static qt_glXGetProcAddressARB glXGetProcAddressARB = 0;
358 static bool triedResolvingGlxGetProcAddress =
false;
359 if (!triedResolvingGlxGetProcAddress) {
360 triedResolvingGlxGetProcAddress =
true;
362 if (extensions.
match(
"GLX_ARB_get_proc_address")) {
363 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) 364 void *handle = dlopen(NULL, RTLD_LAZY);
366 glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle,
"glXGetProcAddressARB");
369 if (!glXGetProcAddressARB)
372 #if !defined(QT_NO_LIBRARY) 376 glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.
resolve(
"glXGetProcAddressARB");
382 void *procAddress = 0;
383 if (glXGetProcAddressARB)
384 procAddress = glXGetProcAddressARB(procName);
387 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) 389 void *handle = dlopen(NULL, RTLD_LAZY);
391 procAddress = dlsym(handle, procName);
396 #if !defined(QT_NO_LIBRARY) 401 procAddress = lib.
resolve(procName);
410 return glXQueryExtension(
X11->display, 0, 0) != 0;
418 return trans_colors.
size() > 0;
422 int bufDepth,
bool onlyFBConfig =
false)
425 spec[i++] = GLX_LEVEL;
426 spec[i++] = f.
plane();
428 bool useFBConfig = onlyFBConfig;
430 #if defined(GLX_VERSION_1_3) && !defined(QT_NO_XRENDER) && !defined(Q_OS_HPUX) 437 widget = static_cast<QWidget*>(paintDevice);
444 #if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_info) 445 static bool useTranspExt =
false;
446 static bool useTranspExtChecked =
false;
447 if (f.
plane() && !useTranspExtChecked && paintDevice) {
449 useTranspExt = extensions.
match(
"GLX_EXT_visual_info");
453 useTranspExt = !cstr.
contains(
"Xi Graphics");
458 int tmpSpec[] = { GLX_LEVEL, f.
plane(), GLX_TRANSPARENT_TYPE_EXT,
459 f.
rgba() ? GLX_TRANSPARENT_RGB_EXT : GLX_TRANSPARENT_INDEX_EXT,
461 XVisualInfo * vinf = glXChooseVisual(xinfo->
display(), xinfo->
screen(), tmpSpec);
463 useTranspExt =
false;
468 useTranspExtChecked =
true;
470 if (f.
plane() && useTranspExt && !useFBConfig) {
472 spec[i++] = GLX_TRANSPARENT_TYPE_EXT;
473 spec[i++] = f.
rgba() ? GLX_TRANSPARENT_RGB_EXT : GLX_TRANSPARENT_INDEX_EXT;
477 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) 486 spec[i++] = GLX_DOUBLEBUFFER;
490 spec[i++] = GLX_DEPTH_SIZE;
494 spec[i++] = GLX_STEREO;
499 spec[i++] = GLX_STENCIL_SIZE;
504 spec[i++] = GLX_RGBA;
505 spec[i++] = GLX_RED_SIZE;
507 spec[i++] = GLX_GREEN_SIZE;
509 spec[i++] = GLX_BLUE_SIZE;
512 spec[i++] = GLX_ALPHA_SIZE;
516 spec[i++] = GLX_ACCUM_RED_SIZE;
518 spec[i++] = GLX_ACCUM_GREEN_SIZE;
520 spec[i++] = GLX_ACCUM_BLUE_SIZE;
523 spec[i++] = GLX_ACCUM_ALPHA_SIZE;
528 spec[i++] = GLX_BUFFER_SIZE;
529 spec[i++] = bufDepth;
539 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) 542 switch(paintDevice->
devType()) {
544 spec[i++] = GLX_PIXMAP_BIT;
550 qWarning(
"QGLContext: Unknown paint device type %d", paintDevice->
devType());
553 spec[i++] = GLX_WINDOW_BIT;
573 d->vi = chooseVisual();
577 if (deviceIsPixmap() &&
578 (((XVisualInfo*)
d->vi)->depth != xinfo->
depth() ||
579 ((XVisualInfo*)
d->vi)->screen != xinfo->
screen()))
582 XVisualInfo appVisInfo;
583 memset(&appVisInfo, 0,
sizeof(XVisualInfo));
584 appVisInfo.visualid = XVisualIDFromVisual((Visual *) xinfo->
visual());
585 appVisInfo.screen = xinfo->
screen();
587 d->vi = XGetVisualInfo(disp, VisualIDMask | VisualScreenMask, &appVisInfo, &nvis);
592 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_USE_GL, &useGL);
597 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_LEVEL, &res);
598 d->glFormat.setPlane(res);
599 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_DOUBLEBUFFER, &res);
600 d->glFormat.setDoubleBuffer(res);
601 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_DEPTH_SIZE, &res);
602 d->glFormat.setDepth(res);
603 if (
d->glFormat.depth())
604 d->glFormat.setDepthBufferSize(res);
605 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_RGBA, &res);
606 d->glFormat.setRgba(res);
607 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_RED_SIZE, &res);
608 d->glFormat.setRedBufferSize(res);
609 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_GREEN_SIZE, &res);
610 d->glFormat.setGreenBufferSize(res);
611 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_BLUE_SIZE, &res);
612 d->glFormat.setBlueBufferSize(res);
613 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_ALPHA_SIZE, &res);
614 d->glFormat.setAlpha(res);
615 if (
d->glFormat.alpha())
616 d->glFormat.setAlphaBufferSize(res);
617 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_ACCUM_RED_SIZE, &res);
618 d->glFormat.setAccum(res);
619 if (
d->glFormat.accum())
620 d->glFormat.setAccumBufferSize(res);
621 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_STENCIL_SIZE, &res);
622 d->glFormat.setStencil(res);
623 if (
d->glFormat.stencil())
624 d->glFormat.setStencilBufferSize(res);
625 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_STEREO, &res);
626 d->glFormat.setStereo(res);
628 d->glFormat.setSampleBuffers(res);
629 if (
d->glFormat.sampleBuffers()) {
631 d->glFormat.setSamples(res);
634 Bool direct =
format().directRendering() ? True : False;
637 (!shareContext->
isValid() || !shareContext->d_func()->cx)) {
638 qWarning(
"QGLContext::chooseContext(): Cannot share with invalid context");
649 || (deviceIsPixmap() && glXIsDirect(disp, (GLXContext)shareContext->d_func()->cx))
650 || (shareContext->d_func()->screen != xinfo->
screen())))
655 const int major =
d->reqFormat.majorVersion();
656 const int minor =
d->reqFormat.minorVersion();
663 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) 668 if ((major == 3 && minor >= 2) || major > 3) {
678 typedef GLXContext ( * Q_PFNGLXCREATECONTEXTATTRIBSARBPROC)
679 (
Display* dpy, GLXFBConfig config, GLXContext share_context, Bool direct,
const int *attrib_list);
682 Q_PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs =
685 if (glXCreateContextAttribs) {
687 glXGetConfig(disp, (XVisualInfo*)
d->vi, GLX_BUFFER_SIZE, &res);
690 GLXFBConfig *configs;
694 if (configs && configCount > 0) {
695 d->cx = glXCreateContextAttribs(disp, configs[0],
696 shareContext ? (GLXContext)shareContext->d_func()->cx : 0, direct, attributes);
697 if (!
d->cx && shareContext) {
699 d->cx = glXCreateContextAttribs(disp, configs[0], 0, direct, attributes);
701 d->screen = ((XVisualInfo*)
d->vi)->screen;
705 qWarning(
"QGLContext::chooseContext(): OpenGL %d.%d is not supported", major, minor);
717 if (!
d->cx && shareContext) {
718 d->cx = glXCreateContext(disp, (XVisualInfo *)
d->vi,
719 (GLXContext)shareContext->d_func()->cx, direct);
720 d->screen = ((XVisualInfo*)
d->vi)->screen;
723 d->cx = glXCreateContext(disp, (XVisualInfo *)
d->vi, NULL, direct);
724 d->screen = ((XVisualInfo*)
d->vi)->screen;
728 if (shareContext &&
d->cx) {
731 share->d_func()->sharing =
true;
736 d->glFormat.setDirectRendering(glXIsDirect(disp, (GLXContext)
d->cx));
737 if (deviceIsPixmap()) {
738 #if defined(GLX_MESA_pixmap_colormap) && defined(QGL_USE_MESA_EXT) 739 d->gpm = glXCreateGLXPixmapMESA(disp, (XVisualInfo *)
d->vi,
743 d->gpm = (
quint32)glXCreateGLXPixmap(disp, (XVisualInfo *)
d->vi,
750 if (extensions.
match(
"GLX_SGI_video_sync")) {
751 if (
d->glFormat.swapInterval() == -1)
752 d->glFormat.setSwapInterval(0);
754 d->glFormat.setSwapInterval(-1);
765 static const int bufDepths[] = { 8, 4, 2, 1 };
772 bool triedDouble =
false;
773 bool triedSample =
false;
776 while(!fail && !(vis = tryVisual(fmt, bufDepths[i]))) {
777 if (!fmt.
rgba() && bufDepths[i] > 1) {
786 }
else if (triedDouble) {
833 bool useFBConfig =
buildSpec(spec, f,
d->paintDevice, bufDepth,
false);
835 XVisualInfo* chosenVisualInfo = 0;
837 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) 838 while (useFBConfig) {
839 GLXFBConfig *configs;
846 for (
int i = 0; i < configCount; ++i) {
848 vi = glXGetVisualFromFBConfig(xinfo->
display(), configs[i]);
852 #if !defined(QT_NO_XRENDER) 855 w = static_cast<QWidget*>(
d->paintDevice);
859 XRenderPictFormat *pictFormat;
860 pictFormat = XRenderFindVisualFormat(xinfo->
display(), vi->visual);
862 if (pictFormat && (pictFormat->type == PictTypeDirect) && pictFormat->direct.alphaMask) {
864 if (chosenVisualInfo)
865 XFree(chosenVisualInfo);
866 chosenVisualInfo = vi;
870 #endif //QT_NO_XRENDER 871 if (chosenVisualInfo) {
877 if (!chosenVisualInfo)
878 chosenVisualInfo = vi;
886 #endif // defined(GLX_VERSION_1_3) 888 if (!chosenVisualInfo)
889 chosenVisualInfo = glXChooseVisual(xinfo->
display(), xinfo->
screen(), spec);
891 return chosenVisualInfo;
904 glXDestroyGLXPixmap(xinfo->
display(), (GLXPixmap)
d->gpm);
906 glXDestroyContext(xinfo->
display(), (GLXContext)
d->cx);
924 qWarning(
"QGLContext::makeCurrent(): Cannot make invalid context current.");
930 ok = glXMakeCurrent(xinfo->
display(), (GLXPixmap)
d->gpm, (GLXContext)
d->cx);
932 ok = glXMakeCurrent(xinfo->
display(), (GLXPbuffer)
d->pbuf, (GLXContext)
d->cx);
934 ok = glXMakeCurrent(xinfo->
display(), ((
QWidget *)
d->paintDevice)->internalWinId(), (GLXContext)
d->cx);
937 qWarning(
"QGLContext::makeCurrent(): Failed.");
956 if (!deviceIsPixmap()) {
957 int interval =
d->glFormat.swapInterval();
959 typedef int (*qt_glXGetVideoSyncSGI)(
uint *);
960 typedef int (*qt_glXWaitVideoSyncSGI)(int, int,
uint *);
961 static qt_glXGetVideoSyncSGI glXGetVideoSyncSGI = 0;
962 static qt_glXWaitVideoSyncSGI glXWaitVideoSyncSGI = 0;
963 static bool resolved =
false;
967 if (extensions.
match(
"GLX_SGI_video_sync")) {
973 if (glXGetVideoSyncSGI && glXWaitVideoSyncSGI) {
975 if (!glXGetVideoSyncSGI(&counter))
976 glXWaitVideoSyncSGI(interval + 1, (counter + interval) % (interval + 1), &counter);
980 static_cast<QWidget *
>(
d->paintDevice)->winId());
993 for (
int i = 0; i < trans_colors.
size(); i++) {
994 if (trans_colors[i].vis ==
id && trans_colors[i].screen == screen)
995 return trans_colors[i].color;
1003 int screen = ((XVisualInfo *)
d->vi)->screen;
1008 ((XVisualInfo *)
d->vi)->screen);
1010 if (((XVisualInfo*)
d->vi)->visualid ==
1012 return colmap.
pixel(c);
1014 XVisualInfo *
info = (XVisualInfo *)
d->vi;
1017 + (info->screen * 256));
1019 if (it !=
hash->constEnd())
1021 if (x && !x->
alloc) {
1022 int rf = (int)(((
float)c.
red() * (x->
scmap.red_max+1))/256.0);
1023 int gf = (int)(((
float)c.
green() * (x->
scmap.green_max+1))/256.0);
1024 int bf = (int)(((
float)c.
blue() * (x->
scmap.blue_max+1))/256.0);
1026 + (rf * x->
scmap.red_mult)
1027 + (gf * x->
scmap.green_mult)
1028 + (bf * x->
scmap.blue_mult);
1036 for (; it != cmap.
end(); ++
it) {
1037 if ((*it) == target)
1042 unsigned long plane_mask[2];
1043 unsigned long color_map_entry;
1045 &color_map_entry, 1))
1046 return colmap.
pixel(c);
1049 col.flags = DoRed | DoGreen | DoBlue;
1050 col.pixel = color_map_entry;
1051 col.red = (
ushort)((
qRed(c.
rgb()) / 255.0) * 65535.0 + 0.5);
1056 cmap.
insert(color_map_entry, target);
1057 return color_map_entry;
1063 #ifndef QT_NO_FONTCONFIG 1076 glGetFloatv(GL_CURRENT_COLOR, color);
1079 GLint gl_swapbytes, gl_lsbfirst, gl_rowlength, gl_skiprows, gl_skippixels, gl_alignment;
1080 glGetIntegerv (GL_UNPACK_SWAP_BYTES, &gl_swapbytes);
1081 glGetIntegerv (GL_UNPACK_LSB_FIRST, &gl_lsbfirst);
1082 glGetIntegerv (GL_UNPACK_ROW_LENGTH, &gl_rowlength);
1083 glGetIntegerv (GL_UNPACK_SKIP_ROWS, &gl_skiprows);
1084 glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &gl_skippixels);
1087 glPixelStorei(GL_UNPACK_SWAP_BYTES,
GL_FALSE);
1088 glPixelStorei(GL_UNPACK_LSB_FIRST,
GL_FALSE);
1089 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1090 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
1091 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
1098 for (
int i = first; i < count; ++i) {
1099 int list = listBase + i;
1100 GLfloat x0, y0, dx, dy;
1104 err = FT_Load_Glyph(face, FT_Get_Char_Index(face, i), FT_LOAD_DEFAULT);
1106 qDebug(
"failed loading glyph %d from font", i);
1109 err = FT_Render_Glyph(face->glyph, (antialiased ? FT_RENDER_MODE_NORMAL
1110 : FT_RENDER_MODE_MONO));
1112 qDebug(
"failed rendering glyph %d from font", i);
1116 FT_Bitmap bm = face->glyph->bitmap;
1117 x0 = face->glyph->metrics.horiBearingX >> 6;
1118 y0 = (face->glyph->metrics.height - face->glyph->metrics.horiBearingY) >> 6;
1119 dx = face->glyph->metrics.horiAdvance >> 6;
1121 int sz = bm.pitch * bm.rows;
1123 uchar *ua_glyph = 0;
1126 aa_glyph =
new uint[sz];
1128 ua_glyph =
new uchar[sz];
1131 for (
int y = 0; y < bm.rows; ++y) {
1132 for (
int x = 0; x < bm.pitch; ++x) {
1133 int c1 = y*bm.pitch + x;
1134 int c2 = (bm.rows - y - 1) > 0 ? (bm.rows-y-1)*bm.pitch + x : x;
1136 aa_glyph[c1] = (int(color[0]*255) << 24)
1137 | (
int(color[1]*255) << 16)
1138 | (
int(color[2]*255) << 8) | bm.buffer[c2];
1140 ua_glyph[c1] = bm.buffer[c2];
1145 glNewList(list, GL_COMPILE);
1149 glBitmap(0, 0, 0, 0, x0, -y0, 0);
1150 glDrawPixels(bm.pitch, bm.rows,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, aa_glyph);
1151 glBitmap(0, 0, 0, 0, dx-x0, y0, 0);
1153 glBitmap(bm.pitch*8, bm.rows, -x0, y0, dx, dy, ua_glyph);
1156 antialiased ?
delete[] aa_glyph :
delete[] ua_glyph;
1162 glPixelStorei(GL_UNPACK_SWAP_BYTES, gl_swapbytes);
1163 glPixelStorei(GL_UNPACK_LSB_FIRST, gl_lsbfirst);
1164 glPixelStorei(GL_UNPACK_ROW_LENGTH, gl_rowlength);
1165 glPixelStorei(GL_UNPACK_SKIP_ROWS, gl_skiprows);
1166 glPixelStorei(GL_UNPACK_SKIP_PIXELS, gl_skippixels);
1178 engine = static_cast<QFontEngineMulti *>(engine)->engine(0);
1179 #ifndef QT_NO_FONTCONFIG 1181 qgl_use_font(static_cast<QFontEngineFT *>(engine), 0, 256, listBase);
1189 glXUseXFont(static_cast<Font>(f.
handle()), 0, 256, listBase);
1194 typedef void *(*qt_glXGetProcAddressARB)(
const GLubyte *);
1195 static qt_glXGetProcAddressARB glXGetProcAddressARB = 0;
1196 static bool resolved =
false;
1198 if (resolved && !glXGetProcAddressARB)
1200 if (!glXGetProcAddressARB) {
1202 if (extensions.
match(
"GLX_ARB_get_proc_address")) {
1203 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) 1204 void *handle = dlopen(NULL, RTLD_LAZY);
1206 glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle,
"glXGetProcAddressARB");
1209 if (!glXGetProcAddressARB)
1212 #if !defined(QT_NO_LIBRARY) 1216 glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.
resolve(
"glXGetProcAddressARB");
1222 if (!glXGetProcAddressARB)
1224 return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(proc.
toLatin1().
data()));
1243 d->initialized =
false;
1248 int attribs[] = {GLX_RGBA,
XNone};
1249 XVisualInfo *vi = glXChooseVisual(
X11->display, screen, attribs);
1251 qWarning(
"QGLTempContext: No GL capable X visuals available.");
1256 glXGetConfig(
X11->display, vi, GLX_USE_GL, &useGL);
1262 d->oldDrawable = glXGetCurrentDrawable();
1263 d->oldContext = glXGetCurrentContext();
1265 XSetWindowAttributes
a;
1267 d->drawable = XCreateWindow(
X11->display, RootWindow(
X11->display, screen),
1269 vi->depth, InputOutput, vi->visual,
1271 d->context = glXCreateContext(
X11->display, vi, 0, True);
1272 if (
d->context && glXMakeCurrent(
X11->display,
d->drawable,
d->context)) {
1273 d->initialized =
true;
1275 qWarning(
"QGLTempContext: Unable to create GL context.");
1276 XDestroyWindow(
X11->display,
d->drawable);
1283 if (
d->initialized) {
1284 glXMakeCurrent(
X11->display, 0, 0);
1285 glXDestroyContext(
X11->display,
d->context);
1286 XDestroyWindow(
X11->display,
d->drawable);
1288 if (
d->oldDrawable &&
d->oldContext)
1289 glXMakeCurrent(
X11->display,
d->oldDrawable,
d->oldContext);
1303 void initializeGL();
1305 void resizeGL(
int w,
int h);
1318 :
QGLWidget(format, parent, shareWidget ? shareWidget->d_func()->olw : 0)
1329 if (transparentColor.
isValid())
1332 qWarning(
"QGLOverlayWidget::initializeGL(): Could not get transparent color");
1339 glViewport(0, 0, w, h);
1351 #include "qgl_x11.moc" 1360 initContext(context, shareWidget);
1364 QString olwName = q->objectName();
1367 olw->setObjectName(olwName);
1368 if (olw->isValid()) {
1369 olw->setAutoBufferSwap(
false);
1370 olw->setFocusProxy(q);
1375 glcx->d_func()->glFormat.setOverlay(
false);
1383 if (((XVisualInfo*)glcx->d_func()->vi)->
depth != pm->
depth())
1387 #if defined(GLX_MESA_pixmap_colormap) && defined(QGL_USE_MESA_EXT) 1388 glPm = glXCreateGLXPixmapMESA(
X11->display,
1389 (XVisualInfo*)glcx->vi,
1392 (XVisualInfo*)glcx->vi));
1394 glPm = (
quint32)glXCreateGLXPixmap(
X11->display,
1395 (XVisualInfo*)glcx->d_func()->vi,
1399 if (!glXMakeCurrent(
X11->display, glPm, (GLXContext)glcx->d_func()->cx)) {
1400 glXDestroyGLXPixmap(
X11->display, glPm);
1405 if (!glcx->initialized())
1411 glXDestroyGLXPixmap(
X11->display, glPm);
1412 q->resizeGL(q->width(), q->height());
1418 if (!
cmap.handle()) {
1421 XFreeColormap(
X11->display, (Colormap)
cmap.handle());
1430 d->olw->setMouseTracking(enable);
1441 if (!
d->glcx->initialized())
1446 d->olw->setGeometry(
rect());
1453 return d->olw->context();
1463 d->olw->makeCurrent();
1486 bool deleteOldContext)
1490 qWarning(
"QGLWidget::setContext: Cannot set null context");
1494 qWarning(
"QGLWidget::setContext: Context must refer to this widget");
1499 d->glcx->doneCurrent();
1512 QGLFormat& fmt =
d->glcx->d_func()->glFormat;
1516 bool createFailed =
false;
1517 if (!
d->glcx->isValid()) {
1518 if (!
d->glcx->create(shareContext ? shareContext : oldcx))
1519 createFailed =
true;
1522 if (deleteOldContext)
1527 if (
d->glcx->windowCreated() ||
d->glcx->deviceIsPixmap()) {
1528 if (deleteOldContext)
1537 XVisualInfo *vi = (XVisualInfo*)
d->glcx->d_func()->vi;
1538 XSetWindowAttributes
a;
1544 Window p = RootWindow(
X11->display, vi->screen);
1549 0, vi->depth, InputOutput, vi->visual,
1550 CWBackPixel|CWBorderPixel|CWColormap, &a);
1556 cmw =
new Window[count+1];
1557 memcpy((
char *)cmw, (
char *)cmwret,
sizeof(
Window)*count);
1558 XFree((
char *)cmwret);
1560 for (i=0; i<count; i++) {
1561 if (cmw[i] ==
winId()) {
1574 #if defined(GLX_MESA_release_buffers) && defined(QGL_USE_MESA_EXT) 1576 glXReleaseBuffersMESA(
X11->display,
winId());
1578 if (deleteOldContext)
1586 XSetWMColormapWindows(
X11->display,
window()->
winId(), cmw, count);
1595 XFlush(
X11->display);
1596 d->glcx->setWindowCreated(
true);
1615 for (
int i = 0; i < cols.
size(); i++) {
1618 c.red = (
ushort)((
qRed(color) / 255.0) * 65535.0 + 0.5);
1619 c.green = (
ushort)((
qGreen(color) / 255.0) * 65535.0 + 0.5);
1620 c.blue = (
ushort)((
qBlue(color) / 255.0) * 65535.0 + 0.5);
1621 c.flags = DoRed | DoGreen | DoBlue;
1622 XStoreColor(
X11->display, cmap, &c);
1631 bool validVisual =
false;
1635 XVisualInfo * visuals;
1638 mask = VisualScreenMask;
1640 visuals = XGetVisualInfo(
X11->display, mask, &templ, &numVisuals);
1642 for (
int i = 0; i < numVisuals; i++) {
1643 if (visuals[i].visualid ==
id) {
1644 switch (visuals[i].c_class) {
1649 validVisual =
false;
1673 if (!
d->cmap.handle())
1677 qWarning(
"QGLWidget::setColormap: Cannot create a read/write " 1678 "colormap for this visual");
1686 VisualID cvId = XVisualIDFromVisual((Visual *)
x11Info().visual());
1687 VisualID tvId = XVisualIDFromVisual((Visual *) tlw->
x11Info().
visual());
1693 if (!
d->cmap.handle())
1694 d->cmap.setHandle(XCreateColormap(
X11->display, wid, vis, AllocAll));
1697 XSetWindowColormap(
X11->display, wid, (Colormap)
d->cmap.handle());
1703 if (XGetWMColormapWindows(
X11->display, tlw->
winId(), &cmwret, &count))
1705 cmw =
new Window[count+1];
1706 memcpy((
char *) cmw, (
char *) cmwret,
sizeof(
Window) * count);
1707 XFree((
char *) cmwret);
1709 for (i = 0; i < count; i++) {
1710 if (cmw[i] ==
winId()) {
1715 cmw[count++] =
winId();
1721 XSetWMColormapWindows(
X11->display, tlw->
winId(), cmw, count);
1726 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) 1727 typedef void (*qt_glXBindTexImageEXT)(
Display*, GLXDrawable, int,
const int*);
1728 typedef void (*qt_glXReleaseTexImageEXT)(
Display*, GLXDrawable, int);
1729 static qt_glXBindTexImageEXT glXBindTexImageEXT = 0;
1730 static qt_glXReleaseTexImageEXT glXReleaseTexImageEXT = 0;
1732 static bool qt_resolveTextureFromPixmap(
QPaintDevice *paintDevice)
1734 static bool resolvedTextureFromPixmap =
false;
1736 if (!resolvedTextureFromPixmap) {
1737 resolvedTextureFromPixmap =
true;
1748 int screen = xinfo ? xinfo->
screen() :
X11->defaultScreen;
1752 if (serverExtensions.
match(
"GLX_EXT_texture_from_pixmap")
1753 && clientExtensions.
match(
"GLX_EXT_texture_from_pixmap"))
1756 glXReleaseTexImageEXT = (qt_glXReleaseTexImageEXT)
qglx_getProcAddress(
"glXReleaseTexImageEXT");
1760 return glXBindTexImageEXT && glXReleaseTexImageEXT;
1762 #endif //defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) 1766 QGLContext::BindOptions options)
1768 #if !defined(GLX_VERSION_1_3) || defined(Q_OS_HPUX) 1773 int majorVersion = 0;
1774 int minorVersion = 0;
1775 glXQueryVersion(
X11->display, &majorVersion, &minorVersion);
1776 if (majorVersion < 1 || (majorVersion == 1 && minorVersion < 3))
1788 if (!qt_resolveTextureFromPixmap(paintDevice))
1794 static GLXFBConfig glxRGBPixmapConfig = 0;
1795 static bool RGBConfigInverted =
false;
1796 static GLXFBConfig glxRGBAPixmapConfig = 0;
1797 static bool RGBAConfigInverted =
false;
1802 if ( (hasAlpha && !glxRGBAPixmapConfig) || (!hasAlpha && !glxRGBPixmapConfig) ) {
1803 GLXFBConfig *configList = 0;
1804 int configCount = 0;
1806 int configAttribs[] = {
1822 glxRGBAPixmapConfig = configList[0];
1823 RGBAConfigInverted = yInv;
1826 glxRGBPixmapConfig = configList[0];
1827 RGBConfigInverted = yInv;
1838 destroyGlSurfaceForPixmap(pixmapData);
1843 GLXPixmap glxPixmap;
1844 int pixmapAttribs[] = {
1852 glxPixmap = glXCreatePixmap(x11Info.
display(),
1853 hasAlpha ? glxRGBAPixmapConfig : glxRGBPixmapConfig,
1854 pixmapData->
handle(), pixmapAttribs);
1866 glGenTextures(1, &textureId);
1875 if (!((hasAlpha && RGBAConfigInverted) || (!hasAlpha && RGBConfigInverted)))
1892 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) 1895 if (pixmapData->gl_surface) {
1897 pixmapData->gl_surface = 0;
1904 #if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX) The QColor class provides colors based on RGB, HSV or CMYK values.
static uint hash(const uchar *p, int n)
int depth() const
Returns the color depth (bits per pixel) of the X display.
virtual void swapBuffers() const
Swaps the screen contents with an off-screen buffer.
GLCMapHash * qglcmap_hash
const Key & key() const
Returns the current item's key as a const reference.
void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost)
static QColormap instance(int screen=-1)
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
#define GL_TEXTURE_MIN_FILTER
static mach_timebase_info_data_t info
#define QT_END_NAMESPACE
This macro expands to.
int width() const
Returns the width of the pixmap.
QPointer< QWidget > widget
void clear()
Removes all items from the hash.
char * data()
Returns a pointer to the data stored in the byte array.
Drawable qt_x11Handle(const QPaintDevice *pd)
Returns the X11 Drawable of the paint device.
#define GLX_FRONT_LEFT_EXT
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB
static void setCurrentContext(QGLContext *context)
#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
#define GLX_CONTEXT_PROFILE_MASK_ARB
#define it(className, varName)
static QGLTextureCache * instance()
void qAddPostRoutine(QtCleanUpFunction p)
int size() const
Returns the number of colorcells in the colormap.
#define GLX_TEXTURE_TARGET_EXT
The QByteArray class provides an array of bytes.
static QVector< QTransColor > trans_colors
#define GLX_TEXTURE_2D_EXT
#define glXGetFBConfigAttrib
QColor overlayTransparentColor() const
If this context is a valid context in an overlay plane, returns the plane's transparent color...
virtual void * tryVisual(const QGLFormat &f, int bufDepth=1)
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Qt::HANDLE handle() const
Returns the pixmap's handle to the device context.
CMapEntryHash * cmap_hash
void * getProcAddress(const QString &proc) const
Returns a function pointer to the GL extension function passed in proc.
static void enableCleanupHooks(const QImage &image)
long ASN1_INTEGER_get ASN1_INTEGER * a
void * resolve(const char *symbol)
Returns the address of the exported symbol symbol.
int depth() const
Returns the depth of the pixmap.
ushort red
Returns the red color component of this color.
The QString class provides a Unicode character string.
The QHash class is a template class that provides a hash-table-based dictionary.
HFONT handle() const
Returns the window system handle to the font, for low-level access.
static void removeShare(const QGLContext *context)
The QVector class is a template class that provides a dynamic array.
Q_GUI_EXPORT QString extensions()
#define glXChooseFBConfig
static void cleanup_cmaps()
virtual Type type() const =0
virtual int devType() const
QGLContext::BindOptions options
#define GLX_BIND_TO_TEXTURE_RGB_EXT
void setStyleStrategy(StyleStrategy s)
Sets the style strategy for the font to s.
static void find_trans_colors()
#define GLX_SAMPLE_BUFFERS_ARB
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
void resize(int size)
Sets the size of the vector to size.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
static const QGLContext * currentContext()
Returns the current context, i.e.
QGLTexture * bindTextureFromNativePixmap(QPixmap *, const qint64 key, QGLContext::BindOptions options)
static int trans_colors_init
static void qStoreColors(QWidget *tlw, Colormap cmap, const QGLColormap &cols)
QHash< int, QMap< int, QRgb > > GLCMapHash
Q_CORE_EXPORT void qDebug(const char *,...)
#define GLX_BIND_TO_TEXTURE_TARGETS_EXT
T * data() const
Returns a pointer to the shared data object.
Q_OPENGL_EXPORT const QString qt_gl_library_name()
const Q_GUI_EXPORT QX11Info * qt_x11Info(const QPaintDevice *pd)
Returns the QX11Info structure for the pd paint device.
#define QT_BEGIN_NAMESPACE
This macro expands to.
#define GLX_DRAWABLE_TYPE
Q_GUI_EXPORT EGLDisplay display()
struct FT_FaceRec_ * FT_Face
void generateFontDisplayLists(const QFont &fnt, int listBase)
Generates a set of 256 display lists for the 256 first characters in the font font.
QGLFormat format() const
Returns the frame buffer format that was obtained (this may be a subset of what was requested)...
Qt::HANDLE handle() const
The QGLContext class encapsulates an OpenGL rendering context.
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
#define GLX_TEXTURE_FORMAT_RGB_EXT
#define GLX_CONTEXT_MAJOR_VERSION_ARB
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
The QResizeEvent class contains event parameters for resize events.
const T & value() const
Returns the current item's value.
Q_CORE_EXPORT void qWarning(const char *,...)
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
QPaintDevice * device() const
Returns the paint device set for this context.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
bool deviceIsPixmap() const
Returns true if the paint device of this context is a pixmap; otherwise returns false.
void * visual() const
Returns the current visual.
static Qt::HANDLE appColormap(int screen=-1)
Returns a handle for the application's color map on the given screen.
static void destroyGlSurfaceForPixmap(QPixmapData *)
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
The QGLColormap class is used for installing custom colormaps into a QGLWidget.
uint pixel(const QColor &color) const
QHash< int, QCMapEntry * > CMapEntryHash
#define GL_UNPACK_ALIGNMENT
QFontEngine * engineForScript(int script) const
virtual void * chooseVisual()
X11 only: This virtual function tries to find a visual that matches the format, reducing the demands ...
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
QRgb entryRgb(int idx) const
Returns the QRgb value in the colorcell with index idx.
#define GLX_Y_INVERTED_EXT
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
static void qgl_use_font(QFontEngineFT *engine, int first, int count, int listBase)
This is basically a substitute for glxUseXFont() which can only handle XLFD fonts.
bool windowCreated() const
Returns true if a window has been created for this context; otherwise returns false.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
void reset()
Resets the context and makes it invalid.
virtual bool chooseContext(const QGLContext *shareContext=0)
This semi-internal function is called by create().
The QX11Info class provides information about the X display configuration.
ushort blue
Returns the blue color component of this color.
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
bool isValid() const
Returns true if a GL rendering context has been successfully created; otherwise returns false...
The QFont class specifies a font used for drawing text.
bool hasAlphaChannel() const
static void * appVisual(int screen=-1)
Returns the current visual used by the application on the given screen.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
static uint qt_transparent_pixel(VisualID id, int screen)
#define GLX_MIPMAP_TEXTURE_EXT
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
static bool qCanAllocColors(QWidget *w)
QObject * parent() const
Returns a pointer to the parent object.
virtual void doneCurrent()
Makes no GL context the current context.
void * qglx_getProcAddress(const char *procName)
QExplicitlySharedDataPointer< QFontPrivate > d
FT_Face lockFace(Scaling scale=Scaled) const
virtual void makeCurrent()
Makes this context the current OpenGL rendering context.
bool match(const char *str) const
QGLTemporaryContext(bool directRendering=true, QWidget *parent=0)
static Extensions glExtensions()
void setLoadHints(LoadHints hints)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
#define GLX_TEXTURE_FORMAT_EXT
uint colorIndex(const QColor &c) const
Returns a colormap index for the color c, in ColorIndex mode.
int height() const
Returns the height of the pixmap.
#define GLX_CONTEXT_MINOR_VERSION_ARB
bool isValid() const
Returns true if the color is valid; otherwise returns false.
#define GLX_TEXTURE_2D_BIT_EXT
#define GL_TEXTURE_MAG_FILTER
static void unbindPixmapFromTexture(QPixmapData *)
#define GLX_BIND_TO_TEXTURE_RGBA_EXT
const QX11Info * qt_x11Info(const QPaintDevice *pd)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
ushort green
Returns the green color component of this color.
int size() const
Returns the number of items in the vector.
bool drawAntialiased() const
QRgb rgb() const
Returns the RGB value of the color.
Colormap qt_gl_choose_cmap(Display *dpy, XVisualInfo *vi)
static Display * display()
Returns the default display for the application.
The QMap class is a template class that provides a skip-list-based dictionary.
int screen() const
Returns the number of the screen currently in use.
static bool buildSpec(int *spec, const QGLFormat &f, QPaintDevice *paintDevice, int bufDepth, bool onlyFBConfig=false)
The QLibrary class loads shared libraries at runtime.
#define GLX_TEXTURE_FORMAT_RGBA_EXT
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.