~gnome3-team/mutter/trunk

« back to all changes in this revision

Viewing changes to cogl/cogl/cogl-onscreen.h

  • Committer: Rui Matos
  • Date: 2016-04-27 16:36:25 UTC
  • mfrom: (0.87.3184)
  • Revision ID: git-v1:3fcbe1d3ec5c9208dde080f7e9dac24e4c379bc0
Merge cogl's cogl-1.22 branch into mutter

https://bugzilla.gnome.org/show_bug.cgi?id=760439

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Cogl
 
3
 *
 
4
 * A Low Level GPU Graphics and Utilities API
 
5
 *
 
6
 * Copyright (C) 2011,2012,2013 Intel Corporation.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person
 
9
 * obtaining a copy of this software and associated documentation
 
10
 * files (the "Software"), to deal in the Software without
 
11
 * restriction, including without limitation the rights to use, copy,
 
12
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 
13
 * of the Software, and to permit persons to whom the Software is
 
14
 * furnished to do so, subject to the following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be
 
17
 * included in all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
22
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
23
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
24
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
25
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
26
 * SOFTWARE.
 
27
 *
 
28
 *
 
29
 *
 
30
 * Authors:
 
31
 *   Robert Bragg <robert@linux.intel.com>
 
32
 */
 
33
 
 
34
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
 
35
#error "Only <cogl/cogl.h> can be included directly."
 
36
#endif
 
37
 
 
38
#ifndef __COGL_ONSCREEN_H
 
39
#define __COGL_ONSCREEN_H
 
40
 
 
41
#include <cogl/cogl-context.h>
 
42
#include <cogl/cogl-framebuffer.h>
 
43
#include <cogl/cogl-frame-info.h>
 
44
#include <cogl/cogl-object.h>
 
45
 
 
46
#ifdef COGL_HAS_GTYPE_SUPPORT
 
47
#include <glib-object.h>
 
48
#endif
 
49
 
 
50
COGL_BEGIN_DECLS
 
51
 
 
52
typedef struct _CoglOnscreen CoglOnscreen;
 
53
#define COGL_ONSCREEN(X) ((CoglOnscreen *)(X))
 
54
 
 
55
#ifdef COGL_HAS_GTYPE_SUPPORT
 
56
/**
 
57
 * cogl_onscreen_get_gtype:
 
58
 *
 
59
 * Returns: a #GType that can be used with the GLib type system.
 
60
 */
 
61
GType cogl_onscreen_get_gtype (void);
 
62
#endif
 
63
 
 
64
/**
 
65
 * cogl_onscreen_new: (constructor)
 
66
 * @context: A #CoglContext
 
67
 * @width: The desired framebuffer width
 
68
 * @height: The desired framebuffer height
 
69
 *
 
70
 * Instantiates an "unallocated" #CoglOnscreen framebuffer that may be
 
71
 * configured before later being allocated, either implicitly when
 
72
 * it is first used or explicitly via cogl_framebuffer_allocate().
 
73
 *
 
74
 * Return value: (transfer full): A newly instantiated #CoglOnscreen framebuffer
 
75
 * Since: 1.8
 
76
 * Stability: unstable
 
77
 */
 
78
CoglOnscreen *
 
79
cogl_onscreen_new (CoglContext *context, int width, int height);
 
80
 
 
81
#ifdef COGL_HAS_X11
 
82
typedef void (*CoglOnscreenX11MaskCallback) (CoglOnscreen *onscreen,
 
83
                                             uint32_t event_mask,
 
84
                                             void *user_data);
 
85
 
 
86
/**
 
87
 * cogl_x11_onscreen_set_foreign_window_xid:
 
88
 * @onscreen: The unallocated framebuffer to associated with an X
 
89
 *            window.
 
90
 * @xid: The XID of an existing X window
 
91
 * @update: A callback that notifies of updates to what Cogl requires
 
92
 *          to be in the core X protocol event mask.
 
93
 * @user_data: user data passed to @update
 
94
 *
 
95
 * Ideally we would recommend that you let Cogl be responsible for
 
96
 * creating any X window required to back an onscreen framebuffer but
 
97
 * if you really need to target a window created manually this
 
98
 * function can be called before @onscreen has been allocated to set a
 
99
 * foreign XID for your existing X window.
 
100
 *
 
101
 * Since Cogl needs, for example, to track changes to the size of an X
 
102
 * window it requires that certain events be selected for via the core
 
103
 * X protocol. This requirement may also be changed asynchronously so
 
104
 * you must pass in an @update callback to inform you of Cogl's
 
105
 * required event mask.
 
106
 *
 
107
 * For example if you are using Xlib you could use this API roughly
 
108
 * as follows:
 
109
 * [{
 
110
 * static void
 
111
 * my_update_cogl_x11_event_mask (CoglOnscreen *onscreen,
 
112
 *                                uint32_t event_mask,
 
113
 *                                void *user_data)
 
114
 * {
 
115
 *   XSetWindowAttributes attrs;
 
116
 *   MyData *data = user_data;
 
117
 *   attrs.event_mask = event_mask | data->my_event_mask;
 
118
 *   XChangeWindowAttributes (data->xdpy,
 
119
 *                            data->xwin,
 
120
 *                            CWEventMask,
 
121
 *                            &attrs);
 
122
 * }
 
123
 *
 
124
 * {
 
125
 *   *snip*
 
126
 *   cogl_x11_onscreen_set_foreign_window_xid (onscreen,
 
127
 *                                             data->xwin,
 
128
 *                                             my_update_cogl_x11_event_mask,
 
129
 *                                             data);
 
130
 *   *snip*
 
131
 * }
 
132
 * }]
 
133
 *
 
134
 * Since: 2.0
 
135
 * Stability: Unstable
 
136
 */
 
