Path: blob/21.2-virgl/src/glx/apple/apple_glx_drawable.h
4560 views
/*1Copyright (c) 2008, 2009 Apple Inc.23Permission is hereby granted, free of charge, to any person4obtaining a copy of this software and associated documentation files5(the "Software"), to deal in the Software without restriction,6including without limitation the rights to use, copy, modify, merge,7publish, distribute, sublicense, and/or sell copies of the Software,8and to permit persons to whom the Software is furnished to do so,9subject to the following conditions:1011The above copyright notice and this permission notice shall be12included in all copies or substantial portions of the Software.1314THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT18HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,19WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21DEALINGS IN THE SOFTWARE.2223Except as contained in this notice, the name(s) of the above24copyright holders shall not be used in advertising or otherwise to25promote the sale, use or other dealings in this Software without26prior written authorization.27*/28#ifndef APPLE_GLX_DRAWABLE_H29#define APPLE_GLX_DRAWABLE_H3031/* Must be first for:32* <rdar://problem/6953344>33*/34#include "apple_glx_context.h"3536#include <pthread.h>37#include <stdbool.h>38#include <limits.h>39#include <GL/glx.h>40#define XP_NO_X_HEADERS41#include <Xplugin.h>42#undef XP_NO_X_HEADERS4344enum45{46APPLE_GLX_DRAWABLE_SURFACE = 1,47APPLE_GLX_DRAWABLE_PBUFFER,48APPLE_GLX_DRAWABLE_PIXMAP49};5051/* The flag for the find routine. */52enum53{54APPLE_GLX_DRAWABLE_LOCK = 2,55APPLE_GLX_DRAWABLE_REFERENCE = 456};5758struct apple_glx_context;59struct apple_glx_drawable;6061struct apple_glx_surface62{63xp_surface_id surface_id;64unsigned int uid;65bool pending_destroy;66};6768struct apple_glx_pbuffer69{70GLXPbuffer xid; /* our pixmap */71int width, height;72GLint fbconfigID;73CGLPBufferObj buffer_obj;74unsigned long event_mask;75};7677struct apple_glx_pixmap78{79GLXPixmap xpixmap;80void *buffer;81int width, height, pitch, /*bytes per pixel */ bpp;82size_t size;83char path[PATH_MAX];84int fd;85CGLPixelFormatObj pixel_format_obj;86CGLContextObj context_obj;87GLint fbconfigID;88};8990struct apple_glx_drawable_callbacks91{92int type;93bool(*make_current) (struct apple_glx_context * ac,94struct apple_glx_drawable * d);95void (*destroy) (Display * dpy, struct apple_glx_drawable * d);96};9798struct apple_glx_drawable99{100Display *display;101int reference_count;102GLXDrawable drawable;103int type; /* APPLE_GLX_DRAWABLE_* */104105union106{107struct apple_glx_pixmap pixmap;108struct apple_glx_pbuffer pbuffer;109struct apple_glx_surface surface;110} types;111112struct apple_glx_drawable_callbacks callbacks;113114/*115* This mutex protects the reference count and any other drawable data.116* It's used to prevent an early release of a drawable.117*/118pthread_mutex_t mutex;119void (*lock) (struct apple_glx_drawable * agd);120void (*unlock) (struct apple_glx_drawable * agd);121122void (*reference) (struct apple_glx_drawable * agd);123void (*release) (struct apple_glx_drawable * agd);124125bool(*destroy) (struct apple_glx_drawable * agd);126127bool(*is_pbuffer) (struct apple_glx_drawable * agd);128129bool(*is_pixmap) (struct apple_glx_drawable * agd);130131/*BEGIN These are used for the mixed mode drawing... */132int width, height;133int row_bytes;134char path[PATH_MAX];135int fd; /* The file descriptor for this drawable's shared memory. */136void *buffer; /* The memory for the drawable. Typically shared memory. */137size_t buffer_length;138/*END*/ struct apple_glx_drawable *previous, *next;139};140141struct apple_glx_context;142143/* May return NULL if not found */144struct apple_glx_drawable *apple_glx_find_drawable(Display * dpy,145GLXDrawable drawable);146147/* Returns true on error and locks the agd result with a reference. */148bool apple_glx_drawable_create(Display * dpy,149int screen,150GLXDrawable drawable,151struct apple_glx_drawable **agd,152struct apple_glx_drawable_callbacks153*callbacks);154155/* Returns true on error */156bool apple_glx_create_drawable(Display * dpy,157struct apple_glx_context *ac,158GLXDrawable drawable,159struct apple_glx_drawable **agd);160161void apple_glx_garbage_collect_drawables(Display * dpy);162163/*164* This returns the total number of drawables.165* It's mostly intended for debugging and introspection.166*/167unsigned int apple_glx_get_drawable_count(void);168169struct apple_glx_drawable *apple_glx_drawable_find_by_type(GLXDrawable170drawable, int type,171int flags);172173struct apple_glx_drawable *apple_glx_drawable_find(GLXDrawable drawable,174int flags);175176177bool apple_glx_drawable_destroy_by_type(Display * dpy, GLXDrawable drawable,178int type);179180struct apple_glx_drawable *apple_glx_drawable_find_by_uid(unsigned int uid,181int flags);182183/* Surfaces */184185bool apple_glx_surface_create(Display * dpy, int screen, GLXDrawable drawable,186struct apple_glx_drawable **resultptr);187188void apple_glx_surface_destroy(unsigned int uid);189190/* Pbuffers */191192/* Returns true if an error occurred. */193bool apple_glx_pbuffer_create(Display * dpy, GLXFBConfig config,194int width, int height, int *errorcode,195GLXPbuffer * pbuf);196197/* Returns true if the pbuffer was invalid. */198bool apple_glx_pbuffer_destroy(Display * dpy, GLXPbuffer pbuf);199200/* Returns true if the pbuffer was valid and the attribute. */201bool apple_glx_pbuffer_query(GLXDrawable d, int attribute,202unsigned int *value);203204/* Returns true if the GLXDrawable is a valid GLXPbuffer, and the mask is set. */205bool apple_glx_pbuffer_set_event_mask(GLXDrawable d, unsigned long mask);206207/* Returns true if the GLXDrawable is a valid GLXPbuffer, and the *mask is set. */208bool apple_glx_pbuffer_get_event_mask(GLXDrawable d, unsigned long *mask);209210211/* Pixmaps */212213/* mode is a struct glx_config * */214/* Returns true if an error occurred. */215bool apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,216const void *mode);217218/* Returns true if an error occurred. */219bool apple_glx_pixmap_destroy(Display * dpy, Pixmap pixmap);220221bool apple_glx_pixmap_query(GLXPixmap pixmap, int attribute,222unsigned int *value);223224225226#endif227228229