Cogl.Onscreen

g Cogl.Framebuffer Cogl.Framebuffer Cogl.Onscreen Cogl.Onscreen Cogl.Framebuffer->Cogl.Onscreen Cogl.Object Cogl.Object Cogl.Object->Cogl.Onscreen GObject.GInterface GObject.GInterface GObject.GInterface->Cogl.Framebuffer

Implementations:

None

Methods

Inherited:

Cogl.Object (2), Cogl.Framebuffer (67)

class

new (context, width, height)

add_dirty_callback (callback, user_data, destroy)

add_frame_callback (callback, user_data, destroy)

add_resize_callback (callback, user_data, destroy)

add_swap_buffers_callback (callback, *user_data)

get_buffer_age ()

get_frame_counter ()

get_resizable ()

hide ()

remove_dirty_callback (closure)

remove_frame_callback (closure)

remove_resize_callback (closure)

remove_swap_buffers_callback (id)

set_resizable (resizable)

set_swap_throttled (throttled)

show ()

swap_buffers ()

swap_buffers_with_damage (rectangles, n_rectangles)

swap_region (rectangles, n_rectangles)

Virtual Methods

None

Properties

None

Signals

None

Fields

None

Class Details

class Cogl.Onscreen
Bases:

Cogl.Object, Cogl.Framebuffer

classmethod new(context, width, height)
Parameters:
Returns:

A newly instantiated Cogl.Onscreen framebuffer

Return type:

Cogl.Onscreen

Instantiates an “unallocated” Cogl.Onscreen framebuffer that may be configured before later being allocated, either implicitly when it is first used or explicitly via Cogl.Framebuffer.allocate().

New in version 1.8.

add_dirty_callback(callback, user_data, destroy)
Parameters:
  • callback (Cogl.OnscreenDirtyCallback) – A callback function to call for dirty events

  • user_data (object or None) – A private pointer to be passed to callback

  • destroy (GLib.DestroyNotify or None) – An optional callback to destroy user_data when the callback is removed or self is freed.

Returns:

a Cogl.OnscreenDirtyClosure pointer that can be used to remove the callback and associated user_data later.

Return type:

Cogl.OnscreenDirtyClosure

Installs a callback function that will be called whenever the window system has lost the contents of a region of the onscreen buffer and the application should redraw it to repair the buffer. For example this may happen in a window system without a compositor if a window that was previously covering up the onscreen window has been moved causing a region of the onscreen to be exposed.

The callback will be passed a Cogl.OnscreenDirtyInfo struct which decribes a rectangle containing the newly dirtied region. Note that this may be called multiple times to describe a non-rectangular region composed of multiple smaller rectangles.

The dirty events are separate from Cogl.FrameEvent.SYNC events so the application should also listen for this event before rendering the dirty region to ensure that the framebuffer is actually ready for rendering.

New in version 1.16.

add_frame_callback(callback, user_data, destroy)
Parameters:
  • callback (Cogl.FrameCallback) – A callback function to call for frame events

  • user_data (object or None) – A private pointer to be passed to callback

  • destroy (GLib.DestroyNotify or None) – An optional callback to destroy user_data when the callback is removed or self is freed.

Returns:

a Cogl.FrameClosure pointer that can be used to remove the callback and associated user_data later.

Return type:

Cogl.FrameClosure

Installs a callback function that will be called for significant events relating to the given self framebuffer.

The callback will be used to notify when the system compositor is ready for this application to render a new frame. In this case Cogl.FrameEvent.SYNC will be passed as the event argument to the given callback in addition to the Cogl.FrameInfo corresponding to the frame beeing acknowledged by the compositor.

The callback will also be called to notify when the frame has ended. In this case Cogl.FrameEvent.COMPLETE will be passed as the event argument to the given callback in addition to the Cogl.FrameInfo corresponding to the newly presented frame. The meaning of “ended” here simply means that no more timing information will be collected within the corresponding Cogl.FrameInfo and so this is a good opportunity to analyse the given info. It does not necessarily mean that the GPU has finished rendering the corresponding frame.

We highly recommend throttling your application according to Cogl.FrameEvent.SYNC events so that your application can avoid wasting resources, drawing more frames than your system compositor can display.

New in version 1.14.

add_resize_callback(callback, user_data, destroy)
Parameters:
Returns:

a Cogl.OnscreenResizeClosure pointer that can be used to remove the callback and associated user_data later.

Return type:

Cogl.OnscreenResizeClosure

Registers a callback with self that will be called whenever the self framebuffer changes size.

The callback can be removed using Cogl.Onscreen.remove_resize_callback() passing the returned closure pointer.

Since Cogl automatically updates the viewport of an self framebuffer that is resized, a resize callback can also be used to track when the viewport has been changed automatically by Cogl in case your application needs more specialized control over the viewport. A resize callback will only ever be called while dispatching Cogl events from the system mainloop; so for example during Cogl.poll_renderer_dispatch(). This is so that callbacks shouldn’t occur while an application might have arbitrary locks held for example.

New in version 2.0.

add_swap_buffers_callback(callback, *user_data)
Parameters:
  • callback (Cogl.SwapBuffersNotify) – A callback function to call when a swap has completed

  • user_data (object or None) – A private pointer to be passed to callback

Returns:

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

Return type:

int

Installs a callback function that should be called whenever a swap buffers request (made using Cogl.Onscreen.swap_buffers()) for the given self completes.

Applications should check for the Cogl.FeatureID.OGL_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.

New in version 1.10.

Deprecated since version 1.14: Use Cogl.Onscreen.add_frame_callback() instead

get_buffer_age()
Returns:

The age of the buffer contents or 0 when the buffer contents are undefined.

Return type:

int

Gets the current age of the buffer contents.

This function allows applications to query the age of the current back buffer contents for a Cogl.Onscreen as the number of frames elapsed since the contents were most recently defined.

These age values exposes enough information to applications about how Cogl internally manages back buffers to allow applications to re-use the contents of old frames and minimize how much must be redrawn for the next frame.

The back buffer contents can either be reported as invalid (has an age of 0) or it may be reported to be the same contents as from n frames prior to the current frame.

The queried value remains valid until the next buffer swap.

One caveat is that under X11 the buffer age does not reflect changes to buffer contents caused by the window systems. X11 applications must track Expose events to determine what buffer regions need to additionally be repaired each frame. The recommended way to take advantage of this buffer age api is to build up a circular buffer of length 3 for tracking damage regions over the last 3 frames and when starting a new frame look at the age of the buffer and combine the damage regions for the current frame with the damage regions of previous age frames so you know everything that must be redrawn to update the old contents for the new frame.

If the system doesn’t not support being able to track the age of back buffers then this function will always return 0 which implies that the contents are undefined. The Cogl.FeatureID.OGL_FEATURE_ID_BUFFER_AGE feature can optionally be explicitly checked to determine if Cogl is currently tracking the age of Cogl.Onscreen back buffer contents. If this feature is missing then this function will always return 0.

New in version 1.14.

get_frame_counter()
Returns:

the current frame counter value

Return type:

int

Gets the value of the framebuffers frame counter. This is a counter that increases by one each time Cogl.Onscreen.swap_buffers() or Cogl.Onscreen.swap_region() is called.

New in version 1.14.

get_resizable()
Returns:

Returns whether self has been marked as resizable or not.

Return type:

int

Lets you query whether self has been marked as resizable via the Cogl.Onscreen.set_resizable() api.

By default, if possible, a self will be created by Cogl as non resizable, but it is not guaranteed that this is always possible for all window systems.

If Cogl.Onscreen.set_resizable(self, True) has been previously called then this function will return True, but it’s possible that the current windowing system being used does not support window resizing (consider fullscreen windows on a phone or a TV). This function is not aware of whether resizing is truly meaningful with your window system, only whether the self has been marked as resizable.

New in version 2.0.

hide()

This requests to make self 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 self framebuffer before hiding it.

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.

New in version 2.0.

remove_dirty_callback(closure)
Parameters:

closure (Cogl.OnscreenDirtyClosure) – A Cogl.OnscreenDirtyClosure returned from Cogl.Onscreen.add_dirty_callback()

Removes a callback and associated user data that were previously registered using Cogl.Onscreen.add_dirty_callback().

If a destroy callback was passed to Cogl.Onscreen.add_dirty_callback() to destroy the user data then this will also get called.

New in version 1.16.

remove_frame_callback(closure)
Parameters:

closure (Cogl.FrameClosure) – A Cogl.FrameClosure returned from Cogl.Onscreen.add_frame_callback()