137
void
 
138
cogl_x11_onscreen_set_foreign_window_xid (CoglOnscreen *onscreen,
 
139
                                          uint32_t xid,
 
140
                                          CoglOnscreenX11MaskCallback update,
 
141
                                          void *user_data);
 
142
 
 
143
/**
 
144
 * cogl_x11_onscreen_get_window_xid:
 
145
 * @onscreen: A #CoglOnscreen framebuffer
 
146
 *
 
147
 * Assuming you know the given @onscreen framebuffer is based on an x11 window
 
148
 * this queries the XID of that window. If
 
149
 * cogl_x11_onscreen_set_foreign_window_xid() was previously called then it
 
150
 * will return that same XID otherwise it will be the XID of a window Cogl
 
151
 * created internally. If the window has not been allocated yet and a foreign
 
152
 * xid has not been set then it's undefined what value will be returned.
 
153
 *
 
154
 * It's undefined what this function does if called when not using an x11 based
 
155
 * renderer.
 
156
 *
 
157
 * Since: 1.10
 
158
 * Stability: unstable
 
159
 */
 
160
uint32_t
 
161
cogl_x11_onscreen_get_window_xid (CoglOnscreen *onscreen);
 
162
 
 
163
/* XXX: we should maybe remove this, since nothing currently uses
 
164
 * it and the current implementation looks dubious. */
 
165
uint32_t
 
166
cogl_x11_onscreen_get_visual_xid (CoglOnscreen *onscreen);
 
167
#endif /* COGL_HAS_X11 */
 
168
 
 
169
/**
 
170
 * cogl_onscreen_set_swap_throttled:
 
171
 * @onscreen: A #CoglOnscreen framebuffer
 
172
 * @throttled: Whether swap throttling is wanted or not.
 
173
 *
 
174
 * Requests that the given @onscreen framebuffer should have swap buffer
 
175
 * requests (made using cogl_onscreen_swap_buffers()) throttled either by a
 
176
 * displays vblank period or perhaps some other mechanism in a composited
 
177
 * environment.
 
178
 *
 
179
 * Since: 1.8
 
180
 * Stability: unstable
 
181
 */
 
182
void
 
183
cogl_onscreen_set_swap_throttled (CoglOnscreen *onscreen,
 
184
                                  CoglBool throttled);
 
185
 
 
186
/**
 
187
 * cogl_onscreen_show:
 
188
 * @onscreen: The onscreen framebuffer to make visible
 
189
 *
 
190
 * This requests to make @onscreen visible to the user.
 
191
 *
 
192
 * Actually the precise semantics of this function depend on the
 
193
 * window system currently in use, and if you don't have a
 
194
 * multi-windowining system this function may in-fact do nothing.
 
195
 *
 
196
 * This function will implicitly allocate the given @onscreen
 
197
 * framebuffer before showing it if it hasn't already been allocated.
 
198
 *
 
199
 * When using the Wayland winsys calling this will set the surface to
 
200
 * a toplevel type which will make it appear. If the application wants
 
201
 * to set a different type for the surface, it can avoid calling
 
202
 * cogl_onscreen_show() and set its own type directly with the Wayland
 
203
 * client API via cogl_wayland_onscreen_get_surface().
 
204
 *
 
205
 * <note>Since Cogl doesn't explicitly track the visibility status of
 
206
 * onscreen framebuffers it wont try to avoid redundant window system
 
207
 * requests e.g. to show an already visible window. This also means
 
208
 * that it's acceptable to alternatively use native APIs to show and
 
209
 * hide windows without confusing Cogl.</note>
 
210
 *
 
211
 * Since: 2.0
 
212
 * Stability: Unstable
 
213
 */
 
214
void
 
215
cogl_onscreen_show (CoglOnscreen *onscreen);
 
216
 
 
217
/**
 
218
 * cogl_onscreen_hide:
 
219
 * @onscreen: The onscreen framebuffer to make invisible
 
220
 *
 
221
 * This requests to make @onscreen invisible to the user.
 
222
 *
 
223
 * Actually the precise semantics of this function depend on the
 
224
 * window system currently in use, and if you don't have a
 
225
 * multi-windowining system this function may in-fact do nothing.
 
226
 *
 
227
 * This function does not implicitly allocate the given @onscreen
 
228
 * framebuffer before hiding it.
 
229
 *
 
230
 * <note>Since Cogl doesn't explicitly track the visibility status of
 
231
 * onscreen framebuffers it wont try to avoid redundant window system
 
232
 * requests e.g. to show an already visible window. This also means
 
233
 * that it's acceptable to alternatively use native APIs to show and
 
234
 * hide windows without confusing Cogl.</note>
 
235
 *
 
236
 * Since: 2.0
 
237
 * Stability: Unstable
 
238
 */
 
239
void
 
240
cogl_onscreen_hide (CoglOnscreen *onscreen);
 
