#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 <= 720 && height <= 480) {
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;
* \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->rotateMode = 0;
dpy->driverContext.agpmode = 1;
dpy->driverContext.isPCI = 0;
+ dpy->driverContext.colorTiling = 0;
fname = getenv("MINIGLX_CONF");
if (!fname) fname = "/etc/miniglx.conf";
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 ) {
}
/* init other per-window fields */
- win->x = 0;
- win->y = 0;
+ win->x = x;
+ win->y = y;
win->w = width;
win->h = height;
win->visual = visual; /* ptr assignment */
win->bytesPerPixel = dpy->driverContext.cpp;
win->rowStride = dpy->driverContext.shared.virtualWidth * win->bytesPerPixel;
win->size = win->rowStride * height;
- win->frontStart = dpy->driverContext.FBAddress;
+ win->frontStart = dpy->driverContext.FBAddress + (win->rowStride * win->x) + (win->y * win->bytesPerPixel);
win->frontBottom = (GLubyte *) win->frontStart + (height-1) * win->rowStride;
/* This is incorrect: the hardware driver could put the backbuffer
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;
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)
{
__DRIscreen *pDRIScreen;
- __DRIscreenPrivate *psp;
+ __DRIscreen *psp;
pDRIScreen = __glXFindDRIScreen(dpy, screen);
if ( (pDRIScreen == NULL) || (pDRIScreen->private == NULL) ) {
return GL_FALSE;
}
- psp = (__DRIscreenPrivate *) pDRIScreen->private;
+ psp = (__DRIscreen *) pDRIScreen->private;
if (psp->fd) {
if (drmCreateContext(psp->fd, 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;
+ __DRIscreen *psp = display->driScreen.private;
+ __DRIcontext *pcp = (__DRIcontext *)CurrentContext->driContext.private;
+ __DRIdrawable *pdp = pcp->driDrawablePriv;
if (drawable == 0) {
return GL_FALSE;
}
*index = display->clientID;
*stamp = pcp->driScreenPriv->pSAREA->drawableTable[display->clientID].stamp;
+ drmUpdateDrawableInfo(psp->fd, pdp->hHWDrawable, DRM_DRAWABLE_CLIPRECTS, 1, cliprect);
*x = drawable->x;
*y = drawable->y;
*width = drawable->w;
}
-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;
+
+ Display *display = (Display *)dpy;
+ __DRIscreen *psp = display->driScreen.private;
+ int ret;
+ ret = drmCreateDrawable(psp->fd, hHWDrawable);
+
+ fprintf(stderr, "drawable is %d %08X ret is %d\n", *hHWDrawable, drawable, -ret);
+ if (ret != 0)
+ return GL_FALSE;
+ return GL_TRUE;
}
-GLboolean
-XF86DRIDestroyDrawable(__DRInativeDisplay *dpy, int screen, __DRIid drawable)
+static GLboolean
+xf86DRI_DestroyDrawable(__DRInativeDisplay *dpy, int screen, __DRIid drawable)
{
- return GL_TRUE;
+ 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 },
- { "__glXFindDRIScreen", (void *)__glXFindDRIScreen },
{ NULL, NULL }
};
const struct name_address *entry;
return _glapi_get_proc_address((const char *) procname);
}
+void (*glXGetProcAddressARB(const GLubyte *procName))( void ) __attribute__ ((alias ("glXGetProcAddress")));
/**
* \brief Query the Mini GLX version.
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;
+}
/*@}*/