apple_glx_drawable.h revision ad503c41557606d15b0420c824369456f6d20a8f
1/* 2 Copyright (c) 2008, 2009 Apple Inc. 3 4 Permission is hereby granted, free of charge, to any person 5 obtaining a copy of this software and associated documentation files 6 (the "Software"), to deal in the Software without restriction, 7 including without limitation the rights to use, copy, modify, merge, 8 publish, distribute, sublicense, and/or sell copies of the Software, 9 and to permit persons to whom the Software is furnished to do so, 10 subject to the following conditions: 11 12 The above copyright notice and this permission notice shall be 13 included in all copies or substantial portions of the Software. 14 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 DEALINGS IN THE SOFTWARE. 23 24 Except as contained in this notice, the name(s) of the above 25 copyright holders shall not be used in advertising or otherwise to 26 promote the sale, use or other dealings in this Software without 27 prior written authorization. 28*/ 29#ifndef APPLE_GLX_DRAWABLE_H 30#define APPLE_GLX_DRAWABLE_H 31 32#include <pthread.h> 33#include <stdbool.h> 34#include <limits.h> 35#include <GL/glx.h> 36#define XP_NO_X_HEADERS 37#include <Xplugin.h> 38#undef XP_NO_X_HEADERS 39#include "apple_glx_context.h" 40 41enum 42{ 43 APPLE_GLX_DRAWABLE_SURFACE = 1, 44 APPLE_GLX_DRAWABLE_PBUFFER, 45 APPLE_GLX_DRAWABLE_PIXMAP 46}; 47 48/* The flag for the find routine. */ 49enum 50{ 51 APPLE_GLX_DRAWABLE_LOCK = 2, 52 APPLE_GLX_DRAWABLE_REFERENCE = 4 53}; 54 55struct apple_glx_context; 56struct apple_glx_drawable; 57 58struct apple_glx_surface 59{ 60 xp_surface_id surface_id; 61 unsigned int uid; 62 bool pending_destroy; 63}; 64 65struct apple_glx_pbuffer 66{ 67 GLXPbuffer xid; /* our pixmap */ 68 int width, height; 69 GLint fbconfigID; 70 CGLPBufferObj buffer_obj; 71 unsigned long event_mask; 72}; 73 74struct apple_glx_pixmap 75{ 76 GLXPixmap xpixmap; 77 void *buffer; 78 int width, height, pitch, /*bytes per pixel */ bpp; 79 size_t size; 80 char path[PATH_MAX]; 81 int fd; 82 CGLPixelFormatObj pixel_format_obj; 83 CGLContextObj context_obj; 84 GLint fbconfigID; 85}; 86 87struct apple_glx_drawable_callbacks 88{ 89 int type; 90 bool(*make_current) (struct apple_glx_context * ac, 91 struct apple_glx_drawable * d); 92 void (*destroy) (Display * dpy, struct apple_glx_drawable * d); 93}; 94 95struct apple_glx_drawable 96{ 97 Display *display; 98 int reference_count; 99 GLXDrawable drawable; 100 int type; /* APPLE_GLX_DRAWABLE_* */ 101 102 union 103 { 104 struct apple_glx_pixmap pixmap; 105 struct apple_glx_pbuffer pbuffer; 106 struct apple_glx_surface surface; 107 } types; 108 109 struct apple_glx_drawable_callbacks callbacks; 110 111 /* 112 * This mutex protects the reference count and any other drawable data. 113 * It's used to prevent an early release of a drawable. 114 */ 115 pthread_mutex_t mutex; 116 void (*lock) (struct apple_glx_drawable * agd); 117 void (*unlock) (struct apple_glx_drawable * agd); 118 119 void (*reference) (struct apple_glx_drawable * agd); 120 void (*release) (struct apple_glx_drawable * agd); 121 122 bool(*destroy) (struct apple_glx_drawable * agd); 123 124 bool(*is_pbuffer) (struct apple_glx_drawable * agd); 125 126 bool(*is_pixmap) (struct apple_glx_drawable * agd); 127 128/*BEGIN These are used for the mixed mode drawing... */ 129 int width, height; 130 int row_bytes; 131 char path[PATH_MAX]; 132 int fd; /* The file descriptor for this drawable's shared memory. */ 133 void *buffer; /* The memory for the drawable. Typically shared memory. */ 134 size_t buffer_length; 135 /*END*/ struct apple_glx_drawable *previous, *next; 136}; 137 138struct apple_glx_context; 139 140/* May return NULL if not found */ 141struct apple_glx_drawable *apple_glx_find_drawable(Display * dpy, 142 GLXDrawable drawable); 143 144/* Returns true on error and locks the agd result with a reference. */ 145bool apple_glx_drawable_create(Display * dpy, 146 int screen, 147 GLXDrawable drawable, 148 struct apple_glx_drawable **agd, 149 struct apple_glx_drawable_callbacks 150 *callbacks); 151 152/* Returns true on error */ 153bool apple_glx_create_drawable(Display * dpy, 154 struct apple_glx_context *ac, 155 GLXDrawable drawable, 156 struct apple_glx_drawable **agd); 157 158void apple_glx_garbage_collect_drawables(Display * dpy); 159 160/* 161 * This returns the total number of drawables. 162 * It's mostly intended for debugging and introspection. 163 */ 164unsigned int apple_glx_get_drawable_count(void); 165 166struct apple_glx_drawable *apple_glx_drawable_find_by_type(GLXDrawable 167 drawable, int type, 168 int flags); 169 170struct apple_glx_drawable *apple_glx_drawable_find(GLXDrawable drawable, 171 int flags); 172 173 174bool apple_glx_drawable_destroy_by_type(Display * dpy, GLXDrawable drawable, 175 int type); 176 177struct apple_glx_drawable *apple_glx_drawable_find_by_uid(unsigned int uid, 178 int flags); 179 180/* Surfaces */ 181 182bool apple_glx_surface_create(Display * dpy, int screen, GLXDrawable drawable, 183 struct apple_glx_drawable **resultptr); 184 185void apple_glx_surface_destroy(unsigned int uid); 186 187/* Pbuffers */ 188 189/* Returns true if an error occurred. */ 190bool apple_glx_pbuffer_create(Display * dpy, GLXFBConfig config, 191 int width, int height, int *errorcode, 192 GLXPbuffer * pbuf); 193 194/* Returns true if the pbuffer was invalid. */ 195bool apple_glx_pbuffer_destroy(Display * dpy, GLXPbuffer pbuf); 196 197/* Returns true if the pbuffer was valid and the attribute. */ 198bool apple_glx_pbuffer_query(GLXDrawable d, int attribute, 199 unsigned int *value); 200 201/* Returns true if the GLXDrawable is a valid GLXPbuffer, and the mask is set. */ 202bool apple_glx_pbuffer_set_event_mask(GLXDrawable d, unsigned long mask); 203 204/* Returns true if the GLXDrawable is a valid GLXPbuffer, and the *mask is set. */ 205bool apple_glx_pbuffer_get_event_mask(GLXDrawable d, unsigned long *mask); 206 207 208/* Pixmaps */ 209 210/* mode is a __GLcontextModes * */ 211/* Returns true if an error occurred. */ 212bool apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap, 213 const void *mode); 214 215/* Returns true if an error occurred. */ 216bool apple_glx_pixmap_destroy(Display * dpy, Pixmap pixmap); 217 218bool apple_glx_pixmap_query(GLXPixmap pixmap, int attribute, 219 unsigned int *value); 220 221 222 223#endif 224