241
 
 
242
/**
 
243
 * cogl_onscreen_swap_buffers:
 
244
 * @onscreen: A #CoglOnscreen framebuffer
 
245
 *
 
246
 * Swaps the current back buffer being rendered too, to the front for display.
 
247
 *
 
248
 * This function also implicitly discards the contents of the color, depth and
 
249
 * stencil buffers as if cogl_framebuffer_discard_buffers() were used. The
 
250
 * significance of the discard is that you should not expect to be able to
 
251
 * start a new frame that incrementally builds on the contents of the previous
 
252
 * frame.
 
253
 *
 
254
 * <note>It is highly recommended that applications use
 
255
 * cogl_onscreen_swap_buffers_with_damage() instead whenever possible
 
256
 * and also use the cogl_onscreen_get_buffer_age() api so they can
 
257
 * perform incremental updates to older buffers instead of having to
 
258
 * render a full buffer for every frame.</note>
 
259
 *
 
260
 * Since: 1.10
 
261
 * Stability: unstable
 
262
 */
 
263
void
 
264
cogl_onscreen_swap_buffers (CoglOnscreen *onscreen);
 
265
 
 
266
 
 
267
/**
 
268
 * cogl_onscreen_get_buffer_age:
 
269
 * @onscreen: A #CoglOnscreen framebuffer
 
270
 *
 
271
 * Gets the current age of the buffer contents.
 
272
 *
 
273
 * This function allows applications to query the age of the current
 
274
 * back buffer contents for a #CoglOnscreen as the number of frames
 
275
 * elapsed since the contents were most recently defined.
 
276
 *
 
277
 * These age values exposes enough information to applications about
 
278
 * how Cogl internally manages back buffers to allow applications to
 
279
 * re-use the contents of old frames and minimize how much must be
 
280
 * redrawn for the next frame.
 
281
 *
 
282
 * The back buffer contents can either be reported as invalid (has an
 
283
 * age of 0) or it may be reported to be the same contents as from n
 
284
 * frames prior to the current frame.
 
285
 *
 
286
 * The queried value remains valid until the next buffer swap.
 
287
 *
 
288
 * <note>One caveat is that under X11 the buffer age does not reflect
 
289
 * changes to buffer contents caused by the window systems. X11
 
290
 * applications must track Expose events to determine what buffer
 
291
 * regions need to additionally be repaired each frame.</note>
 
292
 *
 
293
 * The recommended way to take advantage of this buffer age api is to
 
294
 * build up a circular buffer of length 3 for tracking damage regions
 
295
 * over the last 3 frames and when starting a new frame look at the
 
296
 * age of the buffer and combine the damage regions for the current
 
297
 * frame with the damage regions of previous @age frames so you know
 
298
 * everything that must be redrawn to update the old contents for the
 
299
 * new frame.
 
300
 *
 
301
 * <note>If the system doesn't not support being able to track the age
 
302
 * of back buffers then this function will always return 0 which
 
303
 * implies that the contents are undefined.</note>
 
304
 *
 
305
 * <note>The %COGL_FEATURE_ID_BUFFER_AGE feature can optionally be
 
306
 * explicitly checked to determine if Cogl is currently tracking the
 
307
 * age of #CoglOnscreen back buffer contents. If this feature is
 
308
 * missing then this function will always return 0.</note>
 
309
 *
 
310
 * Return value: The age of the buffer contents or 0 when the buffer
 
311
 *               contents are undefined.
 
312
 *
 
313
 * Since: 1.14
 
314
 * Stability: stable
 
315
 */
 
316
int
 
317
cogl_onscreen_get_buffer_age (CoglOnscreen *onscreen);
 
318
 
 
319
/**
 
320
 * cogl_onscreen_swap_buffers_with_damage:
 
321
 * @onscreen: A #CoglOnscreen framebuffer
 
322
 * @rectangles: An array of integer 4-tuples representing damaged
 
323
 *              rectangles as (x, y, width, height) tuples.
 
324
 * @n_rectangles: The number of 4-tuples to be read from @rectangles
 
325
 *
 
326
 * Swaps the current back buffer being rendered too, to the front for
 
327
 * display and provides information to any system compositor about
 
328
 * what regions of the buffer have changed (damage) with respect to
 
329
 * the last swapped buffer.
 
330
 *
 
331
 * This function has the same semantics as
 
332
 * cogl_framebuffer_swap_buffers() except that it additionally allows
 
333
 * applications to pass a list of damaged rectangles which may be
 
334
 * passed on to a compositor so that it can minimize how much of the
 
335
 * screen is redrawn in response to this applications newly swapped
 
336
 * front buffer.
 
337
 *
 
338
 * For example if your application is only animating a small object in
 
339
 * the corner of the screen and everything else is remaining static
 
340
 * then it can help the compositor to know that only the bottom right
 
341
 * corner of your newly swapped buffer has really changed with respect
 
342
 * to your previously swapped front buffer.
 
343
 *
 
344
 * If @n_rectangles is 0 then the whole buffer will implicitly be
 
345
 * reported as damaged as if cogl_onscreen_swap_buffers() had been
 
346
 * called.
 
347
 *
 
348
 * This function also implicitly discards the contents of the color,
 
349
 * depth and stencil buffers as if cogl_framebuffer_discard_buffers()
 
350
 * were used. The significance of the discard is that you should not
 
351
 * expect to be able to start a new frame that incrementally builds on
 
352
 * the contents of the previous frame. If you want to perform
 
353
 * incremental updates to older back buffers then please refer to the
 
354
 * cogl_onscreen_get_buffer_age() api.
 
355
 *
 
356
 * Whenever possible it is recommended that applications use this
 
357
 * function instead of cogl_onscreen_swap_buffers() to improve
 
358
 * performance when running under a compositor.
 
359
 *
 
360
 * <note>It is highly recommended to use this API in conjunction with
 
361
 * the cogl_onscreen_get_buffer_age() api so that your application can
 
362
 * perform incremental rendering based on old back buffers.</note>
 
363
 *
 
364
 * Since: 1.16
 
365
 * Stability: unstable
 
366
 */
 
