summaryrefslogtreecommitdiffstats
path: root/src/glx/apple/apple_glx_drawable.h
blob: e49eae355e93d742391b847602a1d4346a260bcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
 Copyright (c) 2008, 2009 Apple Inc.
 
 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation files
 (the "Software"), to deal in the Software without restriction,
 including without limitation the rights to use, copy, modify, merge,
 publish, distribute, sublicense, and/or sell copies of the Software,
 and to permit persons to whom the Software is furnished to do so,
 subject to the following conditions:
 
 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
 HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 DEALINGS IN THE SOFTWARE.
 
 Except as contained in this notice, the name(s) of the above
 copyright holders shall not be used in advertising or otherwise to
 promote the sale, use or other dealings in this Software without
 prior written authorization.
*/
#ifndef APPLE_GLX_DRAWABLE_H
#define APPLE_GLX_DRAWABLE_H

/* Must be first for:
 * <rdar://problem/6953344>
 */
#include "apple_glx_context.h"

#include <pthread.h>
#include <stdbool.h>
#include <limits.h>
#include <GL/glx.h>
#define XP_NO_X_HEADERS
#include <Xplugin.h>
#undef XP_NO_X_HEADERS

enum
{
   APPLE_GLX_DRAWABLE_SURFACE = 1,
   APPLE_GLX_DRAWABLE_PBUFFER,
   APPLE_GLX_DRAWABLE_PIXMAP
};

/* The flag for the find routine. */
enum
{
   APPLE_GLX_DRAWABLE_LOCK = 2,
   APPLE_GLX_DRAWABLE_REFERENCE = 4
};

struct apple_glx_context;
struct apple_glx_drawable;

struct apple_glx_surface
{
   xp_surface_id surface_id;
   unsigned int uid;
   bool pending_destroy;
};

struct apple_glx_pbuffer
{
   GLXPbuffer xid;              /* our pixmap */
   int width, height;
   GLint fbconfigID;
   CGLPBufferObj buffer_obj;
   unsigned long event_mask;
};

struct apple_glx_pixmap
{
   GLXPixmap xpixmap;
   void *buffer;
   int width, height, pitch, /*bytes per pixel */ bpp;
   size_t size;
   char path[PATH_MAX];
   int fd;
   CGLPixelFormatObj pixel_format_obj;
   CGLContextObj context_obj;
   GLint fbconfigID;
};

struct apple_glx_drawable_callbacks
{
   int type;
     bool(*make_current) (struct apple_glx_context * ac,
                          struct apple_glx_drawable * d);
   void (*destroy) (Display * dpy, struct apple_glx_drawable * d);
};

struct apple_glx_drawable
{
   Display *display;
   int reference_count;
   GLXDrawable drawable;
   int type;                    /* APPLE_GLX_DRAWABLE_* */

   union
   {
      struct apple_glx_pixmap pixmap;
      struct apple_glx_pbuffer pbuffer;
      struct apple_glx_surface surface;
   } types;

   struct apple_glx_drawable_callbacks callbacks;

   /* 
    * This mutex protects the reference count and any other drawable data.
    * It's used to prevent an early release of a drawable.
    */
   pthread_mutex_t mutex;
   void (*lock) (struct apple_glx_drawable * agd);
   void (*unlock) (struct apple_glx_drawable * agd);

   void (*reference) (struct apple_glx_drawable * agd);
   void (*release) (struct apple_glx_drawable * agd);

     bool(*destroy) (struct apple_glx_drawable * agd);

     bool(*is_pbuffer) (struct apple_glx_drawable * agd);

     bool(*is_pixmap) (struct apple_glx_drawable * agd);

/*BEGIN These are used for the mixed mode drawing... */
   int width, height;
   int row_bytes;
   char path[PATH_MAX];
   int fd;                      /* The file descriptor for this drawable's shared memory. */
   void *buffer;                /* The memory for the drawable.  Typically shared memory. */
   size_t buffer_length;
     /*END*/ struct apple_glx_drawable *previous, *next;
};

struct apple_glx_context;

/* May return NULL if not found */
struct apple_glx_drawable *apple_glx_find_drawable(Display * dpy,
                                                   GLXDrawable drawable);

/* Returns true on error and locks the agd result with a reference. */
bool apple_glx_drawable_create(Display * dpy,
                               int screen,
                               GLXDrawable drawable,
                               struct apple_glx_drawable **agd,
                               struct apple_glx_drawable_callbacks
                               *callbacks);

/* Returns true on error */
bool apple_glx_create_drawable(Display * dpy,
                               struct apple_glx_context *ac,
                               GLXDrawable drawable,
                               struct apple_glx_drawable **agd);

void apple_glx_garbage_collect_drawables(Display * dpy);

/* 
 * This returns the total number of drawables. 
 * It's mostly intended for debugging and introspection.
 */
unsigned int apple_glx_get_drawable_count(void);

struct apple_glx_drawable *apple_glx_drawable_find_by_type(GLXDrawable
                                                           drawable, int type,
                                                           int flags);

struct apple_glx_drawable *apple_glx_drawable_find(GLXDrawable drawable,
                                                   int flags);


bool apple_glx_drawable_destroy_by_type(Display * dpy, GLXDrawable drawable,
                                        int type);

struct apple_glx_drawable *apple_glx_drawable_find_by_uid(unsigned int uid,
                                                          int flags);

/* Surfaces */

bool apple_glx_surface_create(Display * dpy, int screen, GLXDrawable drawable,
                              struct apple_glx_drawable **resultptr);

void apple_glx_surface_destroy(unsigned int uid);

/* Pbuffers */

/* Returns true if an error occurred. */
bool apple_glx_pbuffer_create(Display * dpy, GLXFBConfig config,
                              int width, int height, int *errorcode,
                              GLXPbuffer * pbuf);

/* Returns true if the pbuffer was invalid. */
bool apple_glx_pbuffer_destroy(Display * dpy, GLXPbuffer pbuf);

/* Returns true if the pbuffer was valid and the attribute. */
bool apple_glx_pbuffer_query(GLXDrawable d, int attribute,
                             unsigned int *value);

/* Returns true if the GLXDrawable is a valid GLXPbuffer, and the mask is set. */
bool apple_glx_pbuffer_set_event_mask(GLXDrawable d, unsigned long mask);

/* Returns true if the GLXDrawable is a valid GLXPbuffer, and the *mask is set. */
bool apple_glx_pbuffer_get_event_mask(GLXDrawable d, unsigned long *mask);


/* Pixmaps */

/* mode is a __GLcontextModes * */
/* Returns true if an error occurred. */
bool apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,
                             const void *mode);

/* Returns true if an error occurred. */
bool apple_glx_pixmap_destroy(Display * dpy, Pixmap pixmap);

bool apple_glx_pixmap_query(GLXPixmap pixmap, int attribute,
                            unsigned int *value);



#endif