#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
+#include <sys/time.h> /* for gettimeofday */
#include <linux/kd.h>
#include <linux/vt.h>
#include "glcontextmodes.h"
#include "glapi.h"
+#include "pciaccess.h"
-extern GLboolean __glXCreateContextWithConfig(__DRInativeDisplay *dpy,
+static GLboolean __glXCreateContextWithConfig(__DRInativeDisplay *dpy,
int screen, int fbconfigID, void *contextID,
drm_context_t *hHWContext);
-extern GLboolean __glXGetDrawableInfo(__DRInativeDisplay *dpy, int scrn,
+static GLboolean __glXGetDrawableInfo(__DRInativeDisplay *dpy, int scrn,
__DRIid draw, unsigned int * index, unsigned int * stamp,
int * x, int * y, int * width, int * height,
int * numClipRects, drm_clip_rect_t ** pClipRects,
int * backX, int * backY,
int * numBackClipRects, drm_clip_rect_t ** pBackClipRects);
+static __DRIscreen * __glXFindDRIScreen(__DRInativeDisplay *dpy, int scrn);
+
+static GLboolean __glXWindowExists(__DRInativeDisplay *dpy, __DRIid draw);
+
+static int __glXGetUST( int64_t * ust );
+
+static GLboolean __glXGetMscRate(__DRInativeDisplay * dpy, __DRIid drawable,
+ int32_t * numerator, int32_t * denominator);
+
+static GLboolean xf86DRI_DestroyContext(__DRInativeDisplay *dpy, int screen,
+ __DRIid context_id );
+
+static GLboolean xf86DRI_CreateDrawable(__DRInativeDisplay *dpy, int screen,
+ __DRIid drawable, drm_drawable_t *hHWDrawable );
+
+static GLboolean xf86DRI_DestroyDrawable(__DRInativeDisplay *dpy, int screen,
+ __DRIid drawable);
+
/** Wrapper around either malloc() */
void *
width = dpy->driverContext.shared.virtualWidth;
height = dpy->driverContext.shared.virtualHeight;
+ if (width==832)
+ width=800;
+#if 0
/* Bump size up to next supported mode.
*/
- if (width <= 800 && height <= 600) {
+ if (width <= 720 && height <= 480) {
+ width = 720; height = 480;
+ }
+ else if (width <= 960 && height <= 540) {
+ width = 960; height = 540;
+ }
+ else if (width <= 800 && height <= 600) {
width = 800; height = 600;
}
else if (width <= 1024 && height <= 768) {
else if (width <= 1280 && height <= 1024) {
width = 1280; height = 1024;
}
+#endif
-
- dpy->driverContext.shared.virtualHeight = height;
- dpy->driverContext.shared.virtualWidth = width;
dpy->driverContext.shared.fbStride = width * (dpy->driverContext.bpp / 8);
/* set the depth, resolution, etc */
dpy->VarInfo.bits_per_pixel = dpy->driverContext.bpp;
dpy->VarInfo.xres_virtual = dpy->driverContext.shared.virtualWidth;
dpy->VarInfo.yres_virtual = dpy->driverContext.shared.virtualHeight;
- dpy->VarInfo.xres = width;
+ dpy->VarInfo.xres = dpy->driverContext.shared.Width;
dpy->VarInfo.yres = height;
dpy->VarInfo.xoffset = 0;
dpy->VarInfo.yoffset = 0;
return 0;
}
+ /* These should be calculated with the gtf.c program, and then we could
+ remove all this... AlanH. */
if (dpy->VarInfo.xres == 1280 &&
dpy->VarInfo.yres == 1024) {
/* timing values taken from /etc/fb.modes (1280x1024 @ 75Hz) */
dpy->VarInfo.hsync_len = 72;
dpy->VarInfo.vsync_len = 2;
}
+ else if (dpy->VarInfo.xres == 720 &&
+ dpy->VarInfo.yres == 480) {
+ dpy->VarInfo.pixclock = 37202;
+ dpy->VarInfo.left_margin = 88;
+ dpy->VarInfo.right_margin = 16;
+ dpy->VarInfo.upper_margin = 14;
+ dpy->VarInfo.lower_margin = 1;
+ dpy->VarInfo.hsync_len = 72;
+ dpy->VarInfo.vsync_len = 3;
+ }
+ else if (dpy->VarInfo.xres == 960 &&
+ dpy->VarInfo.yres == 540) {
+ dpy->VarInfo.pixclock = 24273;
+ dpy->VarInfo.left_margin = 128;
+ dpy->VarInfo.right_margin = 32;
+ dpy->VarInfo.upper_margin = 16;
+ dpy->VarInfo.lower_margin = 1;
+ dpy->VarInfo.hsync_len = 96;
+ dpy->VarInfo.vsync_len = 3;
+ }
else if (dpy->VarInfo.xres == 768 &&
dpy->VarInfo.yres == 1024) {
/* timing values for 768x1024 @ 75Hz */
* \internal
* Returns the MiniGLXDisplayRec::driScreen attribute.
*/
-__DRIscreen *
+static __DRIscreen *
__glXFindDRIScreen(__DRInativeDisplay *dpy, int scrn)
{
(void) scrn;
* Since Mini GLX only supports one window, compares the specified drawable with
* the MiniGLXDisplayRec::TheWindow attribute.
*/
-Bool
-__glXWindowExists(__DRInativeDisplay *dpy, GLXDrawable draw)
+static GLboolean
+__glXWindowExists(__DRInativeDisplay *dpy, __DRIid draw)
{
- Display* display = (Display*)dpy;
- if (display->TheWindow == draw)
+ const Display * const display = (Display*)dpy;
+ if (display->TheWindow == (Window) draw)
return True;
else
return False;
dpy->driverContext.cpp = 4;
dpy->rotateMode = 0;
dpy->driverContext.agpmode = 1;
+ dpy->driverContext.isPCI = 0;
+ dpy->driverContext.colorTiling = 0;
fname = getenv("MINIGLX_CONF");
if (!fname) fname = "/etc/miniglx.conf";
if (sscanf(val, "%d", &dpy->driverContext.agpmode) != 1)
fprintf(stderr, "malformed agpmode: %s\n", opt);
}
+ else if (strcmp(opt, "isPCI") == 0) {
+ dpy->driverContext.isPCI = atoi(val) ? 1 : 0;
+ }
+ else if (strcmp(opt, "colorTiling") == 0) {
+ dpy->driverContext.colorTiling = atoi(val) ? 1 : 0;
+ }
}
fclose(file);
return 1;
}
+/**
+ * Versioned name of the expected \c __driCreateNewScreen function.
+ *
+ * The version of the last incompatible loader/driver inteface change is
+ * appended to the name of the \c __driCreateNewScreen function. This
+ * prevents loaders from trying to load drivers that are too old.
+ *
+ * \todo
+ * Create a macro or something so that this is automatically updated.
+ */
+static const char createNewScreenName[] = "__driCreateNewScreen_20050727";
+
+
static int InitDriver( Display *dpy )
{
/*
/* Pull in standard DRI client-side driver hooks:
*/
dpy->createNewScreen = (PFNCREATENEWSCREENFUNC)
- dlsym(dpy->dlHandle, "__driCreateNewScreen");
+ dlsym(dpy->dlHandle, createNewScreenName);
if (!dpy->createNewScreen) {
- fprintf(stderr, "Couldn't find __driCreateScreen in %s\n",
+ fprintf(stderr, "Couldn't find %s in %s\n", createNewScreenName,
dpy->clientDriverName);
goto failed;
}
Display *dpy;
int use_vt = 0;
+ pci_system_init();
+
dpy = (Display *)calloc(1, sizeof(Display));
if (!dpy)
return NULL;
}
+/**
+ * Implement \c __DRIinterfaceMethods::getProcAddress.
+ */
+static __DRIfuncPtr get_proc_address( const char * proc_name )
+{
+ (void) proc_name;
+ return NULL;
+}
+
+
+/**
+ * Table of functions exported by the loader to the driver.
+ */
+static const __DRIinterfaceMethods interface_methods = {
+ get_proc_address,
+
+ _gl_context_modes_create,
+ _gl_context_modes_destroy,
+
+ __glXFindDRIScreen,
+ __glXWindowExists,
+
+ __glXCreateContextWithConfig,
+ xf86DRI_DestroyContext,
+
+ xf86DRI_CreateDrawable,
+ xf86DRI_DestroyDrawable,
+ __glXGetDrawableInfo,
+
+ __glXGetUST,
+ __glXGetMscRate,
+};
+
+
static void *
CallCreateNewScreen(Display *dpy, int scrn, __DRIscreen *psc)
{
- int directCapable;
void *psp = NULL;
drm_handle_t hSAREA;
drmAddress pSAREA;
const char * err_extra;
drmVersionPtr version;
drm_handle_t hFB;
- int junk;
+ drm_magic_t magic;
- err_msg = "XF86DRIOpenConnection";
- err_extra = NULL;
hSAREA = dpy->driverContext.shared.hSAREA;
BusID = dpy->driverContext.pciBusID;
if (fd < 0) goto done;
- drm_magic_t magic;
-
err_msg = "drmGetMagic";
err_extra = NULL;
* We'll check the version in each DRI driver's "createScreen"
* function.
*/
- err_msg = "XF86DRIGetClientDriverName";
- ddx_version.major = 4;
+ ddx_version.major = -1;
ddx_version.minor = 0;
ddx_version.patch = 0;
/*
* Get the DRI X extension version.
*/
- err_msg = "XF86DRIQueryVersion";
dri_version.major = 4;
dri_version.minor = 0;
dri_version.patch = 0;
* that has information about the screen size, depth, pitch,
* ancilliary buffers, DRM mmap handles, etc.
*/
- err_msg = "XF86DRIGetDeviceInfo";
hFB = dpy->driverContext.shared.hFrameBuffer;
framebuffer.size = dpy->driverContext.shared.fbSize;
framebuffer.stride = dpy->driverContext.shared.fbStride;
err_extra = strerror( -status );
if ( status == 0 ) {
- PFNGLXGETINTERNALVERSIONPROC get_ver;
-
- get_ver = (PFNGLXGETINTERNALVERSIONPROC)
- glXGetProcAddress( (const GLubyte *) "__glXGetInternalVersion" );
-
err_msg = "InitDriver";
err_extra = NULL;
psp = dpy->createNewScreen(dpy, scrn, psc, NULL,
& framebuffer,
pSAREA,
fd,
- (get_ver != NULL) ? (*get_ver)() : 20040602,
+ 20050727,
+ & interface_methods,
(__GLcontextModes **) &dpy->driver_modes);
- }
+ /* fill in dummy visual ids */
+ {
+ __GLcontextModes *temp;
+ temp = (__GLcontextModes *)dpy->driver_modes;
+ i = 1;
+ while (temp)
+ {
+ temp->visualID = i++;
+ temp=temp->next;
+ }
+ }
+ }
+
done:
if ( psp == NULL ) {
if ( pSAREA != MAP_FAILED ) {
const __GLcontextModes *mode;
XVisualInfo *results;
Visual *visResults;
- int i, n;
+ int i, n=0;
- ASSERT(vinfo_mask == VisualScreenMask);
+ // ASSERT(vinfo_mask == VisualScreenMask);
ASSERT(vinfo_template.screen == 0);
- n = 0;
- for ( mode = dpy->driver_modes ; mode != NULL ; mode = mode->next )
- n++;
+ if (vinfo_mask == VisualIDMask)
+ {
+ for ( mode = dpy->driver_modes ; mode != NULL ; mode= mode->next )
+ if (mode->visualID == vinfo_template->visualid)
+ n=1;
- results = (XVisualInfo *)calloc(1, n * sizeof(XVisualInfo));
- if (!results) {
- *nitens_return = 0;
- return NULL;
- }
+ if (n==0)
+ return NULL;
+
+ results = (XVisualInfo *)calloc(1, n * sizeof(XVisualInfo));
+ if (!results) {
+ *nitens_return = 0;
+ return NULL;
+ }
+
+ visResults = (Visual *)calloc(1, n * sizeof(Visual));
+ if (!results) {
+ free(results);
+ *nitens_return = 0;
+ return NULL;
+ }
- visResults = (Visual *)calloc(1, n * sizeof(Visual));
- if (!results) {
- free(results);
- *nitens_return = 0;
- return NULL;
+ for ( mode = dpy->driver_modes ; mode != NULL ; mode= mode->next )
+ if (mode->visualID == vinfo_template->visualid)
+ {
+ visResults[0].mode=mode;
+ visResults[0].visInfo = results;
+ visResults[0].dpy = dpy;
+ if (dpy->driverContext.bpp == 32)
+ visResults[0].pixelFormat = PF_B8G8R8A8; /* XXX: FIX ME */
+ else
+ visResults[0].pixelFormat = PF_B5G6R5; /* XXX: FIX ME */
+
+ results[0].visual = visResults;
+ results[0].visualid = mode->visualID;
+#if defined(__cplusplus) || defined(c_plusplus)
+ results[0].c_class = TrueColor;
+#else
+ results[0].class = TrueColor;
+#endif
+ results[0].depth = mode->redBits +
+ mode->redBits +
+ mode->redBits +
+ mode->redBits;
+ results[0].bits_per_rgb = dpy->driverContext.bpp;
+
+ }
+
}
-
- for ( mode = dpy->driver_modes, i = 0 ; mode != NULL ; mode = mode->next, i++ ) {
- visResults[i].mode = mode;
- visResults[i].visInfo = results + i;
- visResults[i].dpy = dpy;
-
- if (dpy->driverContext.bpp == 32)
+ else // if (vinfo_mask == VisualScreenMask)
+ {
+ n = 0;
+ for ( mode = dpy->driver_modes ; mode != NULL ; mode = mode->next )
+ n++;
+
+ results = (XVisualInfo *)calloc(1, n * sizeof(XVisualInfo));
+ if (!results) {
+ *nitens_return = 0;
+ return NULL;
+ }
+
+ visResults = (Visual *)calloc(1, n * sizeof(Visual));
+ if (!results) {
+ free(results);
+ *nitens_return = 0;
+ return NULL;
+ }
+
+ for ( mode = dpy->driver_modes, i = 0 ; mode != NULL ; mode = mode->next, i++ ) {
+ visResults[i].mode = mode;
+ visResults[i].visInfo = results + i;
+ visResults[i].dpy = dpy;
+
+ if (dpy->driverContext.bpp == 32)
visResults[i].pixelFormat = PF_B8G8R8A8; /* XXX: FIX ME */
- else
+ else
visResults[i].pixelFormat = PF_B5G6R5; /* XXX: FIX ME */
-
- results[i].visual = visResults + i;
- results[i].visualid = i;
+
+ results[i].visual = visResults + i;
+ results[i].visualid = mode->visualID;
#if defined(__cplusplus) || defined(c_plusplus)
- results[i].c_class = TrueColor;
+ results[i].c_class = TrueColor;
#else
- results[i].class = TrueColor;
+ results[i].class = TrueColor;
#endif
- results[i].depth = mode->redBits +
- mode->redBits +
- mode->redBits +
- mode->redBits;
- results[i].bits_per_rgb = dpy->driverContext.bpp;
+ results[i].depth = mode->redBits +
+ mode->redBits +
+ mode->redBits +
+ mode->redBits;
+ results[i].bits_per_rgb = dpy->driverContext.bpp;
+ }
}
*nitens_return = n;
return results;
GLint redBits = 0, greenBits = 0, blueBits = 0, alphaBits = 0;
GLint indexBits = 0, depthBits = 0, stencilBits = 0;
GLint numSamples = 0;
- int i;
+ int i=0;
/*
* XXX in the future, <screen> might be interpreted as a VT
(void) alphaBits;
(void) stereoFlag;
for ( mode = dpy->driver_modes ; mode != NULL ; mode = mode->next ) {
+ i++;
if (mode->rgbMode == rgbFlag &&
mode->doubleBufferMode == dbFlag &&
mode->redBits >= redBits &&
else
sharePriv = NULL;
+ ctx->driContext.mode = vis->visual->mode;
ctx->driContext.private = dpy->driScreen.createNewContext(dpy, vis->visual->mode,
GLX_WINDOW_BIT, sharePriv, &ctx->driContext);
if (ctx) {
if (glxctx == ctx) {
/* destroying current context */
- ctx->driContext.bindContext3(dpy, 0, 0, 0, 0);
+ ctx->driContext.bindContext(dpy, 0, 0, 0, 0);
CurrentContext = 0;
}
ctx->driContext.destroyContext(dpy, 0, ctx->driContext.private);
GLXDrawable oldDrawable = glXGetCurrentDrawable();
/* unbind old */
if (oldContext) {
- oldContext->driContext.unbindContext3(dpy, 0,
+ oldContext->driContext.unbindContext(dpy, 0,
(__DRIid) oldDrawable, (__DRIid) oldDrawable,
&oldContext->driContext);
}
/* bind new */
CurrentContext = ctx;
- ctx->driContext.bindContext3(dpy, 0, (__DRIid) drawable,
+ ctx->driContext.bindContext(dpy, 0, (__DRIid) drawable,
(__DRIid) drawable, &ctx->driContext);
ctx->drawBuffer = drawable;
ctx->curBuffer = drawable;
}
else if (ctx && dpy) {
/* unbind */
- ctx->driContext.bindContext3(dpy, 0, 0, 0, 0);
+ ctx->driContext.bindContext(dpy, 0, 0, 0, 0);
}
else if (dpy) {
CurrentContext = 0; /* kw: this seems to be intended??? */
}
-GLboolean
+static GLboolean
__glXCreateContextWithConfig(__DRInativeDisplay *dpy, int screen,
int fbconfigID, void *contextID, drm_context_t *hHWContext)
{
}
-GLboolean
+static GLboolean
__glXGetDrawableInfo(__DRInativeDisplay *dpy, int scrn,
__DRIid draw, unsigned int * index, unsigned int * stamp,
int * x, int * y, int * width, int * height,
{
GLXDrawable drawable = (GLXDrawable) draw;
drm_clip_rect_t * cliprect;
-
+ Display* display = (Display*)dpy;
+ __DRIcontextPrivate *pcp = (__DRIcontextPrivate *)CurrentContext->driContext.private;
if (drawable == 0) {
return GL_FALSE;
}
cliprect->y1 = drawable->y;
cliprect->x2 = drawable->x + drawable->w;
cliprect->y2 = drawable->y + drawable->h;
+
+ /* the drawable index is by client id */
+ *index = display->clientID;
+ *stamp = pcp->driScreenPriv->pSAREA->drawableTable[display->clientID].stamp;
*x = drawable->x;
*y = drawable->y;
*width = drawable->w;
*height = drawable->h;
*numClipRects = 1;
*pClipRects = cliprect;
- *backX = 0;
- *backY = 0;
+
+ *backX = drawable->x;
+ *backY = drawable->y;
*numBackClipRects = 0;
*pBackClipRects = 0;
}
-GLboolean
-XF86DRIDestroyContext(__DRInativeDisplay *dpy, int screen, __DRIid context_id )
+static GLboolean
+xf86DRI_DestroyContext(__DRInativeDisplay *dpy, int screen, __DRIid context_id )
{
return GL_TRUE;
}
-GLboolean
-XF86DRICreateDrawable(__DRInativeDisplay *dpy, int screen, __DRIid drawable,
+static GLboolean
+xf86DRI_CreateDrawable(__DRInativeDisplay *dpy, int screen, __DRIid drawable,
drm_drawable_t *hHWDrawable )
{
return GL_TRUE;
}
-GLboolean
-XF86DRIDestroyDrawable(__DRInativeDisplay *dpy, int screen, __DRIid drawable)
+static GLboolean
+xf86DRI_DestroyDrawable(__DRInativeDisplay *dpy, int screen, __DRIid drawable)
{
return GL_TRUE;
}
{ "glXDestroyPbuffer", (void *) glXDestroyPbuffer },
{ "glXChooseFBConfig", (void *) glXChooseFBConfig },
{ "glXGetVisualFromFBConfig", (void *) glXGetVisualFromFBConfig },
- { "__glXCreateContextWithConfig", (void *) __glXCreateContextWithConfig },
- { "__glXGetDrawableInfo", (void *) __glXGetDrawableInfo },
- { "__glXWindowExists", (void *) __glXWindowExists },
- { "__glXCreateContextModes", (void *) _gl_context_modes_create },
{ NULL, NULL }
};
const struct name_address *entry;
return config.visInfo;
}
+void *glXAllocateMemoryMESA(Display *dpy, int scrn,
+ size_t size, float readFreq,
+ float writeFreq, float priority)
+{
+ if (dpy->driScreen.private && dpy->driScreen.allocateMemory) {
+ return (*dpy->driScreen.allocateMemory)( dpy, scrn, size,
+ readFreq, writeFreq,
+ priority );
+ }
+
+ return NULL;
+}
+
+void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer)
+{
+ if (dpy->driScreen.private && dpy->driScreen.freeMemory) {
+ (*dpy->driScreen.freeMemory)( dpy, scrn, pointer );
+ }
+}
+
+GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn,
+ const void *pointer )
+{
+ if (dpy->driScreen.private && dpy->driScreen.memoryOffset) {
+ return (*dpy->driScreen.memoryOffset)( dpy, scrn, pointer );
+ }
+
+ return 0;
+}
+
+
+/**
+ * Get the unadjusted system time (UST). Currently, the UST is measured in
+ * microseconds since Epoc. The actual resolution of the UST may vary from
+ * system to system, and the units may vary from release to release.
+ * Drivers should not call this function directly. They should instead use
+ * \c glXGetProcAddress to obtain a pointer to the function.
+ *
+ * \param ust Location to store the 64-bit UST
+ * \returns Zero on success or a negative errno value on failure.
+ *
+ * \note
+ * This function was copied directly from src/glx/x11/glxcmds.c.
+ */
+static int __glXGetUST( int64_t * ust )
+{
+ struct timeval tv;
+
+ if ( ust == NULL ) {
+ return -EFAULT;
+ }
+
+ if ( gettimeofday( & tv, NULL ) == 0 ) {
+ ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
+ return 0;
+ } else {
+ return -errno;
+ }
+}
+
+/**
+ *
+ * \bug
+ * This needs to be implemented for miniGlx.
+ */
+static GLboolean __glXGetMscRate(__DRInativeDisplay * dpy, __DRIid drawable,
+ int32_t * numerator, int32_t * denominator)
+{
+ *numerator = 0;
+ *denominator = 0;
+ return False;
+}
/*@}*/