CoglOnscreen: The Onscreen Framebuffer Interface

CoglOnscreen: The Onscreen Framebuffer Interface

Synopsis

                    CoglOnscreen;
CoglBool            cogl_is_onscreen                    (void *object);
#define             COGL_ONSCREEN                       (X)

CoglOnscreen *      cogl_onscreen_new                   (CoglContext *context,
                                                         int width,
                                                         int height);

void                (*CoglOnscreenX11MaskCallback)      (CoglOnscreen *onscreen,
                                                         uint32_t event_mask,
                                                         void *user_data);
void                cogl_x11_onscreen_set_foreign_window_xid
                                                        (CoglOnscreen *onscreen,
                                                         uint32_t xid,
                                                         CoglOnscreenX11MaskCallback update,
                                                         void *user_data);
uint32_t            cogl_x11_onscreen_get_window_xid    (CoglOnscreen *onscreen);
uint32_t            cogl_x11_onscreen_get_visual_xid    (CoglOnscreen *onscreen);

void                cogl_win32_onscreen_set_foreign_window
                                                        (CoglOnscreen *onscreen,
                                                         HWND hwnd);
HWND                cogl_win32_onscreen_get_window      (CoglOnscreen *onscreen);

void                cogl_onscreen_show                  (CoglOnscreen *onscreen);
void                cogl_onscreen_hide                  (CoglOnscreen *onscreen);

void                cogl_onscreen_swap_buffers          (CoglOnscreen *onscreen);
void                cogl_onscreen_swap_region           (CoglOnscreen *onscreen,
                                                         const int *rectangles,
                                                         int n_rectangles);
void                cogl_onscreen_set_swap_throttled    (CoglOnscreen *onscreen,
                                                         CoglBool throttled);
void                (*CoglSwapBuffersNotify)            (CoglFramebuffer *framebuffer,
                                                         void *user_data);
unsigned int        cogl_onscreen_add_swap_buffers_callback
                                                        (CoglOnscreen *onscreen,
                                                         CoglSwapBuffersNotify callback,
                                                         void *user_data);
void                cogl_onscreen_remove_swap_buffers_callback
                                                        (CoglOnscreen *onscreen,
                                                         unsigned int id);

Description

Details

CoglOnscreen

typedef struct _CoglOnscreen CoglOnscreen;

cogl_is_onscreen ()

CoglBool            cogl_is_onscreen                    (void *object);

Gets whether the given object references a CoglOnscreen.

object :

A CoglObject pointer

Returns :

TRUE if the object references a CoglOnscreen and FALSE otherwise.

Since 1.10

Stability Level: Unstable


COGL_ONSCREEN()

#define COGL_ONSCREEN(X) ((CoglOnscreen *)(X))

cogl_onscreen_new ()

CoglOnscreen *      cogl_onscreen_new                   (CoglContext *context,
                                                         int width,
                                                         int height);

Instantiates an "unallocated" CoglOnscreen framebuffer that may be configured before later being allocated, either implicitly when it is first used or explicitly via cogl_framebuffer_allocate().

context :

A CoglContext

width :

The desired framebuffer width

height :

The desired framebuffer height

Returns :

A newly instantiated CoglOnscreen framebuffer

Since 1.8

Stability Level: Unstable


CoglOnscreenX11MaskCallback ()

void                (*CoglOnscreenX11MaskCallback)      (CoglOnscreen *onscreen,
                                                         uint32_t event_mask,
                                                         void *user_data);

cogl_x11_onscreen_set_foreign_window_xid ()

void                cogl_x11_onscreen_set_foreign_window_xid
                                                        (CoglOnscreen *onscreen,
                                                         uint32_t xid,
                                                         CoglOnscreenX11MaskCallback update,
                                                         void *user_data);

Ideally we would recommend that you let Cogl be responsible for creating any X window required to back an onscreen framebuffer but if you really need to target a window created manually this function can be called before onscreen has been allocated to set a foreign XID for your existing X window.