367
void
 
368
cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
 
369
                                        const int *rectangles,
 
370
                                        int n_rectangles);
 
371
 
 
372
/**
 
373
 * cogl_onscreen_swap_region:
 
374
 * @onscreen: A #CoglOnscreen framebuffer
 
375
 * @rectangles: An array of integer 4-tuples representing rectangles as
 
376
 *              (x, y, width, height) tuples.
 
377
 * @n_rectangles: The number of 4-tuples to be read from @rectangles
 
378
 *
 
379
 * Swaps a region of the back buffer being rendered too, to the front for
 
380
 * display.  @rectangles represents the region as array of @n_rectangles each
 
381
 * defined by 4 sequential (x, y, width, height) integers.
 
382
 *
 
383
 * This function also implicitly discards the contents of the color, depth and
 
384
 * stencil buffers as if cogl_framebuffer_discard_buffers() were used. The
 
385
 * significance of the discard is that you should not expect to be able to
 
386
 * start a new frame that incrementally builds on the contents of the previous
 
387
 * frame.
 
388
 *
 
389
 * Since: 1.10
 
390
 * Stability: unstable
 
391
 */
 
392
void
 
393
cogl_onscreen_swap_region (CoglOnscreen *onscreen,
 
394
                           const int *rectangles,
 
395
                           int n_rectangles);
 
396
 
 
397
/**
 
398
 * CoglFrameEvent:
 
399
 * @COGL_FRAME_EVENT_SYNC: Notifies that the system compositor has
 
400
 *                         acknowledged a frame and is ready for a
 
401
 *                         new frame to be created.
 
402
 * @COGL_FRAME_EVENT_COMPLETE: Notifies that a frame has ended. This
 
403
 *                             is a good time for applications to
 
404
 *                             collect statistics about the frame
 
405
 *                             since the #CoglFrameInfo should hold
 
406
 *                             the most data at this point. No other
 
407
 *                             events should be expected after a
 
408
 *                             @COGL_FRAME_EVENT_COMPLETE event.
 
409
 *
 
410
 * Identifiers that are passed to #CoglFrameCallback functions
 
411
 * (registered using cogl_onscreen_add_frame_callback()) that
 
412
 * mark the progression of a frame in some way which usually
 
413
 * means that new information will have been accumulated in the
 
414
 * frame's corresponding #CoglFrameInfo object.
 
415
 *
 
416
 * The last event that will be sent for a frame will be a
 
417
 * @COGL_FRAME_EVENT_COMPLETE event and so these are a good
 
418
 * opportunity to collect statistics about a frame since the
 
419
 * #CoglFrameInfo should hold the most data at this point.
 
420
 *
 
421
 * <note>A frame may not be completed before the next frame can start
 
422
 * so applications should avoid needing to collect all statistics for
 
423
 * a particular frame before they can start a new frame.</note>
 
424
 *
 
425
 * Since: 1.14
 
426
 * Stability: unstable
 
427
 */
 
428
typedef enum _CoglFrameEvent
 
429
{
 
430
  COGL_FRAME_EVENT_SYNC = 1,
 
431
  COGL_FRAME_EVENT_COMPLETE
 
432
} CoglFrameEvent;
 
433
 
 
434
/**
 
435
 * CoglFrameCallback:
 
436
 * @onscreen: The onscreen that the frame is associated with
 
437
 * @event: A #CoglFrameEvent notifying how the frame has progressed
 
438
 * @info: The meta information, such as timing information, about
 
439
 *        the frame that has progressed.
 
440
 * @user_data: The user pointer passed to
 
441
 *             cogl_onscreen_add_frame_callback()
 
442
 *
 
443
 * Is a callback that can be registered via
 
444
 * cogl_onscreen_add_frame_callback() to be called when a frame
 
445
 * progresses in some notable way.
 
446
 *
 
447
 * Please see the documentation for #CoglFrameEvent and
 
448
 * cogl_onscreen_add_frame_callback() for more details about what
 
449
 * events can be notified.
 
450
 *
 
451
 * Since: 1.14
 
452
 * Stability: unstable
 
453
 */
 
454
typedef void (*CoglFrameCallback) (CoglOnscreen *onscreen,
 
455
                                   CoglFrameEvent event,
 
456
                                   CoglFrameInfo *info,
 
457
                                   void *user_data);
 
458
 
 
459
/**
 
460
 * CoglFrameClosure:
 
461
 *
 
462
 * An opaque type that tracks a #CoglFrameCallback and associated user
 
463
 * data. A #CoglFrameClosure pointer will be returned from
 
464
 * cogl_onscreen_add_frame_callback() and it allows you to remove a
 
465
 * callback later using cogl_onscreen_remove_frame_callback().
 
466
 *
 
467
 * Since: 1.14
 
468
 * Stability: unstable
 
469
 */
 
