2
Copyright (c) 2009 Apple Inc.
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:
12
The above copyright notice and this permission notice shall be
13
included in all copies or substantial portions of the Software.
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.
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.
34
#include <sys/types.h>
38
#include "apple_glx.h"
39
#include "apple_cgl.h"
40
#include "apple_visual.h"
41
#include "apple_glx_drawable.h"
43
#include "glcontextmodes.h"
45
static bool pixmap_make_current(struct apple_glx_context *ac,
46
struct apple_glx_drawable *d);
48
static void pixmap_destroy(Display * dpy, struct apple_glx_drawable *d);
50
static struct apple_glx_drawable_callbacks callbacks = {
51
.type = APPLE_GLX_DRAWABLE_PIXMAP,
52
.make_current = pixmap_make_current,
53
.destroy = pixmap_destroy
57
pixmap_make_current(struct apple_glx_context *ac,
58
struct apple_glx_drawable *d)
61
struct apple_glx_pixmap *p = &d->types.pixmap;
63
assert(APPLE_GLX_DRAWABLE_PIXMAP == d->type);
65
cglerr = apple_cgl.set_current_context(p->context_obj);
67
if (kCGLNoError != cglerr) {
68
fprintf(stderr, "set current context: %s\n",
69
apple_cgl.error_string(cglerr));
73
cglerr = apple_cgl.set_off_screen(p->context_obj, p->width, p->height,
76
if (kCGLNoError != cglerr) {
77
fprintf(stderr, "set off screen: %s\n", apple_cgl.error_string(cglerr));
82
if (!ac->made_current) {
83
glViewport(0, 0, p->width, p->height);
84
glScissor(0, 0, p->width, p->height);
85
ac->made_current = true;
92
pixmap_destroy(Display * dpy, struct apple_glx_drawable *d)
94
struct apple_glx_pixmap *p = &d->types.pixmap;
96
if (p->pixel_format_obj)
97
(void) apple_cgl.destroy_pixel_format(p->pixel_format_obj);
100
(void) apple_cgl.destroy_context(p->context_obj);
102
XAppleDRIDestroyPixmap(dpy, p->xpixmap);
105
if (munmap(p->buffer, p->size))
108
if (-1 == close(p->fd))
111
if (shm_unlink(p->path))
112
perror("shm_unlink");
115
apple_glx_diagnostic("destroyed pixmap buffer for: 0x%lx\n", d->drawable);
118
/* Return true if an error occurred. */
120
apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap,
123
struct apple_glx_drawable *d;
124
struct apple_glx_pixmap *p;
125
bool double_buffered;
128
const struct glx_config *cmodes = mode;
130
if (apple_glx_drawable_create(dpy, screen, pixmap, &d, &callbacks))
133
/* d is locked and referenced at this point. */
135
p = &d->types.pixmap;
140
if (!XAppleDRICreatePixmap(dpy, screen, pixmap,
141
&p->width, &p->height, &p->pitch, &p->bpp,
142
&p->size, p->path, PATH_MAX)) {
148
p->fd = shm_open(p->path, O_RDWR, 0);
157
p->buffer = mmap(NULL, p->size, PROT_READ | PROT_WRITE,
158
MAP_FILE | MAP_SHARED, p->fd, 0);
160
if (MAP_FAILED == p->buffer) {
167
apple_visual_create_pfobj(&p->pixel_format_obj, mode, &double_buffered,
168
&uses_stereo, /*offscreen */ true);
170
error = apple_cgl.create_context(p->pixel_format_obj, NULL,
173
if (kCGLNoError != error) {
179
p->fbconfigID = cmodes->fbconfigID;
183
apple_glx_diagnostic("created: pixmap buffer for 0x%lx\n", d->drawable);
189
apple_glx_pixmap_query(GLXPixmap pixmap, int attr, unsigned int *value)
191
struct apple_glx_drawable *d;
192
struct apple_glx_pixmap *p;
195
d = apple_glx_drawable_find_by_type(pixmap, APPLE_GLX_DRAWABLE_PIXMAP,
196
APPLE_GLX_DRAWABLE_LOCK);
199
p = &d->types.pixmap;
212
case GLX_FBCONFIG_ID:
213
*value = p->fbconfigID;
224
/* Return true if the type is valid for pixmap. */
226
apple_glx_pixmap_destroy(Display * dpy, GLXPixmap pixmap)
228
return !apple_glx_drawable_destroy_by_type(dpy, pixmap,
229
APPLE_GLX_DRAWABLE_PIXMAP);