Since Cogl needs, for example, to track changes to the size of an X window it requires that certain events be selected for via the core X protocol. This requirement may also be changed asynchronously so you must pass in an update callback to inform you of Cogl's required event mask.

For example if you are using Xlib you could use this API roughly as follows: [{ static void my_update_cogl_x11_event_mask (CoglOnscreen *onscreen, uint32_t event_mask, void *user_data) { XSetWindowAttributes attrs; MyData *data = user_data; attrs.event_mask = event_mask | data->my_event_mask; XChangeWindowAttributes (data->xdpy, data->xwin, CWEventMask, &attrs); }

{ *snip* cogl_x11_onscreen_set_foreign_window_xid (onscreen, data->xwin, my_update_cogl_x11_event_mask, data); *snip* } }]

onscreen :

The unallocated framebuffer to associated with an X window.

xid :

The XID of an existing X window

update :

A callback that notifies of updates to what Cogl requires to be in the core X protocol event mask.

user_data :

user data passed to update

Since 2.0

Stability Level: Unstable


cogl_x11_onscreen_get_window_xid ()

uint32_t            cogl_x11_onscreen_get_window_xid    (CoglOnscreen *onscreen);

Assuming you know the given onscreen framebuffer is based on an x11 window this queries the XID of that window. If cogl_x11_onscreen_set_foreign_window_xid() was previously called then it will return that same XID otherwise it will be the XID of a window Cogl created internally. If the window has not been allocated yet and a foreign xid has not been set then it's undefined what value will be returned.

It's undefined what this function does if called when not using an x11 based renderer.

onscreen :

A CoglOnscreen framebuffer

Since 1.10

Stability Level: Unstable


cogl_x11_onscreen_get_visual_xid ()

uint32_t            cogl_x11_onscreen_get_visual_xid    (CoglOnscreen *onscreen);

cogl_win32_onscreen_set_foreign_window ()

void                cogl_win32_onscreen_set_foreign_window
                                                        (CoglOnscreen *onscreen,
                                                         HWND hwnd);

Ideally we would recommend that you let Cogl be responsible for creating any window required to back an onscreen framebuffer but if you really need to target a window created manually this function can be called before onscreen has been allocated to set a foreign XID for your existing X window.

onscreen :

A CoglOnscreen framebuffer

hwnd :

A win32 window handle

Since 1.10

Stability Level: Unstable


cogl_win32_onscreen_get_window ()

HWND                cogl_win32_onscreen_get_window      (CoglOnscreen *onscreen);

Queries the internally created window HWND backing the given onscreen framebuffer. If cogl_win32_onscreen_set_foreign_window() has been used then it will return the same handle set with that API.

onscreen :

A CoglOnscreen framebuffer

Since 1.10

Stability Level: Unstable


cogl_onscreen_show ()

void                cogl_onscreen_show                  (CoglOnscreen *onscreen);

This requests to make onscreen visible to the user.

Actually the precise semantics of this function depend on the window system currently in use, and if you don't have a multi-windowining system this function may in-fact do nothing.

This function will implicitly allocate the given onscreen framebuffer before showing it if it hasn't already been allocated.

Note

Since Cogl doesn't explicitly track the visibility status of onscreen framebuffers it wont try to avoid redundant window system requests e.g. to show an already visible window. This also means that it's acceptable to alternatively use native APIs to show and hide windows without confusing Cogl.

onscreen :

The onscreen framebuffer to make visible

Since 2.0

Stability Level: Unstable


cogl_onscreen_hide ()

void                cogl_onscreen_hide                  (CoglOnscreen *onscreen);

This requests to make onscreen invisible to the user.

Actually the precise semantics of this function depend on the window system currently in use, and if you don't have a multi-windowining system this function may in-fact do nothing.

This function does not implicitly allocate the given onscreen framebuffer before hiding it.

