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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
/*
* Copyright © 2004 David Reveman, Peter Nilsson
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the names of
* David Reveman and Peter Nilsson not be used in advertising or
* publicity pertaining to distribution of the software without
* specific, written prior permission. David Reveman and Peter Nilsson
* makes no representations about the suitability of this software for
* any purpose. It is provided "as is" without express or implied warranty.
*
* DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND
* PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
* OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Authors: David Reveman <c99drn@cs.umu.se>
* Peter Nilsson <c99pnn@cs.umu.se>
*/
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif
#include "glitz_glxint.h"
static glitz_bool_t
_glitz_glx_surface_push_current (void *abstract_surface,
glitz_constraint_t constraint)
{
glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface;
glitz_bool_t success = 1;
if (constraint == GLITZ_CN_SURFACE_DRAWABLE_CURRENT &&
(!surface->drawable)) {
if (surface->base.format->draw.offscreen) {
surface->drawable = surface->pbuffer =
glitz_glx_pbuffer_create (surface->screen_info,
surface->context->fbconfig,
&surface->base.texture);
} else {
constraint = GLITZ_CN_ANY_CONTEXT_CURRENT;
success = 0;
}
}
surface = glitz_glx_context_push_current (surface, constraint);
if (surface) {
glitz_surface_update_state (&surface->base);
return 1;
}
return success;
}
static void
_glitz_glx_surface_pop_current (void *abstract_surface)
{
glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface;
surface = glitz_glx_context_pop_current (surface);
if (surface)
glitz_surface_update_state (&surface->base);
}
static glitz_bool_t
_glitz_glx_surface_make_current_read (void *abstract_surface)
{
/* This doesn't seem to work.
glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface;
glitz_glx_static_proc_address_list_t *glx =
&surface->screen_info->display_info->thread_info->glx;
if ((screen_info->glx_feature_mask &
GLITZ_GLX_FEATURE_GLX_MAKE_CURRENT_READ_MASK) && surface->drawable) {
GLXContext context = glXGetCurrentContext ();
if (context == surface->context->context)
return
glx->make_context_current (surface->screen_info->display_info->display,
glXGetCurrentDrawable (),
surface->drawable,
context);
}
*/
return 0;
}
static glitz_texture_t *
_glitz_glx_surface_get_texture (void *abstract_surface,
glitz_bool_t allocate)
{
glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface;
if (surface->base.flags & GLITZ_SURFACE_FLAG_DIRTY_MASK) {
glitz_bounding_box_t copy_box;
copy_box.x1 = copy_box.y1 = 0;
copy_box.x2 = surface->base.width;
copy_box.y2 = surface->base.height;
glitz_intersect_bounding_box (&surface->base.dirty_box,
©_box, ©_box);
if (!(TEXTURE_ALLOCATED (&surface->base.texture)))
glitz_texture_allocate (&surface->base.backend->gl,
&surface->base.texture);
glitz_texture_copy_surface (&surface->base.texture, &surface->base,
copy_box.x1,
copy_box.y1,
copy_box.x2 - copy_box.x1,
copy_box.y2 - copy_box.y1,
copy_box.x1,
copy_box.y1);
surface->base.flags &= ~GLITZ_SURFACE_FLAG_DIRTY_MASK;
}
if (allocate) {
if (!(TEXTURE_ALLOCATED (&surface->base.texture)))
glitz_texture_allocate (&surface->base.backend->gl,
&surface->base.texture);
}
if (TEXTURE_ALLOCATED (&surface->base.texture))
return &surface->base.texture;
else
return NULL;
}
static glitz_surface_t *
_glitz_glx_surface_create (glitz_glx_screen_info_t *screen_info,
glitz_format_t *format,
int width,
int height)
{
glitz_glx_surface_t *surface;
glitz_glx_context_t *context;
if (width <= 0 || height <= 0)
return NULL;
context = glitz_glx_context_get (screen_info, format);
if (!context)
return NULL;
surface = (glitz_glx_surface_t *) calloc (1, sizeof (glitz_glx_surface_t));
if (surface == NULL)
return NULL;
glitz_surface_init (&surface->base,
&context->backend,
format,
width,
height);
surface->screen_info = screen_info;
surface->context = context;
surface->base.flags |= GLITZ_SURFACE_FLAG_OFFSCREEN_MASK;
if (format->draw.offscreen)
surface->base.flags |= GLITZ_SURFACE_FLAG_DRAWABLE_MASK;
if (surface->context->backend.gl.need_lookup) {
glitz_glx_context_push_current (surface, GLITZ_CN_SURFACE_CONTEXT_CURRENT);
glitz_glx_context_pop_current (surface);
}
if (width > 64 || height > 64) {
glitz_glx_context_push_current (surface, GLITZ_CN_ANY_CONTEXT_CURRENT);
glitz_texture_size_check (&surface->base.backend->gl,
&surface->base.texture,
context->max_texture_2d_size,
context->max_texture_rect_size);
glitz_glx_context_pop_current (surface);
if (TEXTURE_INVALID_SIZE (&surface->base.texture) ||
(format->draw.offscreen &&
((width > context->max_viewport_dims[0]) ||
(height > context->max_viewport_dims[1])))) {
glitz_surface_destroy (&surface->base);
return NULL;
}
}
return &surface->base;
}
glitz_surface_t *
glitz_glx_surface_create (Display *display,
int screen,
glitz_format_t *format,
int width,
int height)
{
glitz_glx_screen_info_t *screen_info;
screen_info = glitz_glx_screen_info_get (display, screen);
if (!screen_info)
return NULL;
return _glitz_glx_surface_create (screen_info, format, width, height);
}
slim_hidden_def(glitz_glx_surface_create);
glitz_surface_t *
glitz_glx_surface_create_for_window (Display *display,
int screen,
glitz_format_t *format,
Window window,
int width,
int height)
{
glitz_glx_surface_t *surface;
glitz_glx_context_t *context;
glitz_glx_screen_info_t *screen_info;
if (width <= 0 || height <= 0)
return NULL;
screen_info = glitz_glx_screen_info_get (display, screen);
if (!screen_info)
return NULL;
context = glitz_glx_context_get (screen_info, format);
if (!context)
return NULL;
surface = (glitz_glx_surface_t *) calloc (1, sizeof (glitz_glx_surface_t));
if (surface == NULL)
return NULL;
glitz_surface_init (&surface->base,
&context->backend,
format,
width,
height);
surface->screen_info = screen_info;
surface->context = context;
surface->drawable = window;
surface->base.flags |= GLITZ_SURFACE_FLAG_DRAWABLE_MASK;
if (surface->context->backend.gl.need_lookup) {
glitz_glx_context_push_current (surface, GLITZ_CN_SURFACE_CONTEXT_CURRENT);
glitz_glx_context_pop_current (surface);
}
if (width > 64 || height > 64) {
glitz_glx_context_push_current (surface, GLITZ_CN_ANY_CONTEXT_CURRENT);
glitz_texture_size_check (&surface->base.backend->gl,
&surface->base.texture,
context->max_texture_2d_size,
context->max_texture_rect_size);
glitz_glx_context_pop_current (surface);
if (TEXTURE_INVALID_SIZE (&surface->base.texture) ||
(width > context->max_viewport_dims[0]) ||
(height > context->max_viewport_dims[1])) {
glitz_surface_destroy (&surface->base);
return NULL;
}
}
return &surface->base;
}
slim_hidden_def(glitz_glx_surface_create_for_window);
static glitz_surface_t *
_glitz_glx_surface_create_similar (void *abstract_templ,
glitz_format_t *format,
int width,
int height)
{
glitz_glx_surface_t *templ = (glitz_glx_surface_t *) abstract_templ;
if (!format->read.offscreen)
return NULL;
return _glitz_glx_surface_create (templ->screen_info, format, width, height);
}
static void
_glitz_glx_surface_destroy (void *abstract_surface)
{
glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface;
glitz_surface_fini (&surface->base);
if (surface->drawable &&
(glXGetCurrentDrawable () == surface->drawable)) {
surface->drawable = None;
glitz_glx_context_make_current (surface, (GLXContext) 0, 0);
}
if (surface->pbuffer)
glitz_glx_pbuffer_destroy (surface->screen_info, surface->pbuffer);
free (surface);
}
static void
_glitz_glx_surface_swap_buffers (void *abstract_surface)
{
glitz_glx_surface_t *surface = (glitz_glx_surface_t *) abstract_surface;
if (surface->pbuffer || (!surface->drawable))
return;
glitz_glx_context_push_current (surface, GLITZ_CN_SURFACE_DRAWABLE_CURRENT);
glXSwapBuffers (surface->screen_info->display_info->display,
surface->drawable);
glitz_glx_context_pop_current (surface);
}
void
glitz_glx_surface_backend_init (glitz_surface_backend_t *backend)
{
backend->create_similar = _glitz_glx_surface_create_similar;
backend->destroy = _glitz_glx_surface_destroy;
backend->push_current = _glitz_glx_surface_push_current;
backend->pop_current = _glitz_glx_surface_pop_current;
backend->get_texture = _glitz_glx_surface_get_texture;
backend->swap_buffers = _glitz_glx_surface_swap_buffers;
backend->make_current_read = _glitz_glx_surface_make_current_read;
}
|