⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dri_glx.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.All Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sub license, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice (including thenext paragraph) shall be included in all copies or substantial portionsof the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FORANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* * Authors: *   Kevin E. Martin <kevin@precisioninsight.com> *   Brian Paul <brian@precisioninsight.com> * */#ifdef GLX_DIRECT_RENDERING#include <X11/Xlib.h>#include <X11/extensions/Xfixes.h>#include <X11/extensions/Xdamage.h>#include "glheader.h"#include "glxclient.h"#include "glcontextmodes.h"#include "xf86dri.h"#include "sarea.h"#include <dlfcn.h>#include <sys/types.h>#include <sys/mman.h>#include "xf86drm.h"#include "dri_common.h"typedef struct __GLXDRIdisplayPrivateRec __GLXDRIdisplayPrivate;typedef struct __GLXDRIcontextPrivateRec __GLXDRIcontextPrivate;struct __GLXDRIdisplayPrivateRec {    __GLXDRIdisplay base;    /*    ** XFree86-DRI version information    */    int driMajor;    int driMinor;    int driPatch;};struct __GLXDRIcontextPrivateRec {    __GLXDRIcontext base;    __DRIcontext *driContext;    XID hwContextID;    __GLXscreenConfigs *psc;};/* * Given a display pointer and screen number, determine the name of * the DRI driver for the screen. (I.e. "r128", "tdfx", etc). * Return True for success, False for failure. */static Bool driGetDriverName(Display *dpy, int scrNum, char **driverName){   int directCapable;   Bool b;   int driverMajor, driverMinor, driverPatch;   *driverName = NULL;   if (!XF86DRIQueryDirectRenderingCapable(dpy, scrNum, &directCapable)) {      ErrorMessageF("XF86DRIQueryDirectRenderingCapable failed\n");      return False;   }   if (!directCapable) {      ErrorMessageF("XF86DRIQueryDirectRenderingCapable returned false\n");      return False;   }   b = XF86DRIGetClientDriverName(dpy, scrNum, &driverMajor, &driverMinor,                                  &driverPatch, driverName);   if (!b) {      ErrorMessageF("Cannot determine driver name for screen %d\n", scrNum);      return False;   }   InfoMessageF("XF86DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n",	     driverMajor, driverMinor, driverPatch, *driverName, scrNum);   return True;}/* * Exported function for querying the DRI driver for a given screen. * * The returned char pointer points to a static array that will be * overwritten by subsequent calls. */PUBLIC const char *glXGetScreenDriver (Display *dpy, int scrNum) {   static char ret[32];   char *driverName;   if (driGetDriverName(dpy, scrNum, &driverName)) {      int len;      if (!driverName)	 return NULL;      len = strlen (driverName);      if (len >= 31)	 return NULL;      memcpy (ret, driverName, len+1);      Xfree(driverName);      return ret;   }   return NULL;}/* * Exported function for obtaining a driver's option list (UTF-8 encoded XML). * * The returned char pointer points directly into the driver. Therefore * it should be treated as a constant. * * If the driver was not found or does not support configuration NULL is * returned. * * Note: The driver remains opened after this function returns. */PUBLIC const char *glXGetDriverConfig (const char *driverName){   void *handle = driOpenDriver (driverName);   if (handle)      return dlsym (handle, "__driConfigOptions");   else      return NULL;}#ifdef XDAMAGE_1_1_INTERFACEstatic GLboolean has_damage_post(Display *dpy){    static GLboolean inited = GL_FALSE;    static GLboolean has_damage;    if (!inited) {	int major, minor;	if (XDamageQueryVersion(dpy, &major, &minor) &&	    major == 1 && minor >= 1)	{	    has_damage = GL_TRUE;	} else {	    has_damage = GL_FALSE;	}	inited = GL_TRUE;    }    return has_damage;}static void __glXReportDamage(__DRIdrawable *driDraw,			      int x, int y,			      drm_clip_rect_t *rects, int num_rects,			      GLboolean front_buffer,			      void *loaderPrivate){    XRectangle *xrects;    XserverRegion region;    int i;    int x_off, y_off;    __GLXDRIdrawable *glxDraw = loaderPrivate;    __GLXscreenConfigs *psc = glxDraw->psc;    Display *dpy = psc->dpy;    Drawable drawable;    if (!has_damage_post(dpy))	return;    if (front_buffer) {	x_off = x;	y_off = y;	drawable = RootWindow(dpy, psc->scr);    } else{	x_off = 0;	y_off = 0;	drawable = glxDraw->xDrawable;    }    xrects = malloc(sizeof(XRectangle) * num_rects);    if (xrects == NULL)	return;    for (i = 0; i < num_rects; i++) {	xrects[i].x = rects[i].x1 + x_off;	xrects[i].y = rects[i].y1 + y_off;	xrects[i].width = rects[i].x2 - rects[i].x1;	xrects[i].height = rects[i].y2 - rects[i].y1;    }    region = XFixesCreateRegion(dpy, xrects, num_rects);    free(xrects);    XDamageAdd(dpy, drawable, region);    XFixesDestroyRegion(dpy, region);}static const __DRIdamageExtension damageExtension = {    { __DRI_DAMAGE, __DRI_DAMAGE_VERSION },    __glXReportDamage,};#endifstatic GLboolean__glXDRIGetDrawableInfo(__DRIdrawable *drawable,			unsigned int *index, unsigned int *stamp, 			int *X, int *Y, int *W, int *H,			int *numClipRects, drm_clip_rect_t ** pClipRects,			int *backX, int *backY,			int *numBackClipRects, drm_clip_rect_t **pBackClipRects,			void *loaderPrivate){    __GLXDRIdrawable *glxDraw = loaderPrivate;    __GLXscreenConfigs *psc = glxDraw->psc;    Display *dpy = psc->dpy;    return XF86DRIGetDrawableInfo(dpy, psc->scr, glxDraw->drawable,				  index, stamp, X, Y, W, H,				  numClipRects, pClipRects,				  backX, backY,				  numBackClipRects, pBackClipRects);}static const __DRIgetDrawableInfoExtension getDrawableInfoExtension = {    { __DRI_GET_DRAWABLE_INFO, __DRI_GET_DRAWABLE_INFO_VERSION },    __glXDRIGetDrawableInfo};static const __DRIextension *loader_extensions[] = {    &systemTimeExtension.base,    &getDrawableInfoExtension.base,#ifdef XDAMAGE_1_1_INTERFACE    &damageExtension.base,#endif    NULL};#ifndef GLX_USE_APPLEGL/** * Perform the required libGL-side initialization and call the client-side * driver's \c __driCreateNewScreen function. *  * \param dpy    Display pointer. * \param scrn   Screen number on the display. * \param psc    DRI screen information. * \param driDpy DRI display information. * \param createNewScreen  Pointer to the client-side driver's *               \c __driCreateNewScreen function. * \returns A pointer to the \c __DRIscreenPrivate structure returned by *          the client-side driver on success, or \c NULL on failure. */static void *CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc,		    __GLXDRIdisplayPrivate * driDpy){    void *psp = NULL;    drm_handle_t hSAREA;    drmAddress pSAREA = MAP_FAILED;    char *BusID;    __DRIversion   ddx_version;    __DRIversion   dri_version;    __DRIversion   drm_version;    __DRIframebuffer  framebuffer;    int   fd = -1;    int   status;    drm_magic_t magic;    drmVersionPtr version;    int newlyopened;    char *driverName;    drm_handle_t  hFB;    int        junk;    const __DRIconfig **driver_configs;    /* DRI protocol version. */    dri_version.major = driDpy->driMajor;    dri_version.minor = driDpy->driMinor;    dri_version.patch = driDpy->driPatch;    framebuffer.base = MAP_FAILED;    framebuffer.dev_priv = NULL;    if (!XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) {	ErrorMessageF("XF86DRIOpenConnection failed\n");	goto handle_error;    }    fd = drmOpenOnce(NULL, BusID, &newlyopened);    Xfree(BusID); /* No longer needed */    if (fd < 0) {	ErrorMessageF("drmOpenOnce failed (%s)\n", strerror(-fd));	goto handle_error;    }    if (drmGetMagic(fd, &magic)) {	ErrorMessageF("drmGetMagic failed\n");	goto handle_error;    }    version = drmGetVersion(fd);    if (version) {	drm_version.major = version->version_major;	drm_version.minor = version->version_minor;	drm_version.patch = version->version_patchlevel;	drmFreeVersion(version);    }    else {	drm_version.major = -1;	drm_version.minor = -1;	drm_version.patch = -1;    }    if (newlyopened && !XF86DRIAuthConnection(dpy, scrn, magic)) {	ErrorMessageF("XF86DRIAuthConnection failed\n");	goto handle_error;    }    /* Get device name (like "tdfx") and the ddx version numbers.     * We'll check the version in each DRI driver's "createNewScreen"     * function. */    if (!XF86DRIGetClientDriverName(dpy, scrn,				    &ddx_version.major,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -