Path: blob/21.2-virgl/src/gallium/frontends/glx/xlib/xm_api.h
4561 views
/*1* Mesa 3-D graphics library2*3* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the "Software"),7* to deal in the Software without restriction, including without limitation8* the rights to use, copy, modify, merge, publish, distribute, sublicense,9* and/or sell copies of the Software, and to permit persons to whom the10* Software is furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice shall be included13* in all copies or substantial portions of the Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS16* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR19* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,20* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR21* OTHER DEALINGS IN THE SOFTWARE.22*/23242526/* Sample Usage:2728In addition to the usual X calls to select a visual, create a colormap29and create a window, you must do the following to use the X/Mesa interface:30311. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo.32332. Call XMesaCreateContext() to create an X/Mesa rendering context, given34the XMesaVisual.35363. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window37and XMesaVisual.38394. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and40to make the context the current one.41425. Make gl* calls to render your graphics.43446. Use XMesaSwapBuffers() when double buffering to swap front/back buffers.45467. Before the X window is destroyed, call XMesaDestroyBuffer().47488. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext.4950*/5152535455#ifndef XM_API_H56#define XM_API_H575859#include "main/mtypes.h" /* for gl_config */60#include "frontend/api.h"61#include "os/os_thread.h"6263#include "frontend/xlibsw_api.h"6465# include <X11/Xlib.h>66# include <X11/Xlibint.h>67# include <X11/Xutil.h>6869struct hud_context;7071typedef struct xmesa_display *XMesaDisplay;72typedef struct xmesa_buffer *XMesaBuffer;73typedef struct xmesa_context *XMesaContext;74typedef struct xmesa_visual *XMesaVisual;757677struct xmesa_display {78mtx_t mutex;7980Display *display;81struct pipe_screen *screen;82struct st_manager *smapi;8384struct pipe_context *pipe;85};868788/*89* Create a new X/Mesa visual.90* Input: display - X11 display91* visinfo - an XVisualInfo pointer92* rgb_flag - GL_TRUE = RGB mode,93* GL_FALSE = color index mode94* alpha_flag - alpha buffer requested?95* db_flag - GL_TRUE = double-buffered,96* GL_FALSE = single buffered97* stereo_flag - stereo visual?98* ximage_flag - GL_TRUE = use an XImage for back buffer,99* GL_FALSE = use an off-screen pixmap for back buffer100* depth_size - requested bits/depth values, or zero101* stencil_size - requested bits/stencil values, or zero102* accum_red_size - requested bits/red accum values, or zero103* accum_green_size - requested bits/green accum values, or zero104* accum_blue_size - requested bits/blue accum values, or zero105* accum_alpha_size - requested bits/alpha accum values, or zero106* num_samples - number of samples/pixel if multisampling, or zero107* level - visual level, usually 0108* visualCaveat - ala the GLX extension, usually GLX_NONE_EXT109* Return; a new XMesaVisual or 0 if error.110*/111extern XMesaVisual XMesaCreateVisual( Display *display,112XVisualInfo * visinfo,113GLboolean rgb_flag,114GLboolean alpha_flag,115GLboolean db_flag,116GLboolean stereo_flag,117GLboolean ximage_flag,118GLint depth_size,119GLint stencil_size,120GLint accum_red_size,121GLint accum_green_size,122GLint accum_blue_size,123GLint accum_alpha_size,124GLint num_samples,125GLint level,126GLint visualCaveat );127128/*129* Destroy an XMesaVisual, but not the associated XVisualInfo.130*/131extern void XMesaDestroyVisual( XMesaVisual v );132133134135/*136* Create a new XMesaContext for rendering into an X11 window.137*138* Input: visual - an XMesaVisual139* share_list - another XMesaContext with which to share display140* lists or NULL if no sharing is wanted.141* Return: an XMesaContext or NULL if error.142*/143extern XMesaContext XMesaCreateContext( XMesaVisual v,144XMesaContext share_list,145GLuint major, GLuint minor,146GLuint profileMask,147GLuint contextFlags);148149150/*151* Destroy a rendering context as returned by XMesaCreateContext()152*/153extern void XMesaDestroyContext( XMesaContext c );154155156157/*158* Create an XMesaBuffer from an X window.159*/160extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, Window w );161162163/*164* Create an XMesaBuffer from an X pixmap.165*/166extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v,167Pixmap p,168Colormap cmap );169170171/*172* Destroy an XMesaBuffer, but not the corresponding window or pixmap.173*/174extern void XMesaDestroyBuffer( XMesaBuffer b );175176177/*178* Return the XMesaBuffer handle which corresponds to an X drawable, if any.179*180* New in Mesa 2.3.181*/182extern XMesaBuffer XMesaFindBuffer( Display *dpy,183Drawable d );184185186187/*188* Bind two buffers (read and draw) to a context and make the189* context the current one.190* New in Mesa 3.3191*/192extern GLboolean XMesaMakeCurrent2( XMesaContext c,193XMesaBuffer drawBuffer,194XMesaBuffer readBuffer );195196197/*198* Unbind the current context from its buffer.199*/200extern GLboolean XMesaUnbindContext( XMesaContext c );201202203/*204* Return a handle to the current context.205*/206extern XMesaContext XMesaGetCurrentContext( void );207208209/*210* Swap the front and back buffers for the given buffer. No action is211* taken if the buffer is not double buffered.212*/213extern void XMesaSwapBuffers( XMesaBuffer b );214215216/*217* Copy a sub-region of the back buffer to the front buffer.218*219* New in Mesa 2.6220*/221extern void XMesaCopySubBuffer( XMesaBuffer b,222int x,223int y,224int width,225int height );226227228229230231/*232* Flush/sync a context233*/234extern void XMesaFlush( XMesaContext c );235236237238/*239* Scan for XMesaBuffers whose window/pixmap has been destroyed, then free240* any memory used by that buffer.241*242* New in Mesa 2.3.243*/244extern void XMesaGarbageCollect( void );245246247248/*249* Create a pbuffer.250* New in Mesa 4.1251*/252extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, Colormap cmap,253unsigned int width, unsigned int height);254255256257/*258* Texture from Pixmap259* New in Mesa 7.1260*/261extern void262XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer,263const int *attrib_list);264265extern void266XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer);267268269extern XMesaBuffer270XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p,271Colormap cmap,272int format, int target, int mipmap);273274275extern void276XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask);277278279/***********************************************************************280*/281282/**283* Visual inforation, derived from GLvisual.284* Basically corresponds to an XVisualInfo.285*/286struct xmesa_visual {287struct gl_config mesa_visual;/* Device independent visual parameters */288int screen, visualID, visualType;289Display *display; /* The X11 display */290XVisualInfo * visinfo; /* X's visual info (pointer to private copy) */291XVisualInfo *vishandle; /* Only used in fakeglx.c */292GLint BitsPerPixel; /* True bits per pixel for XImages */293294GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */295296struct st_visual stvis;297};298299300/**301* Context info, derived from st_context.302* Basically corresponds to a GLXContext.303*/304struct xmesa_context {305struct st_context_iface *st;306XMesaVisual xm_visual; /** pixel format info */307XMesaBuffer xm_buffer; /** current drawbuffer */308XMesaBuffer xm_read_buffer; /** current readbuffer */309struct hud_context *hud;310};311312313/**314* Types of X/GLX drawables we might render into.315*/316typedef enum {317WINDOW, /* An X window */318GLXWINDOW, /* GLX window */319PIXMAP, /* GLX pixmap */320PBUFFER /* GLX Pbuffer */321} BufferType;322323324/**325* Framebuffer information, derived from.326* Basically corresponds to a GLXDrawable.327*/328struct xmesa_buffer {329struct st_framebuffer_iface *stfb;330struct xlib_drawable ws;331332GLboolean wasCurrent; /* was ever the current buffer? */333XMesaVisual xm_visual; /* the X/Mesa visual */334Colormap cmap; /* the X colormap */335BufferType type; /* window, pixmap, pbuffer or glxwindow */336337GLboolean largestPbuffer; /**< for pbuffers */338GLboolean preservedContents; /**< for pbuffers */339340XImage *tempImage;341unsigned long selectedEvents;/* for pbuffers only */342343344GC gc; /* scratch GC for span, line, tri drawing */345346/* GLX_EXT_texture_from_pixmap */347GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */348GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */349GLint TextureMipmap; /** 0 or 1 */350351struct xmesa_buffer *Next; /* Linked list pointer: */352353unsigned width, height;354};355356357358extern const char *359xmesa_get_name(void);360361extern int362xmesa_init(Display *dpy);363364extern XMesaBuffer365xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis);366367extern void368xmesa_get_window_size(Display *dpy, XMesaBuffer b,369GLuint *width, GLuint *height);370371extern void372xmesa_notify_invalid_buffer(XMesaBuffer b);373374extern void375xmesa_check_buffer_size(XMesaBuffer b);376377extern void378xmesa_destroy_buffers_on_display(Display *dpy);379380extern void381xmesa_close_display(Display *dpy);382383static inline GLuint384xmesa_buffer_width(XMesaBuffer b)385{386return b->width;387}388389static inline GLuint390xmesa_buffer_height(XMesaBuffer b)391{392return b->height;393}394395extern boolean xmesa_strict_invalidate;396397#endif398399400