Note

Since Cogl doesn't explicitly track the visibility status of onscreen framebuffers it wont try to avoid redundant window system requests e.g. to show an already visible window. This also means that it's acceptable to alternatively use native APIs to show and hide windows without confusing Cogl.

onscreen :

The onscreen framebuffer to make invisible

Since 2.0

Stability Level: Unstable


cogl_onscreen_swap_buffers ()

void                cogl_onscreen_swap_buffers          (CoglOnscreen *onscreen);

Swaps the current back buffer being rendered too, to the front for display.

This function also implicitly discards the contents of the color, depth and stencil buffers as if cogl_framebuffer_discard_buffers() were used. The significance of the discard is that you should not expect to be able to start a new frame that incrementally builds on the contents of the previous frame.

onscreen :

A CoglOnscreen framebuffer

Since 1.10

Stability Level: Unstable


cogl_onscreen_swap_region ()

void                cogl_onscreen_swap_region           (CoglOnscreen *onscreen,
                                                         const int *rectangles,
                                                         int n_rectangles);

Swaps a region of the back buffer being rendered too, to the front for display. rectangles represents the region as array of n_rectangles each defined by 4 sequential (x, y, width, height) integers.

This function also implicitly discards the contents of the color, depth and stencil buffers as if cogl_framebuffer_discard_buffers() were used. The significance of the discard is that you should not expect to be able to start a new frame that incrementally builds on the contents of the previous frame.

onscreen :

A CoglOnscreen framebuffer

rectangles :

An array of integer 4-tuples representing rectangles as (x, y, width, height) tuples.

n_rectangles :

The number of 4-tuples to be read from rectangles

Since 1.10

Stability Level: Unstable


cogl_onscreen_set_swap_throttled ()

void                cogl_onscreen_set_swap_throttled    (CoglOnscreen *onscreen,
                                                         CoglBool throttled);

Requests that the given onscreen framebuffer should have swap buffer requests (made using cogl_onscreen_swap_buffers()) throttled either by a displays vblank period or perhaps some other mechanism in a composited environment.

onscreen :

A CoglOnscreen framebuffer

throttled :

Whether swap throttling is wanted or not.

Since 1.8

Stability Level: Unstable


CoglSwapBuffersNotify ()

void                (*CoglSwapBuffersNotify)            (CoglFramebuffer *framebuffer,
                                                         void *user_data);

cogl_onscreen_add_swap_buffers_callback ()

unsigned int        cogl_onscreen_add_swap_buffers_callback
                                                        (CoglOnscreen *onscreen,
                                                         CoglSwapBuffersNotify callback,
                                                         void *user_data);

Installs a callback function that should be called whenever a swap buffers request (made using cogl_onscreen_swap_buffers()) for the given onscreen completes.

Note

Applications should check for the COGL_FEATURE_ID_SWAP_BUFFERS_EVENT feature before using this API. It's currently undefined when and if registered callbacks will be called if this feature is not supported.

We recommend using this mechanism when available to manually throttle your applications (in conjunction with cogl_onscreen_set_swap_throttled()) so your application will be able to avoid long blocks in the driver caused by throttling when you request to swap buffers too quickly.

onscreen :

A CoglOnscreen framebuffer

callback :

A callback function to call when a swap has completed

user_data :

A private pointer to be passed to callback

Returns :

a unique identifier that can be used to remove to remove the callback later.

Since 1.10

Stability Level: Unstable


cogl_onscreen_remove_swap_buffers_callback ()

void                cogl_onscreen_remove_swap_buffers_callback
                                                        (CoglOnscreen *onscreen,
                                                         unsigned int id);

Removes a callback that was previously registered using cogl_onscreen_add_swap_buffers_callback().

onscreen :

A CoglOnscreen framebuffer

id :

An identifier returned from cogl_onscreen_add_swap_buffers_callback()

Since 1.10

Stability Level: Unstable