470
typedef struct _CoglClosure CoglFrameClosure;
 
471
 
 
472
#ifdef COGL_HAS_GTYPE_SUPPORT
 
473
/**
 
474
 * cogl_frame_closure_get_gtype:
 
475
 *
 
476
 * Returns: a #GType that can be used with the GLib type system.
 
477
 */
 
478
GType cogl_frame_closure_get_gtype (void);
 
479
#endif
 
480
 
 
481
/**
 
482
 * cogl_onscreen_add_frame_callback:
 
483
 * @onscreen: A #CoglOnscreen framebuffer
 
484
 * @callback: (scope notified): A callback function to call for frame events
 
485
 * @user_data: (closure): A private pointer to be passed to @callback
 
486
 * @destroy: (allow-none): An optional callback to destroy @user_data
 
487
 *           when the @callback is removed or @onscreen is freed.
 
488
 *
 
489
 * Installs a @callback function that will be called for significant
 
490
 * events relating to the given @onscreen framebuffer.
 
491
 *
 
492
 * The @callback will be used to notify when the system compositor is
 
493
 * ready for this application to render a new frame. In this case
 
494
 * %COGL_FRAME_EVENT_SYNC will be passed as the event argument to the
 
495
 * given @callback in addition to the #CoglFrameInfo corresponding to
 
496
 * the frame beeing acknowledged by the compositor.
 
497
 *
 
498
 * The @callback will also be called to notify when the frame has
 
499
 * ended. In this case %COGL_FRAME_EVENT_COMPLETE will be passed as
 
500
 * the event argument to the given @callback in addition to the
 
501
 * #CoglFrameInfo corresponding to the newly presented frame.  The
 
502
 * meaning of "ended" here simply means that no more timing
 
503
 * information will be collected within the corresponding
 
504
 * #CoglFrameInfo and so this is a good opportunity to analyse the
 
505
 * given info. It does not necessarily mean that the GPU has finished
 
506
 * rendering the corresponding frame.
 
507
 *
 
508
 * We highly recommend throttling your application according to
 
509
 * %COGL_FRAME_EVENT_SYNC events so that your application can avoid
 
510
 * wasting resources, drawing more frames than your system compositor
 
511
 * can display.
 
512
 *
 
513
 * Return value: a #CoglFrameClosure pointer that can be used to
 
514
 *               remove the callback and associated @user_data later.
 
515
 * Since: 1.14
 
516
 * Stability: unstable
 
517
 */
 
518
CoglFrameClosure *
 
519
cogl_onscreen_add_frame_callback (CoglOnscreen *onscreen,
 
520
                                  CoglFrameCallback callback,
 
521
                                  void *user_data,
 
522
                                  CoglUserDataDestroyCallback destroy);
 
523
 
 
524
/**
 
525
 * cogl_onscreen_remove_frame_callback:
 
526
 * @onscreen: A #CoglOnscreen
 
527
 * @closure: A #CoglFrameClosure returned from
 
528
 *           cogl_onscreen_add_frame_callback()
 
529
 *
 
530
 * Removes a callback and associated user data that were previously
 
531
 * registered using cogl_onscreen_add_frame_callback().
 
532
 *
 
533
 * If a destroy callback was passed to
 
534
 * cogl_onscreen_add_frame_callback() to destroy the user data then
 
535
 * this will get called.
 
536
 *
 
537
 * Since: 1.14
 
538
 * Stability: unstable
 
539
 */
 
540
void
 
541
cogl_onscreen_remove_frame_callback (CoglOnscreen *onscreen,
 
542
                                     CoglFrameClosure *closure);
 
543
 
 
544
typedef void (*CoglSwapBuffersNotify) (CoglFramebuffer *framebuffer,
 
545
                                       void *user_data);
 
546
 
 
547
/**
 
548
 * cogl_onscreen_add_swap_buffers_callback:
 
549
 * @onscreen: A #CoglOnscreen framebuffer
 
550
 * @callback: (scope notified): A callback function to call when a swap
 
551
 *            has completed
 
552
 * @user_data: (closure): A private pointer to be passed to @callback
 
553
 *
 
554
 * Installs a @callback function that should be called whenever a swap buffers
 
555
 * request (made using cogl_onscreen_swap_buffers()) for the given
 
556
 * @onscreen completes.
 
557
 *
 
558
 * <note>Applications should check for the %COGL_FEATURE_ID_SWAP_BUFFERS_EVENT
 
559
 * feature before using this API. It's currently undefined when and if
 
560
 * registered callbacks will be called if this feature is not supported.</note>
 
561
 *
 
562
 * We recommend using this mechanism when available to manually throttle your
 
563
 * applications (in conjunction with  cogl_onscreen_set_swap_throttled()) so
 
564
 * your application will be able to avoid long blocks in the driver caused by
 
565
 * throttling when you request to swap buffers too quickly.
 
566
 *
 
567
 * Return value: a unique identifier that can be used to remove to remove
 
568
 *               the callback later.
 
569
 * Since: 1.10
 
570
 * Stability: unstable
 
571
 * Deprecated: 1.14: Use cogl_onscreen_add_frame_callback() instead
 
572
 */
 