Removes a callback and associated user data that were previously registered using Cogl.Onscreen.add_frame_callback().

If a destroy callback was passed to Cogl.Onscreen.add_frame_callback() to destroy the user data then this will get called.

New in version 1.14.

remove_resize_callback(closure)
Parameters:

closure (Cogl.OnscreenResizeClosure) – An identifier returned from Cogl.Onscreen.add_resize_callback()

Removes a resize callback and user_data pair that were previously associated with self via Cogl.Onscreen.add_resize_callback().

New in version 2.0.

remove_swap_buffers_callback(id)
Parameters:

id (int) – An identifier returned from Cogl.Onscreen.add_swap_buffers_callback()

Removes a callback that was previously registered using Cogl.Onscreen.add_swap_buffers_callback().

New in version 1.10.

Deprecated since version 1.14: Use Cogl.Onscreen.remove_frame_callback() instead

set_resizable(resizable)
Parameters:

resizable (int) –

Lets you request Cogl to mark an self framebuffer as resizable or not.

By default, if possible, a self will be created by Cogl as non resizable, but it is not guaranteed that this is always possible for all window systems.

Cogl does not know whether marking the self framebuffer is truly meaningful for your current window system (consider applications being run fullscreen on a phone or TV) so this function may not have any useful effect. If you are running on a multi windowing system such as X11 or Win32 or OSX then Cogl will request to the window system that users be allowed to resize the self, although it’s still possible that some other window management policy will block this possibility. Whenever an self framebuffer is resized the viewport will be automatically updated to match the new size of the framebuffer with an origin of (0,0). If your application needs more specialized control of the viewport it will need to register a resize handler using Cogl.Onscreen.add_resize_callback() so that it can track when the viewport has been changed automatically.

New in version 2.0.

set_swap_throttled(throttled)
Parameters:

throttled (int) – Whether swap throttling is wanted or not.

Requests that the given self 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.

New in version 1.8.

show()

This requests to make self 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 self framebuffer before showing it if it hasn’t already been allocated.

When using the Wayland winsys calling this will set the surface to a toplevel type which will make it appear. If the application wants to set a different type for the surface, it can avoid calling Cogl.Onscreen.show() and set its own type directly with the Wayland client API via Cogl.wayland_onscreen_get_surface().

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.

New in version 2.0.

swap_buffers()

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.

It is highly recommended that applications use Cogl.Onscreen.swap_buffers_with_damage() instead whenever possible and also use the Cogl.Onscreen.get_buffer_age() api so they can perform incremental updates to older buffers instead of having to render a full buffer for every frame.

New in version 1.10.

swap_buffers_with_damage(rectangles, n_rectangles)
Parameters:
  • rectangles (int) – An array of integer 4-tuples representing damaged rectangles as (x, y, width, height) tuples.

  • n_rectangles (int) – The number of 4-tuples to be read from rectangles

Swaps the current back buffer being rendered too, to the front for display and provides information to any system compositor about what regions of the buffer have changed (damage) with respect to the last swapped buffer.

This function has the same semantics as cogl_framebuffer_swap_buffers() except that it additionally allows applications to pass a list of damaged rectangles which may be passed on to a compositor so that it can minimize how much of the screen is redrawn in response to this applications newly swapped front buffer.

For example if your application is only animating a small object in the corner of the screen and everything else is remaining static then it can help the compositor to know that only the bottom right corner of your newly swapped buffer has really changed with respect to your previously swapped front buffer.

If n_rectangles is 0 then the whole buffer will implicitly be reported as damaged as if Cogl.Onscreen.swap_buffers() had been called.

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. If you want to perform incremental updates to older back buffers then please refer to the Cogl.Onscreen.get_buffer_age() api.

Whenever possible it is recommended that applications use this function instead of Cogl.Onscreen.swap_buffers() to improve performance when running under a compositor.

It is highly recommended to use this API in conjunction with the Cogl.Onscreen.get_buffer_age() api so that your application can perform incremental rendering based on old back buffers.

New in version 1.16.

swap_region(rectangles, n_rectangles)
Parameters:
  • rectangles (int) – An array of integer 4-tuples representing rectangles as (x, y, width, height) tuples.

  • n_rectangles (int) – The number of 4-tuples to be read from 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.

New in version 1.10.