573
COGL_DEPRECATED_IN_1_14_FOR (cogl_onscreen_add_frame_callback)
 
574
unsigned int
 
575
cogl_onscreen_add_swap_buffers_callback (CoglOnscreen *onscreen,
 
576
                                         CoglSwapBuffersNotify callback,
 
577
                                         void *user_data);
 
578
 
 
579
/**
 
580
 * cogl_onscreen_remove_swap_buffers_callback:
 
581
 * @onscreen: A #CoglOnscreen framebuffer
 
582
 * @id: An identifier returned from cogl_onscreen_add_swap_buffers_callback()
 
583
 *
 
584
 * Removes a callback that was previously registered
 
585
 * using cogl_onscreen_add_swap_buffers_callback().
 
586
 *
 
587
 * Since: 1.10
 
588
 * Stability: unstable
 
589
 * Deprecated: 1.14: Use cogl_onscreen_remove_frame_callback() instead
 
590
 */
 
591
 
 
592
COGL_DEPRECATED_IN_1_14_FOR (cogl_onscreen_remove_frame_callback)
 
593
void
 
594
cogl_onscreen_remove_swap_buffers_callback (CoglOnscreen *onscreen,
 
595
                                            unsigned int id);
 
596
 
 
597
/**
 
598
 * cogl_onscreen_set_resizable:
 
599
 * @onscreen: A #CoglOnscreen framebuffer
 
600
 *
 
601
 * Lets you request Cogl to mark an @onscreen framebuffer as
 
602
 * resizable or not.
 
603
 *
 
604
 * By default, if possible, a @onscreen will be created by Cogl
 
605
 * as non resizable, but it is not guaranteed that this is always
 
606
 * possible for all window systems.
 
607
 *
 
608
 * <note>Cogl does not know whether marking the @onscreen framebuffer
 
609
 * is truly meaningful for your current window system (consider
 
610
 * applications being run fullscreen on a phone or TV) so this
 
611
 * function may not have any useful effect. If you are running on a
 
612
 * multi windowing system such as X11 or Win32 or OSX then Cogl will
 
613
 * request to the window system that users be allowed to resize the
 
614
 * @onscreen, although it's still possible that some other window
 
615
 * management policy will block this possibility.</note>
 
616
 *
 
617
 * <note>Whenever an @onscreen framebuffer is resized the viewport
 
618
 * will be automatically updated to match the new size of the
 
619
 * framebuffer with an origin of (0,0). If your application needs more
 
620
 * specialized control of the viewport it will need to register a
 
621
 * resize handler using cogl_onscreen_add_resize_callback() so that it
 
622
 * can track when the viewport has been changed automatically.</note>
 
623
 *
 
624
 * Since: 2.0
 
625
 */
 
626
void
 
627
cogl_onscreen_set_resizable (CoglOnscreen *onscreen,
 
628
                             CoglBool resizable);
 
629
 
 
630
/**
 
631
 * cogl_onscreen_get_resizable:
 
632
 * @onscreen: A #CoglOnscreen framebuffer
 
633
 *
 
634
 * Lets you query whether @onscreen has been marked as resizable via
 
635
 * the cogl_onscreen_set_resizable() api.
 
636
 *
 
637
 * By default, if possible, a @onscreen will be created by Cogl
 
638
 * as non resizable, but it is not guaranteed that this is always
 
639
 * possible for all window systems.
 
640
 *
 
641
 * <note>If cogl_onscreen_set_resizable(@onscreen, %TRUE) has been
 
642
 * previously called then this function will return %TRUE, but it's
 
643
 * possible that the current windowing system being used does not
 
644
 * support window resizing (consider fullscreen windows on a phone or
 
645
 * a TV). This function is not aware of whether resizing is truly
 
646
 * meaningful with your window system, only whether the @onscreen has
 
647
 * been marked as resizable.</note>
 
648
 *
 
649
 * Return value: Returns whether @onscreen has been marked as
 
650
 *               resizable or not.
 
651
 * Since: 2.0
 
652
 */
 
653
CoglBool
 
654
cogl_onscreen_get_resizable (CoglOnscreen *onscreen);
 
655
 
 
656
/**
 
657
 * CoglOnscreenResizeCallback:
 
658
 * @onscreen: A #CoglOnscreen framebuffer that was resized
 
659
 * @width: The new width of @onscreen
 
660
 * @height: The new height of @onscreen
 
661
 * @user_data: The private passed to
 
662
 *             cogl_onscreen_add_resize_callback()
 
663
 *
 
664
 * Is a callback type used with the
 
665
 * cogl_onscreen_add_resize_callback() allowing applications to be
 
666
 * notified whenever an @onscreen framebuffer is resized.
 
667
 *
 
668
 * <note>Cogl automatically updates the viewport of an @onscreen
 
669
 * framebuffer that is resized so this callback is also an indication
 
670
 * that the viewport has been modified too</note>
 
671
 *
 
672
 * <note>A resize callback will only ever be called while dispatching
 
673
 * Cogl events from the system mainloop; so for example during
 
674
 * cogl_poll_renderer_dispatch(). This is so that callbacks shouldn't
 
675
 * occur while an application might have arbitrary locks held for
 
676
 * example.</note>
 
677
 *
 
678
 * Since: 2.0
 
679
 */
 
680
typedef void (*CoglOnscreenResizeCallback) (CoglOnscreen *onscreen,
 
681
                                            int width,
 
682
                                            int height,
 
683
                                            void *user_data);
 
684
 
 
685
/**
 
686
 * CoglOnscreenResizeClosure:
 
687
 *
 
688
 * An opaque type that tracks a #CoglOnscreenResizeCallback and
 
689
 * associated user data. A #CoglOnscreenResizeClosure pointer will be
 
690
 * returned from cogl_onscreen_add_resize_callback() and it allows you
 
691
 * to remove a callback later using
 
692
 * cogl_onscreen_remove_resize_callback().
 
693
 *
 
694
 * Since: 2.0
 
695
 * Stability: unstable
 
696
 */
 
697
typedef struct _CoglClosure CoglOnscreenResizeClosure;
 
698
 
 
699
#ifdef COGL_HAS_GTYPE_SUPPORT
 
700
/**
 
701
 * cogl_onscreen_resize_closure_get_gtype:
 
702
 *
 
703
 * Returns: a #GType that can be used with the GLib type system.
 
704
 */
 
705
GType cogl_onscreen_resize_closure_get_gtype (void);
 
706
#endif
 
707
 
 
708
/**
 
709
 * cogl_onscreen_add_resize_callback:
 
710
 * @onscreen: A #CoglOnscreen framebuffer
 
711
 * @callback: (scope notified): A #CoglOnscreenResizeCallback to call when
 
712
 *            the @onscreen changes size.
 
713
 * @user_data: (closure): Private data to be passed to @callback.
 
714
 * @destroy: (allow-none): An optional callback to destroy @user_data
 
715
 *           when the @callback is removed or @onscreen is freed.
 
716
 *
 
717
 * Registers a @callback with @onscreen that will be called whenever
 
718
 * the @onscreen framebuffer changes size.
 
719
 *
 
720
 * The @callback can be removed using
 
721
 * cogl_onscreen_remove_resize_callback() passing the returned closure
 
722
 * pointer.
 
723
 *
 
724
 * <note>Since Cogl automatically updates the viewport of an @onscreen
 
725
 * framebuffer that is resized, a resize callback can also be used to
 
726
 * track when the viewport has been changed automatically by Cogl in
 
727
 * case your application needs more specialized control over the
 
728
 * viewport.</note>
 
729
 *
 
730
 * <note>A resize callback will only ever be called while dispatching
 
731
 * Cogl events from the system mainloop; so for example during
 
732
 * cogl_poll_renderer_dispatch(). This is so that callbacks shouldn't
 
733
 * occur while an application might have arbitrary locks held for
 
734
 * example.</note>
 
735
 *
 
736
 * Return value: a #CoglOnscreenResizeClosure pointer that can be used to
 
737
 *               remove the callback and associated @user_data later.
 
738
 * Since: 2.0
 
739
 */
 
740
CoglOnscreenResizeClosure *
 
741
cogl_onscreen_add_resize_callback (CoglOnscreen *onscreen,
 
742
                                   CoglOnscreenResizeCallback callback,
 
743
                                   void *user_data,
 
744
                                   CoglUserDataDestroyCallback destroy);
 
745
 
 
746
/**
 
747
 * cogl_onscreen_remove_resize_callback:
 
748
 * @onscreen: A #CoglOnscreen framebuffer
 
749
 * @closure: An identifier returned from cogl_onscreen_add_resize_callback()
 
750
 *
 
751
 * Removes a resize @callback and @user_data pair that were previously
 
752
 * associated with @onscreen via cogl_onscreen_add_resize_callback().
 
753
 *
 
754
 * Since: 2.0
 
755
 */
 
756
void
 
757
cogl_onscreen_remove_resize_callback (CoglOnscreen *onscreen,
 
758
                                      CoglOnscreenResizeClosure *closure);
 
759
 
 
760
/**
 
761
 * CoglOnscreenDirtyInfo:
 
762
 * @x: Left edge of the dirty rectangle
 
763
 * @y: Top edge of the dirty rectangle, measured from the top of the window
 
764
 * @width: Width of the dirty rectangle
 
765
 * @height: Height of the dirty rectangle
 
766
 *
 
767
 * A structure passed to callbacks registered using
 
768
 * cogl_onscreen_add_dirty_callback(). The members describe a
 
769
 * rectangle within the onscreen buffer that should be redrawn.
 
770
 *
 
771
 * Since: 1.16
 
772
 * Stability: unstable
 
773
 */
 
774
typedef struct _CoglOnscreenDirtyInfo CoglOnscreenDirtyInfo;
 
775
 
 
776
struct _CoglOnscreenDirtyInfo
 
777
{
 
778
  int x, y;
 
779
  int width, height;
 
780
};
 
781
 
 
782
/**
 
783
 * CoglOnscreenDirtyCallback:
 
784
 * @onscreen: The onscreen that the frame is associated with
 
785
 * @info: A #CoglOnscreenDirtyInfo struct containing the details of the
 
786
 *   dirty area
 
787
 * @user_data: The user pointer passed to
 
788
 *             cogl_onscreen_add_frame_callback()
 
789
 *
 
790
 * Is a callback that can be registered via
 
791
 * cogl_onscreen_add_dirty_callback() to be called when the windowing
 
792
 * system determines that a region of the onscreen window has been
 
793
 * lost and the application should redraw it.
 
794
 *
 
795
 * Since: 1.16
 
796
 * Stability: unstable
 
797
 */
 
798
typedef void (*CoglOnscreenDirtyCallback) (CoglOnscreen *onscreen,
 
799
                                           const CoglOnscreenDirtyInfo *info,
 
800
                                           void *user_data);
 
801
 
 
802
/**
 
803
 * CoglOnscreenDirtyClosure:
 
804
 *
 
805
 * An opaque type that tracks a #CoglOnscreenDirtyCallback and associated
 
806
 * user data. A #CoglOnscreenDirtyClosure pointer will be returned from
 
807
 * cogl_onscreen_add_dirty_callback() and it allows you to remove a
 
808
 * callback later using cogl_onscreen_remove_dirty_callback().
 
809
 *
 
810
 * Since: 1.16
 
811
 * Stability: unstable
 
812
 */
 
813
typedef struct _CoglClosure CoglOnscreenDirtyClosure;
 
814
 
 
815
#ifdef COGL_HAS_GTYPE_SUPPORT
 
816
/**
 
817
 * cogl_onscreen_dirty_closure_get_gtype:
 
818
 *
 
819
 * Returns: a #GType that can be used with the GLib type system.
 
820
 */
 
821
GType cogl_onscreen_dirty_closure_get_gtype (void);
 
822
#endif
 
823
 
 
824
/**
 
825
 * cogl_onscreen_add_dirty_callback:
 
826
 * @onscreen: A #CoglOnscreen framebuffer
 
827
 * @callback: (scope notified): A callback function to call for dirty events
 
828
 * @user_data: (closure): A private pointer to be passed to @callback
 
829
 * @destroy: (allow-none): An optional callback to destroy @user_data when the
 
830
 *           @callback is removed or @onscreen is freed.
 
831
 *
 
832
 * Installs a @callback function that will be called whenever the
 
833
 * window system has lost the contents of a region of the onscreen
 
834
 * buffer and the application should redraw it to repair the buffer.
 
835
 * For example this may happen in a window system without a compositor
 
836
 * if a window that was previously covering up the onscreen window has
 
837
 * been moved causing a region of the onscreen to be exposed.
 
838
 *
 
839
 * The @callback will be passed a #CoglOnscreenDirtyInfo struct which
 
840
 * decribes a rectangle containing the newly dirtied region. Note that
 
841
 * this may be called multiple times to describe a non-rectangular
 
842
 * region composed of multiple smaller rectangles.
 
843
 *
 
844
 * The dirty events are separate from %COGL_FRAME_EVENT_SYNC events so
 
845
 * the application should also listen for this event before rendering
 
846
 * the dirty region to ensure that the framebuffer is actually ready
 
847
 * for rendering.
 
848
 *
 
849
 * Return value: a #CoglOnscreenDirtyClosure pointer that can be used to
 
850
 *               remove the callback and associated @user_data later.
 
851
 * Since: 1.16
 
852
 * Stability: unstable
 
853
 */
 
854
CoglOnscreenDirtyClosure *
 
855
cogl_onscreen_add_dirty_callback (CoglOnscreen *onscreen,
 
856
                                  CoglOnscreenDirtyCallback callback,
 
857
                                  void *user_data,
 
858
                                  CoglUserDataDestroyCallback destroy);
 
859
 
 
860
/**
 
861
 * cogl_onscreen_remove_dirty_callback:
 
862
 * @onscreen: A #CoglOnscreen
 
863
 * @closure: A #CoglOnscreenDirtyClosure returned from
 
864
 *           cogl_onscreen_add_dirty_callback()
 
865
 *
 
866
 * Removes a callback and associated user data that were previously
 
867
 * registered using cogl_onscreen_add_dirty_callback().
 
868
 *
 
869
 * If a destroy callback was passed to
 
870
 * cogl_onscreen_add_dirty_callback() to destroy the user data then
 
871
 * this will also get called.
 
872
 *
 
873
 * Since: 1.16
 
874
 * Stability: unstable
 
875
 */
 
876
void
 
877
cogl_onscreen_remove_dirty_callback (CoglOnscreen *onscreen,
 
878
                                     CoglOnscreenDirtyClosure *closure);
 
879
 
 
880
/**
 
881
 * cogl_is_onscreen:
 
882
 * @object: A #CoglObject pointer
 
883
 *
 
884
 * Gets whether the given object references a #CoglOnscreen.
 
885
 *
 
886
 * Return value: %TRUE if the object references a #CoglOnscreen
 
887
 *   and %FALSE otherwise.
 
888
 * Since: 1.10
 
889
 * Stability: unstable
 
890
 */
 
891
CoglBool
 
892
cogl_is_onscreen (void *object);
 
893
 
 
894
/**
 
895
 * cogl_onscreen_get_frame_counter:
 
896
 *
 
897
 * Gets the value of the framebuffers frame counter. This is
 
898
 * a counter that increases by one each time
 
899
 * cogl_onscreen_swap_buffers() or cogl_onscreen_swap_region()
 
900
 * is called.
 
901
 *
 
902
 * Return value: the current frame counter value
 
903
 * Since: 1.14
 
904
 * Stability: unstable
 
905
 */
 
906
int64_t
 
907
cogl_onscreen_get_frame_counter (CoglOnscreen *onscreen);
 
908
 
 
909
COGL_END_DECLS
 
910
 
 
911
#endif /* __COGL_ONSCREEN_H */