Commit Graph

352 Commits

Author SHA1 Message Date
Neil Roberts
fc86d0e12e win32: Minor build fixes for building for win32
This fixes some minor errors and warnings that were preventing Cogl
building with mingw32:

• cogl-framebuffer-gl.c was not including cogl-texture-private.h.
  Presumably something else ends up including that when building for
  GLX.

• The WGL winsys was not including cogl-error-private.h

• A call to strsplit in the WGL winsys was wrong.

• For some reason the test-wrap-rectangle-textures test was trying to
  include the GDKPixbuf header.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 5380343399f834d9f96ca3b137d49c9c2193900a)
2013-02-21 15:20:55 +00:00
Neil Roberts
b34034217a Make it possible to call swap_buffers within a frame event callback
It seems like it would be quite a reasonable design for an application
to immediately paint the buffer and call swap_buffers within the
handler for the sync event. This previously wouldn't work.

When using the GLX winsys if swap_region is called then it immediately
tries to set the pending notification flag. However if this is called
from the event callback then when the callback is complete it will
clear the flag again and the pending notification will be lost. This
patch just makes it clear the pending flag before invoking the
callback so that it can be safely queued again.

With any winsys that doesn't directly handle the sync event
notification it would almost work except that it was iterating the
live list of pending events. If the callback causes another event to
be added to this list by issuing a buffer swap then the iteration
would never complete and cogl_poll_dispatch would never return. This
patch just makes it steal the list before iterating so that any
additions will be dispatched by a later call to cogl_poll_dispatch
instead.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 2263b31594900b73900d2ce22cf70c68e7e793c6)
2013-02-03 10:07:47 +01:00
Robert Bragg
8a1353a215 This reverts the first hunk from Jerome's last patch
The first hunk from commit 93b7b4c850dd928bf21ee168a95641a8d631f713
turned out to be redundant because GLX guarantees that configs returned
by glXChooseFBConfig should be sorted with non msaa configs coming
first. The second hunk is required since we use glXGetFBConfigs in that
case which doesn't sort the configs.

I had meant to drop this part of the patch before landing it but forgot.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit b19fcc1869275826e952925af922125daf8a48de)
2013-01-31 21:12:36 +00:00
Jerome Glisse
1f84b5c9b4 glx do not use multisample visual config for front or pixmap
There is no guaranty that glXGetFBConfigs will return fbconfig ordered
with non msaa config first. This patch make sure that non msaa config
get choose.

Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 93b7b4c850dd928bf21ee168a95641a8d631f713)
2013-01-31 12:28:04 +00:00
Owen W. Taylor
98e3b57d0d Add cogl_get_clock_time()
Add an API to get the current time in the time system that Cogl
is reporting timestamps. This is to be used to convert timestamps
into a different time system.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9f3735a0c37adcfcffa485f81699b53a4cc0caf8)
2013-01-30 20:09:49 +00:00
Owen W. Taylor
24733abf68 onscreen: Add CoglFrameInfo and _add_frame_callback() api
Add a CoglFrameInfo object that tracks timing information for frames
that are drawn. We track a frame counter and frame timing information
for each CoglOnscreen. Internally a CoglFrameInfo is automatically
created for each frame, delimited by cogl_onscreen_swap_buffers() or
cogl_onscreen_swap_region() calls.

CoglFrameInfos are delivered to applications via frame event callbacks
that can be registered with a new cogl_onscreen_add_frame_callback()
api. Two initial event types (dispatched on all platforms) have been
defined; a _SYNC event used for throttling the frame rate of
applications and a _COMPLETE event used so signify the end of a frame.

Note: This new _add_frame_callback() api makes the
cogl_onscreen_add_swap_complete_callback() api redundant and so it
should be considered deprecated. Since the _add_swap_complete_callback()
api is still experimental api, we will be looking to quickly migrate
users to the new api so we can remove the old api.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 700401667db2522045e4623d78797b17f9184501)
2013-01-30 20:09:49 +00:00
Owen W. Taylor
5ce058c0e5 Prefer OML_sync_control over SGI_video_sync when waiting for swap
When we block waiting for the swap, prefer doing that using
glXWaitForMsc() from OML_sync_control because that returns a system
time value for the precise time of the swap.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 1e8114aabc78b90373d3d5f3f7c0224f8786e399)
2013-01-30 20:09:40 +00:00
Owen W. Taylor
88d8bd84f2 Add CoglOutput and track for the GLX backend
The CoglOutput object represents one output such as a monitor or
laptop panel, with information about attributes of the output such as
the position of the output within the global coordinate space, and
the refresh rate.

We don't yet publically export the ability to get output information but
we track it for the GLX backend, where we'll use it to track the refresh
rate.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit d7ef9d8d71488d0e6874f1ffc6e48700d5c82a31)
2013-01-30 19:56:45 +00:00
Neil Roberts
1e00ff268e Bind the dummy surface or drawable when current onscreen is destroyed
Similar to commit 2c0cfdefbb9d1 for the SDL2 winsys, the GLX and EGL
window systems need to bind the dummy surface or drawable when the
currently bound onscreen is destroyed so that there will always be a
valid context bound.

Previously I got the idea that this would not be necessary on GLX
because the documentation for glXDestroyDrawable states that the
drawable won't actually be destroyed if it is currently bound until it
becomes unbound. However it doesn't say what happens if the underlying
X window is also destroyed and after testing it seems this causes a
segfault in Mesa in GLX and an XError for EGLX.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 4a464eec8c5b5832b9fd6b69746ab4ab36229182)
2013-01-25 18:21:09 +00:00
Robert Bragg
d521b61a49 egl: support EGL_EXT_buffer_age
This adds support for the EGL_EXT_buffer_age extension which is a
counterpart to the GLX_EXT_buffer_age extension.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 92d869764c03d0bac6b51dac833510c22669ac4a)
2013-01-23 17:58:20 +00:00
Adel Gadllah
860fb00fdc cogl-onscreen: Add buffer_age support
Add a new BUFFER_AGE winsys feature and a get_buffer_age method to
cogl-onscreen that allows to query the value.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>

Note: When landing the patch I made some gtk-doc updates and changed
_get_buffer_age to return an age of 0 always if the age feature isn't
support instead of using _COGL_RETURN_VAL_IF_FAIL. -- Robert Bragg

(cherry picked from commit 427b1038051e9b53a071d8c229b363b075bb1dc0)
2013-01-23 17:58:10 +00:00
Patrick Welche
8c319e4bc1 Remove vestiges of libdl / dlfcn.h as cogl uses gmodule.
https://bugzilla.gnome.org/show_bug.cgi?id=691944

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 397e673446e86a9116cb7396ea094e9f8b46986e)
2013-01-22 18:00:11 +00:00
Neil Roberts
fe3aa8b8b3 Query glX* functions before getting the context to fix GL3 driver
The GL3 context is created using the glXCreateContextAttribs function
which is part of the GLX_ARB_create_context extension. However
previously the function pointers from GLX extensions were only
retrieved once the GL context is created. That meant that the GL3
context creation function would always assume that the extension is
not supported so it would always fail.

This patch changes it to query the functions when the renderer is set
up instead. The base winsys feature flags that are determined while
querying the functions are stored in a member of CoglGLXRenderer.
These are then copied to the CoglContext when it is initialised.

The spec for glXGetProcAddress says that the functions returned are
context-independent. That implies that it is safe to call it without
binding a context although that is not explicitly stated as far as I
can tell. A big of googling finds this DRI documentation which says it
can be used without a context:

http://dri.freedesktop.org/wiki/glXGetProcAddressNeverReturnsNULL

And also this code sample:

http://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_%28GLX%29

One point that makes me concerned that this might not always work in
practice is that the code in SDL2 to create a GL3 context first
creates a dummy GL2 context in order to have something bound before it
calls glXGetProcAddress. I think this may just be a misunderstanding
based on how wglGetProcAddress works however.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 04a7aca9a98e84e43ac5559305a1358112902e30)
2013-01-22 17:48:18 +00:00
Robert Bragg
73e8a6d7ce Allow lazy texture storage allocation
Consistent with how we lazily allocate framebuffers this patch allows us
to instantiate textures but still specify constraints and requirements
before allocating storage so that we can be sure to allocate the most
appropriate/efficient storage.

This adds a cogl_texture_allocate() function that is analogous to
cogl_framebuffer_allocate() which can optionally be called to explicitly
allocate storage and catch any errors. If this function isn't used
explicitly then Cogl will implicitly ensure textures are allocated
before the storage is needed.

It is generally recommended to rely on lazy storage allocation or at
least perform explicit allocation as late as possible so Cogl can be
fully informed about the best way to allocate storage.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 1fa7c0f10a8a03043e3c75cb079a49625df098b7)

Note: This reverts the cogl_texture_rectangle_new_with_size API change
that dropped the CoglError argument and keeps the semantics of
allocating the texture immediately. This is because Mutter currently
uses this API so we will probably look at updating this later once
we have a corresponding Mutter patch prepared. The other API changes
were kept since they only affected experimental api.
2013-01-22 17:48:17 +00:00
Robert Bragg
5a814e386a texture: add width/height members to base CoglTexture
There was a lot of redundancy in how we tracked the width and height of
different texture types which is greatly simplified by adding width and
height members to CoglTexture directly and removing the get_width and
get_height vfuncs from CoglTextureVtable

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 3236e47723e4287d5e0023f29083521aeffc75dd)
2013-01-22 17:48:17 +00:00
Robert Bragg
0850eea162 Move _cogl_texture_get_gl_format to -texture-gl.c
This moves the _cogl_texture_get_gl_format function from cogl-texture.c
to cogl-texture-gl.c and renames it _cogl_texture_gl_get_format.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit f8deec01eff7d8d9900b509048cf1ff1c86ca879)
2013-01-22 17:48:17 +00:00
Robert Bragg
36c85da3b8 Remove cogl-internal.h
This remove cogl-internal.h in favour of using cogl-private.h. Some
things in cogl-internal.h were moved to driver/gl/cogl-util-gl-private.h
and the _cogl_gl_error_to_string function whose prototype was moved from
cogl-internal.h to cogl-util-gl-private.h has had its implementation
moved from cogl.c to cogl-util-gl.c

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 01cc82ece091aa3bec4c07fdd6bc9e5135fca573)
2013-01-22 17:48:17 +00:00
Neil Roberts
1f0b432a25 sdl: Bind the default window when currently bound window is destroyed
Cogl always needs to have the context bound to something so that it
can freely create resources such as textures even if there is no
current window. When the currently bound SDLWindow is destroyed, SDL
apparently explicitly unbinds the GL context. If something then later
for example tries to create a texture Cogl would start getting GL
errors and fail. To fix this the SDL winsys now just binds the dummy
window before deiniting the currently bound onscreen.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 2c0cfdefbb9d1ac5097d98887d3581b67a324fae)
2013-01-22 17:48:11 +00:00
Damien Lespiau
5d796f0a4c x11: Replace all internal usage of cogl_xlib_get_display()
And use the renderer replacement, cogl_xlib_renderer_get_display()

(cherry picked from commit ea355792e88b09b0b0afa6fb5c5acc311d41688e)
2013-01-22 17:48:09 +00:00
Robert Bragg
7011eb5db4 texture: expose mipmap level in set region apis
cogl_texture_set_region() and cogl_texture_set_region_from_bitmap() now
have a level argument so image data can be uploaded to a specific mipmap
level.

The prototype for cogl_texture_set_region was also updated to simplify
the arguments.

The arguments for cogl_texture_set_region_from_bitmap were reordered to
be consistent with cogl_texture_set_region with the source related
arguments listed first followed by the destination arguments.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 3a336a8adcd406b53731a6de0e7d97ba7932c1a8)

Note: Public API changes were reverted in cherry-picking this patch
2013-01-22 17:48:09 +00:00
Robert Bragg
cd7b15b7df glx: avoid use of _COGL_GET_CONTEXT()
Removes some (not all) use of _COGL_GET_CONTEXT() from cogl-winsys-glx.c

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 698a131c4991e4393ce966b968637fba194f252c)
2013-01-22 17:48:09 +00:00
Robert Bragg
e8eb9793e6 moves some gl texture code too cogl-texture-gl.c
This adds a driver/gl/cogl-texture-gl.c file and moves some gl specific
bits from cogl-texture.c into it. The moved symbols were also given a
_gl_ infix and the calling code was updated accordingly.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 2c9e81de70cc02d72b1ce9013c49e39300a05b6a)
2013-01-22 17:48:08 +00:00
Robert Bragg
f53fb5e2e0 Allow propogation of OOM errors to apps
This allows apps to catch out-of-memory errors when allocating textures.

Textures can be pretty huge at times and so it's quite possible for an
application to try and allocate more memory than is available. It's also
very possible that the application can take some action in response to
reduce memory pressure (such as freeing up texture caches perhaps) so
we shouldn't just automatically abort like we do for trivial heap
allocations.

These public functions now take a CoglError argument so applications can
catch out of memory errors:

cogl_buffer_map
cogl_buffer_map_range
cogl_buffer_set_data
cogl_framebuffer_read_pixels_into_bitmap
cogl_pixel_buffer_new
cogl_texture_new_from_data
cogl_texture_new_from_bitmap

Note: we've been quite conservative with how many apis we let throw OOM
CoglErrors since we don't really want to put a burdon on developers to
be checking for errors with every cogl api call. So long as there is
some lower level api for apps to use that let them catch OOM errors
for everything necessary that's enough and we don't have to make more
convenient apis more awkward to use.

The main focus is on bitmaps and texture allocations since they
can be particularly large and prone to failing.

A new cogl_attribute_buffer_new_with_size() function has been added in
case developers need to catch OOM errors when allocating attribute buffers
whereby they can first use _buffer_new_with_size() (which doesn't take a
CoglError) followed by cogl_buffer_set_data() which will lazily allocate
the buffer storage and report OOM errors.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit f7735e141ad537a253b02afa2a8238f96340b978)

Note: since we can't break the API for Cogl 1.x then actually the main
purpose of cherry picking this patch is to keep in-line with changes
on the master branch so that we can easily cherry-pick patches.

All the api changes relating stable apis released on the 1.12 branch
have been reverted as part of cherry-picking this patch so this most
just applies all the internal plumbing changes that enable us to
correctly propagate OOM errors.
2013-01-22 17:48:07 +00:00
Neil Roberts
4f6fe6f0e2 Fixes for --disable-glib
This fixes some problems which were stopping --disable-glib from
working properly:

• A lot of the public headers were including glib.h. This shouldn't be
  necessary because the API doesn't expose any glib types. Otherwise
  any apps would require glib in order to get the header.

• The public headers were using G_BEGIN_DECLS. There is now a
  replacement macro called COGL_BEGIN_DECLS which is defined in
  cogl-types.h.

• A similar fix has been done for G_GNUC_NULL_TERMINATED and
  G_GNUC_DEPRECATED.

• The CFLAGS were not including $(builddir)/deps/glib which was
  preventing it finding the generated glibconfig.h when building out
  of tree.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 4138b3141c2f39cddaea3d72bfc04342ed5092d0)
2013-01-22 17:48:05 +00:00
Neil Roberts
eec0f1cd65 Add cogl_sdl_onscreen_get_window()
This adds a function to get a pointer to the SDL_Window associated
with a CoglOnscreen when using the SDL2 winsys.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 071f4b80daa8a2f967746a30b3acf014d74f781a)
2013-01-22 17:48:05 +00:00
Neil Roberts
05ebbfdae7 sdl: Support setting resizable before allocate in SDL 1
The SDL 1 winsys now checks for the initial resizable state of the
onscreen framebuffer when it is allocated and updates the video flags
accordingly.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit f5fb9be70a92f751886a94da0b34e14252ed197e)
2013-01-22 17:48:04 +00:00
Neil Roberts
9f107ab3fb Support window resizing in the SDL 2 winsys
The SDL2 winsys will now set the SDL_WINDOW_RESIZABLE flag on the
window before creating it if the resizable property is set on the
onscreen. Note that there doesn't appear to be a way in SDL to change
the flag later so unlike the other winsyses it will only take affect
if it is set before allocating the framebuffer.

The winsys now registers a callback for SDL events so that it can
report window size changes back to the application.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 0dea9aeb897faf029828379b120970477df3c7d5)
2013-01-22 17:48:04 +00:00
Neil Roberts
76843fc529 sdl2: Fix GL3 context creation
The check to verify whether we've got the right GL context was
checking that the GL version was less than 3 whenever the non-GL3
driver is used. However it looks like the driver is free to return a
GL3 context that is compatible with GL2 if GL2 is requested so this
was breaking the GL2 driver.

This also adds the necessary SDL attributes to request a forward
compatible core context like the GLX and EGL winsys's do. I haven't
actually tested this because it looks like SDL will only create a GL
context with GLX and I haven't got a recent enough X server to handle
the glXCreateContextAttribs request.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit d46acafa3ea7ba2e6c4ac7a45f00a132df1b2872)
2013-01-22 17:48:02 +00:00
Neil Roberts
8039c2c779 Fix a warning when building the SDL2 winsys
The SDL2 winsys was using _cogl_set_error without including its header
so it was giving an annoying warning. This patch also fixes some
indentation issues.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 9c8433087b7573f7606dfae2bae3045803ead115)
2013-01-22 17:48:02 +00:00
Neil Roberts
2616ae0fa9 Add a GL 3 driver
This adds a new CoglDriver for GL 3 called COGL_DRIVER_GL3. When
requested, the GLX, EGL and SDL2 winsyss will set the necessary
attributes to request a forward-compatible core profile 3.1 context.
That means it will have no deprecated features.

To simplify the explosion of checks for specific combinations of
context->driver, many of these conditionals have now been replaced
with private feature flags that are checked instead. The GL and GLES
drivers now initialise these private feature flags depending on which
driver is used.

The fixed function backends now explicitly check whether the fixed
function private feature is available which means the GL3 driver will
fall back to always using the GLSL progend. Since Rob's latest patches
the GLSL progend no longer uses any fixed function API anyway so it
should just work.

The driver is currently lower priority than COGL_DRIVER_GL so it will
not be used unless it is specificly requested. We may want to change
this priority at some point because apparently Mesa can make some
memory savings if a core profile context is used.

In GL 3, getting the combined extensions string with glGetString is
deprecated so this patch changes it to use glGetStringi to build up an
array of extensions instead. _cogl_context_get_gl_extensions now
returns this array instead of trying to return a const string. The
caller is expected to free the array.

Some issues with this patch:

• GL 3 does not support GL_ALPHA format textures. We should probably
  make this a feature flag or something. Cogl uses this to render text
  which currently just throws a GL error and breaks so it's pretty
  important to do something about this before considering the GL3
  driver to be stable.

• GL 3 doesn't support client side vertex buffers. This probably
  doesn't matter because CoglBuffer won't normally use malloc'd
  buffers if VBOs are available, but it might but worth making
  malloc'd buffers a private feature and forcing it not to use them.

• GL 3 doesn't support the default vertex array object. This patch
  just makes it create and bind a single non-default vertex array
  object which gets used just like the normal default object. Ideally
  it would be good to use vertex array objects properly and attach
  them to a CoglPrimitive to cache the state.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 66c9db993595b3a22e63f4c201ea468bc9b88cb6)
2013-01-22 17:48:01 +00:00
Robert Bragg
986ba3aa79 egl: remove special re-try without stencil code
The EGL winsys had a special case code path when trying to create a
context where if it failed it would try again except without requesting
a stencil buffer. Historically this code path was to allow Clutter to
run on PowerVR MBX hardware which doesn't support a stencil buffer. It
doesn't really make sense to keep this workaround in Cogl as it would
leave Cogl in a state where the clip stack doesn't work without
providing any feedback to the developer. If we need to support running
on MBX like hardware - probably not very likely these days - then we
should provide developer control over the stencil buffer so the
equivalent workaround could be implemented on top of Cogl.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit a7c391a985e82707b17f2fb1105de5d37822a390)
2013-01-22 17:48:01 +00:00
Neil Roberts
2bcf38d126 Fix a warning in the vtable for texture_2d_get_data
The function pointer for texture_2d_get_data in the driver vtable was
expecting an unsigned int for the rowstride but the definition in
cogl-texture-2d-gl.c took a size_t so it was giving an annoying
warning. This normalizes them both to just take an int. This seems to
better match the pattern used for cogl_bitmap_new_from_data and
cogl_texture_2d_new_from_data.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 003f080531d5368835081568779b031ef4f09a77)
2013-01-22 17:48:00 +00:00
Robert Bragg
8326c71b6b texture: rename texobj flush code as gl specific
This renames the set_filters and set_wrap_mode_parameters texture
virtual functions to gl_flush_legacy_texobj_filters and
gl_flush_legacy_texobj_wrap_modes respectively to clarify that they are
opengl driver specific and that they are only used to support the legacy
opengl apis for setting filters and wrap modes where the state is
associated with texture objects instead of being associated with sampler
objects.

This part of an effort to clearly delimit our abstraction over opengl so
that we can start to consider non-opengl backends for Cogl.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6f78b8a613340d7c6b736e51a16c625f52154430)
2013-01-22 17:47:58 +00:00
Robert Bragg
df21e20f65 Adds CoglError api
Although we use GLib internally in Cogl we would rather not leak GLib
api through Cogl's own api, except through explicitly namespaced
cogl_glib_ / cogl_gtype_ feature apis.

One of the benefits we see to not leaking GLib through Cogl's public API
is that documentation for Cogl won't need to first introduce the Glib
API to newcomers, thus hopefully lowering the barrier to learning Cogl.

This patch provides a Cogl specific typedef for reporting runtime errors
which by no coincidence matches the typedef for GError exactly.  If Cogl
is built with --enable-glib (default) then developers can even safely
assume that a CoglError is a GError under the hood.

This patch also enforces a consistent policy for when NULL is passed as
an error argument and an error is thrown. In this case we log the error
and abort the application, instead of silently ignoring it. In common
cases where nothing has been implemented to handle a particular error
and/or where applications are just printing the error and aborting
themselves then this saves some typing. This also seems more consistent
with language based exceptions which usually cause a program to abort if
they are not explicitly caught (which passing a non-NULL error signifies
in this case)

Since this policy for NULL error pointers is stricter than the standard
GError convention, there is a clear note in the documentation to warn
developers that are used to using the GError api.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit b068d5ea09ab32c37e8c965fc8582c85d1b2db46)

Note: Since we can't change the Cogl 1.x api the patch was changed to
not rename _error_quark() functions to be _error_domain() functions and
although it's a bit ugly, instead of providing our own CoglError type
that's compatible with GError we simply #define CoglError to GError
unless Cogl is built with glib disabled.

Note: this patch does technically introduce an API break since it drops
the cogl_error_get_type() symbol generated by glib-mkenum (Since the
CoglError enum was replaced by a CoglSystemError enum) but for now we
are assuming that this will not affect anyone currently using the Cogl
API. If this does turn out to be a problem in practice then we would be
able to fix this my manually copying an implementation of
cogl_error_get_type() generated by glib-mkenum into a compatibility
source file and we could also define the original COGL_ERROR_ enums for
compatibility too.

Note: another minor concern with cherry-picking this patch to the 1.14
branch is that an api scanner would be lead to believe that some APIs
have changed, and for example the gobject-introspection parser which
understands the semantics of GError will not understand the semantics of
CoglError. We expect most people that have tried to use
gobject-introspection with Cogl already understand though that it is not
well suited to generating bindings of the Cogl api anyway and we aren't
aware or anyone depending on such bindings for apis involving GErrors.
(GnomeShell only makes very-very minimal use of Cogl via the gjs
bindings for the cogl_rectangle and cogl_color apis.)

The main reason we have cherry-picked this patch to the 1.14 branch
even given the above concerns is that without it it would become very
awkward for us to cherry-pick other beneficial patches from master.
2013-01-22 17:47:39 +00:00
Neil Roberts
f1baa4d60f Clear the scissor before calling glBlitFramebuffer in swap_region
glBlitFramebuffer is affected by the scissor so we need to ensure
there is an empty clip flushed before using it. This is similar to
what is done in _cogl_blit_framebuffer().

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Tested-by: Aaron Plattner <aplattner@nvidia.com>

(cherry picked from commit 65da3f88af9c7b8d72758d116c2652aff68195c1)
2013-01-07 16:37:29 +00:00
Neil Roberts
6a62e3077b sdl: Don't set SDL_GL_DOUBLEBUFFER when the swap chain has no pref
The ‘length’ for the swap chain is initially -1 which is supposed to
mean ‘no preference’. However, both of the SDL winsys's were
explicitly setting the SDL_GL_DOUBLEBUFFER attribute to zero in that
case which would try to disable double buffering.

On OS X, the equivalent to eglSwapBuffers (ie, [NSOpenGLContext
flushBuffer]) does nothing for a single buffer context. The
cogl-sdl-hello example does not specify the swap chain length so
presumably it would end up with a single buffer config. When
cogl_onscreen_swap_buffers is called it therefore does nothing and
nothing is painted.

I guess to make single-buffered contexts actually useful we should
expose some public equivalent to glFlush so that you can ensure the
rendering commands will actually hit the buffer. Alternatively we
could document that cogl_onscreen_swap_buffers performs this task on
single-buffered configs and then we could make the SDL winsys
explicitly call glFlush in that case.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 71e57f99002d5dee79bbd44b3bc57712b99acb55)
2012-11-23 15:45:26 +00:00
Rob Bradford
0e33654efb wayland: Port to new Wayland protocol
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit db50c3015c589375029a4c26c58db8295bb17bca)
2012-10-18 17:25:21 +01:00
Neil Roberts
0edb848850 Use the right context when pushing the GLES2 context to an onscreen
Previously when pushing the GLES2 context with an onscreen framebuffer
it would just call bind_onscreen. This actually binds it with Cogl's
context so presumably the context isolation wasn't working properly.
This patch splits out bind_onscreen to have a second function called
bind_onscreen_with_context that explicitly takes the EGL context to
use. Cogl now uses this when pushing the GLES2 context.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3653c5b10058a3f79900eb2644cb30f4cf1ca47e)
2012-10-01 15:05:22 +01:00
Neil Roberts
07a50012b9 egl: Only allow GLES2 context creation for the GLES2 driver
Previously, Cogl was advertising the GLES2 context feature whenever
the EGL winsys was used, even if the winsys was used with the GL
driver. This wasn't working because when the GL context is created the
API is set to GL with eglBindAPI and it is never changed back to GLES
when the GLES2 context is created. That meant that the created context
is actually GL not GLES2. Any rendering would then fail because the GL
context does not understand the precision statement.

It could be possible to fix it so that it will set the API correctly
before creating the context. It would then also need to reset the API
and unbind the previous context whenever switching between GLES2 and
GL contexts. If the context isn't unbound first then eglMakeCurrent
will actually try to bind both contexts at the same time and at least
Mesa detects this situation and reports that the two contexts
conflict. Presumably we would also need to do something more clever
when we retrieve the function pointers for the GLES2 context.
Currently we just copy them from the CoglContext but if the context is
using the GL driver then this would mean the functions came from libGL
not libGLESv2.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 624dea207cf76ae9ccd7f57c4ebd15d3bd65bff0)
2012-10-01 15:05:11 +01:00
Neil Roberts
f9e7f8df94 winsys-glx: Remove the vblank counter feature when indirect rendering
Previously when Cogl detects that the GLX context is indirect it
resets the function pointers for the VBLANK_COUNTER feature to NULL.
However it wasn't removing the VBLANK_COUNTER feature flag. Some other
parts of the winsys check for that feature flag rather than checking
whether the pointer is NULL so it would end up calling an invalid
function pointer and crashing. This just fixes it to also clear the
feature flag.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit e947c713a541086f80a308d22774229f0720196a)
2012-09-28 17:15:11 +01:00
Robert Bragg
0f0ee4a909 texture: Add a context pointer to each texture
As part of our on-going goal to remove our dependence on a global Cogl
context this patch adds a pointer to the context to each CoglTexture
so that the various texture apis no longer need to use
_COGL_GET_CONTEXT.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 83131072eea395f18ab0525ea2446f443a6033b1)
2012-09-17 23:06:20 +01:00
Neil Roberts
27d74f09df kms: Fix the version check for GBM
The check for whether to use ‘stride’ instead of ‘pitch’ from the GBM
API tries to check whether the GBM version is >= 8.1.0. However it was
comparing the major and micro components independently so any version
with the minor part set to 0 would fail. The GBM version in Mesa
master is now 9.0.0 which breaks it. This patch changes it to check
the version using the COGL_VERSION_ENCODE macro instead.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 38f1dc58b35023f9e6bbc0db746b1554bd0377fc)
2012-09-06 18:30:30 +01:00
Robert Bragg
74d749eca4 kms: Update to latest gbm api
gbm_bo_get_pitch was renamed to gbm_bo_get_stride to be consistent with
how the terms pitch and stride are used throughout mesa. This updates
the Cogl backend to use the new gbm_bo_get_stride name.

For compatibility with previous version of libgbm we now explicitly
check the version of libgbm in configure.ac and expose
COGL_GBM_{MAJOR,MINOR,MICRO} defines to the code so we can conditionally
use the older gbm_bo_get_pitch() name with older versions.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 47c6247095e2f1f8725c4eb08d38c9de15e283cd)
2012-09-03 15:51:44 +01:00
Neil Roberts
32fbd0ada6 kms: Use a dummy surface instead of the surfaceless extension
The surfaceless extension that Mesa advertises has been renamed to
EGL_KHR_surfaceless_context instead of a separate extension for the
GLES, GLES2 and GL APIs and the new extension has been ratified by
Khronos. Therefore the KMS backend no longer runs against Mesa master.
We could just rename the extension we check for, however Weston (the
sample Wayland compositor) has switched to just creating a dummy GBM
surface and not using the surfaceless extension at all. We should
probably do the same thing.

Using the surfaceless extension could be a good idea but we don't
really need to rely on it for KMS and we would want to do it for all
EGL backends, not just the KMS backend.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit d4f22f8cb013d417c99ba03924538924191c2fe6)
2012-08-15 17:29:16 +01:00
Neil Roberts
96b726b518 cogl-winsys-sdl: Fix the signature for the get_proc_address method
This function should take an extra third paramter to specify whether
the procedure is in core or not. The parameter is not used so this
patch just fixes an annoying warning.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit eed4ac80cd8c3fa1859493c9bb00547038be6095)
2012-08-06 18:51:33 +01:00
Neil Roberts
59ff396875 cogl-winsys-egl-kms: Remove some unused variables
This just gets rid of some annoying warnings.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3d0aea04d1f6a8094b749e20a59d8a9a95a6235e)
2012-08-06 18:51:33 +01:00
Neil Roberts
74fd618df9 Add conf vars to trick Cogl to think extensions are disabled
This adds two new configuration environment variables:

COGL_DISABLE_GL_EXTENSIONS and
COGL_OVERRIDE_GL_VERSION

The variables can also be set in the cogl.conf file using the same
names.

The first one is a list of GL extension names separated by commas.
When set Cogl will assume any extension listed here is not available
by removing it from the string returned from
glGetString(GL_EXTENSIONS). If the string is set in both the config
file and the environment variable then the union of the two lists will
be used.

The second overrides the value returned from glGetString(GL_VERSION).
If the string is set in both places the version from the environment
variable will take priority.

These are sometimes useful for debugging Cogl to test the various
combinations of extensions. It could also be useful to work around
driver bugs where an extension is badly supported and it would be
better not to use it.

The variables in cogl-config that just set a global char * variable
have been put together in an array instead of having a separate blob
of code for each one in order to make it simpler to add new variables.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit ec69c2dc576c78664e0b73879365cb7414ecf441)
2012-08-06 18:51:33 +01:00
Damien Lespiau
e5fea8b734 egl-x11: Don't use GLXDrawable on EGL
Someone trying to compile cogl (ThijsNL on irc0 for the Rasberry Pi
stumbled into that one. GLXDrawable may not be defined in a pure EGL/X
environment.

Change it to Window, the type used for XConfigureEvent.window.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit f05d6923fff28b1d167a391d486e319743c49215)
2012-08-06 18:51:33 +01:00
Tomeu Vizoso
bb258c1d42 Avoid including the EGL headers from the public Cogl headers
Otherwise, X11 identifiers may leak and cause havoc in big applications

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit ed0cdca0eca815543619fe72fbd42d662d53f92d)
2012-08-06 18:51:32 +01:00
Robert Bragg
df51574116 onscreen: Adds support for resizable windows
This adds api to be able to request that the window system allows a
given onscreen framebuffer to be resizable, and api to add and remove
resize handlers to be called whenever the framebuffer does actually
change size.

The new functions are:
  cogl_onscreen_{get,set}_resizable()
  cogl_onscreen_{add,remove}_resize_handler()

The examples cogl-hello and cogl-x11-foreign have been updated to use
the new api. To smoke test how Cogl updates the viewport automatically
in response to window resizes the cogl-hello test doesn't explicitly
respond to resize events by setting the viewport and cogl-x11-foreign
responds by setting a viewport that is offset by a quarter of the
window's width/height and half the width and height of the window.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit a1a8cc00bfa2cecaf1007aec5f3dd95dc07b1786)
2012-08-06 18:51:32 +01:00
Neil Roberts
df77e8565e Don't use eglGetProcAddress to retrieve core functions
According to the EGL spec, eglGetProcAddress should only be used to
retrieve extension functions. It also says that returning non-NULL
does not mean the extension is available so you could interpret this
as saying that the function is allowed to return garbage for core
functions. This seems to happen at least for the Android
implementation of EGL.

To workaround this the winsys's are now passed down a flag to say
whether the function is from the core API. This information is already
in the gl-prototypes headers as the minimum core GL version and as a
pair of flags to specify whether it is available in core GLES1 and
GLES2. If the function is in core the EGL winsys will now avoid using
eglGetProcAddress and always fallback to querying the library directly
with the GModule API.

The GLX winsys is left alone because glXGetProcAddress apparently
supports querying core API and extension functions.

The WGL winsys could ideally be changed because wglGetProcAddress
should also only be used for extension functions but the situation is
slightly different because WGL considers anything from GL > 1.1 to be
an extension so it would need a bit more information to determine
whether to query the function directly from the library.

The SDL winsys is also left alone because it's not as easy to portably
determine which GL library SDL has chosen to load in order to resolve
the symbols directly.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 72089730ad06ccdd38a344279a893965ae68cec1)

  Since we aren't able to break API on the 1.12 branch
  cogl_get_proc_address is still supported but isn't easily able to
  determine whether the given name corresponds to a core symbol or
  not.  For now we just assume the symbol being queried isn't part
  of the core GL api and update the documentation accordingly.
2012-08-06 14:27:45 +01:00
Neil Roberts
17c818a9a7 Add an SDL2 winsys
This adds an alternate version of the SDL winsys using the SDL 2 API.
The two versions are mutually exclusive and share the same
CoglWinsysID. Version 2 of SDL fits a little bit better with Cogl
because it supports multiple windows and the video subsystem can be
initialised entirely independently of the rest of the subsystems.

The SDL2 winsys creates an invisible dummy window in order to bind the
GL context after creating the Cogl display. This is similar to how the
X11 winsys's work.

SDL2 seems to support compiling with support for both GL and GLES.
However there doesn't seem to be a way to select between the two
backends outside of SDL. In fact if you do compile them both in it
seems to break down because it will always try to use the window
system functions from the GLES backend because those are filled in
second in the vtable. However when creating the window it will always
prefer to use the GL function to choose a visual. This function gets
confused because the GL backend has not been initialised at that
point. The Cogl backend therefore just leaves it up to SDL to pick a
sensible backend. It will then verify that it picked a GL library
which matches the Cogl driver by checking the string from
glGetString(GL_VERSION).

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 6cb5ab41355e7bfe28f367cf4afa39a7afcfeec2)
2012-08-06 14:27:44 +01:00
Robert Bragg
498937083e Adds gles2-context renderer constraint
This adds a new renderer constraint enum:
  COGL_RENDERER_CONSTRAINT_SUPPORTS_GLES2_CONTEXT
that can be used by applications to ensure the renderer they connect to
has support for creating a GLES2 context via cogl_gles2_context_new().

The cogl-gles2-context and cogl-gles2-gears examples and the conformance
tests have been updated to use this constraint.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit ed61463d7194354b26624e8014859f0fbfc06a12)
2012-08-06 14:27:43 +01:00
Robert Bragg
010d16f647 Adds initial GLES2 integration support
This makes it possible to integrate existing GLES2 code with
applications using Cogl as the rendering api.

Currently all GLES2 usage is handled with separate GLES2 contexts to
ensure that GLES2 api usage doesn't interfere with Cogl's own use of
OpenGL[ES]. The api has been designed though so we can provide tighter
integration later.

The api would allow us to support GLES2 virtualized on top of an
OpenGL/GLX driver as well as GLES2 virtualized on the core rendering api
of Cogl itself. Virtualizing the GLES2 support on Cogl will allow us to
take advantage of Cogl debugging facilities as well as let us optimize
the cost of allocating multiple GLES2 contexts and switching between
them which can both be very expensive with many drivers.

As as a side effect of this patch Cogl can also now be used as a
portable window system binding API for GLES2 as an alternative to EGL.

Parts of this patch are based on work done by Tomeu Vizoso
<tomeu.vizoso@collabora.com> who did the first iteration of adding GLES2
API support to Cogl so that WebGL support could be added to
webkit-clutter.

This patch adds a very minimal cogl-gles2-context example that shows how
to create a gles2 context, clear the screen to a random color and also
draw a triangle with the cogl api.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 4bb6eff3dbd50d8fef7d6bdbed55c5aaa70036a8)
2012-08-06 14:27:42 +01:00
Robert Bragg
a945890de6 Workaround drisw bug where clipped redraws don't work
This detects when we are running on any of Mesa's software rasterizer
backends and disables use of glBlitFramebuffer and glXCopySubBuffer.
Both of these currently result in full-screen copies so there's little
point in using these to optimize how much of the screen we present.

To help ensure we re-evaluate this workaround periodically we have added
a comment marker of "ONGOING BUG" above the workaround and added a note
to our RELEASING document that says we should grep for this marker and
write a NEWS section about ongoing bug workarounds.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 11f2f6ebb42398978ec8dd92b3c332ae8140a728)
2012-08-06 14:27:42 +01:00
Neil Roberts
68a6e82828 Add support for the WebOS version of SDL
The stock 1.2.x version of SDL only supports regular OpenGL. The
version on WebOS is specially patched to add some extra API to request
a GLES1 or GLES2 context. This patch adds a configure check to detect
when Cogl is being built with the patched version of SDL. In that case
it will additionally allow the gles1 and gles2 drivers and set the
right video mode attributes to get the corresponding context.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 3726c60deab2bd94617a562abb63f735627a25e4)
2012-08-06 14:27:41 +01:00
Robert Bragg
54735dec84 Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.

Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.

Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.

So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.

Instead of gsize we now use size_t

For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-08-06 14:27:39 +01:00
Robert Bragg
09642a83b5 Removes all remaining use of CoglHandle
Removing CoglHandle has been an on going goal for quite a long time now
and finally this patch removes the last remaining uses of the CoglHandle
type and the cogl_handle_ apis.

Since the big remaining users of CoglHandle were the cogl_program_ and
cogl_shader_ apis which have replaced with the CoglSnippets api this
patch removes both of these apis.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 6ed3aaf4be21d605a1ed3176b3ea825933f85cf0)

  Since the original patch was done after removing deprecated API
  this back ported patch doesn't affect deprecated API and so
  actually this cherry-pick doesn't remove all remaining use of
  CoglHandle as it did for the master branch of Cogl.
2012-08-06 14:27:39 +01:00
Damien Lespiau
943afe5711 winsys-glx: Remove unused variable
Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 2cffcae81fd91d97bfa239e8c7c6a5b2cefb2653)
2012-08-06 14:27:38 +01:00
Robert Bragg
9a1f1df83f Rework sdl integration api
This re-works the SDL integration api to simplify the integration for
application developers and also allow Cogl to know when the application
is about to go idle waiting for events so it can perform idle
book-keeping work.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-12 12:31:46 +01:00
Robert Bragg
bdb645e7f5 kms: defer setting crtc modes until first swap buffers
Instead of creating a dummy framebuffer allocation just so we can setup
crtc modes during display_setup we now wait until the first swap_buffers
request before setting up the crtc modes.

This patch also adds a cogl_kms_display_queue_modes_reset() function
that allows developers to explicitly queue a reset of the crtc modes.
The idea is that applications that handle VT switching can use this for
VT enter events to explicitly ensure their mode is restored since modes
are often not automatically restored correctly.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-11 15:44:58 +01:00
Robert Bragg
125c31a70b kms: Add mirror support and env var configurability
This adds support for mirroring the display output on two KMS
connectors.

This patch also checks for a number of environment variables that can
influence how KMS is configured. The following variables can be set:

COGL_KMS_MIRROR: If this is set to anything then Cogl will try and setup
two connectors with the same resolution so that onscreen frame buffers
can be mirrored.

COGL_KMS_CONNECTOR0: This can be set to an integer identifier for a
specific KMS connector id to use for the first output.

COGL_KMS_CONNECTOR0_MODE: Can be set to a mode name like "1024x768"
explicitly select what mode should be used for the first output.

If COGL_KMS_MIRROR is set then COGL_KMS_CONNECTOR1 and
COGL_KMS_CONNECTOR1_MODE can optionally be set to specify a connector id
and mode name for the second output.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-04-11 15:44:58 +01:00
Neil Roberts
f9d3ea03ec kms: Implement the swap buffers notify feature
The KMS EGL platform now notifies when a swap is complete. The
notification is delayed until the application calls
cogl_context_dispatch. The GLX backend doesn't currently do this but I
think that is how it should behave to make it easier for the
application to handle locks and such.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:50 +01:00
Neil Roberts
cfefff1500 egl-kms: Use drmModePageFlip
The KMS platform now uses drmModePageFlip to present the buffer. The
main loop mechanism is used to poll for events on the DRM file
descriptor so that we notice when the page flip is complete. The
swap_buffers is throttled so that if there is a pending flip it will
block until it is complete before starting another flip.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:45 +01:00
Neil Roberts
d1d2120a91 kms: Use GBM surfaces
Instead of creating FBOs on the GL side, the KMS EGL platform uses the
latest changes to Mesa to create an EGL surface using a GBM surface as
the native surface type. This removes some of the special vtable hooks
that the KMS platform needed because it is now much more similar to
the other platforms.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-11 15:44:32 +01:00
Neil Roberts
e7f1582630 Add a CoglPrimitiveTexture interface
This interface represents any textures that are backed by a single
texture in GL and that can be used directly with the
cogl_framebuffer_draw_attributes family of functions. This currently
equates to CoglTexture2D, CoglTexture3D and CoglTextureRectangle.

The interface currently has only one method called
cogl_primitive_set_auto_mipmap. This replaces the
COGL_TEXTURE_NO_AUTO_MIPMAP flag from the CoglTextureFlags parameter
in the constructors. None of the other flags in CoglTextureFlags make
sense for primitive textures so it doesn't seem like a good idea to
need them for primitive constructors.

There is a boolean in the vtable to mark whether a texture type is
primitive which the new cogl_is_primitive function uses. There is also
a new texture virtual called set_auto_mipmap which is only required to
be implemented for primitive textures.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-04-04 17:02:23 +01:00
Adel Gadllah
fd31da45e2 winsys-glx: Don't assume that copy_sub_buffer is synchronized
We initially assumed that copy_sub_buffer is synchronized on
which is only the case for a subset of GPUs for example it is not
synchronized on INTEL gen6 and gen7, so we remove this assumption
for now.

We should have a specific driver / GPU whitelist if we want to enable
this.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-03-15 15:48:13 +00:00
Neil Roberts
185630085c Add -Wmissing-declarations to maintainer flags and fix problems
This option to GCC makes it give a warning whenever a global function
is defined without a declaration. This should catch cases were we've
defined a function but forgot to put it in a header. In that case it
is either only used within one file so we should make it static or we
should declare it in a header.

The following changes where made to fix problems:

• Some functions were made static

• cogl-path.h (the one containing the 1.0 API) was split into two
  files, one defining the functions and one defining the enums so that
  cogl-path.c can include the enum and function declarations from the
  2.0 API as well as the function declarations from the 1.0 API.

• cogl2-clip-state has been removed. This only had one experimental
  function called cogl_clip_push_from_path but as this is unstable we
  might as well remove it favour of the equivalent cogl_framebuffer_*
  API.

• The GLX, SDL and WGL winsys's now have a private header to define
  their get_vtable function instead of directly declaring in the C
  file where it is called.

• All places that were calling COGL_OBJECT_DEFINE need to have the
  cogl_is_whatever function declared so these have been added either
  as a public function or in a private header.

• Some files that were not including the header containing their
  function declarations have been fixed to do so.

• Any unused error quark functions have been removed. If we later want
  them we should add them back one by one and add a declaration for
  them in a header.

• _cogl_is_framebuffer has been renamed to cogl_is_framebuffer and
  made a public function with a declaration in cogl-framebuffer.h

• Similarly for CoglOnscreen.

• cogl_vdraw_indexed_attributes is called
  cogl_framebuffer_vdraw_indexed_attributes in the header. The
  definition has been changed to match the header.

• cogl_index_buffer_allocate has been removed. This had no declaration
  and I'm not sure what it's supposed to do.

• CoglJournal has been changed to use the internal CoglObject macro so
  that it won't define an exported cogl_is_journal symbol.

• The _cogl_blah_pointer_from_handle functions have been removed.
  CoglHandle isn't used much anymore anyway and in the few places
  where it is used I think it's safe to just use the implicit cast
  from void* to the right type.

• The test-utils.h header for the conformance tests explicitly
  disables the -Wmissing-declaration option using a pragma because all
  of the tests declare their main function without a header. Any
  mistakes relating to missing declarations aren't really important
  for the tests.

• cogl_quaternion_init_from_quaternion and init_from_matrix have been
  given declarations in cogl-quaternion.h

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-03-06 18:45:44 +00:00
Neil Roberts
933db01833 cogl-winsys-egl-wayland: Include cogl-wayland-renderer.h
The Wayland winsys defines functions declared in
cogl-wayland-renderer.h so it should include the header to make sure
the declarations are right. This was breaking because currently the
header #defines the _EXP suffixes on to the function names so it would
end up exporting the wrong symbol names.
2012-02-29 17:45:43 +00:00
Robert Bragg
be237cc2b7 renderer: Adds getters/setters for driver preference
This adds api for explicitly choosing what underlying driver cogl should
use internally for rendering as well as api for querying back what
driver is actually in use.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-24 14:42:31 +00:00
Robert Bragg
4e3f9d0fc2 tex-pixmap-x11: remove CoglHandle use + pass context
This also replaces use of CoglHandle with a CoglTexturePixmapX11 type
instead.

This patch also ensures the CoglTexturePixmapX11 constructor take an
explicit CoglContext pointer and can return a GError consistent with
other CoglTexture constructors.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-21 13:26:14 +00:00
Robert Bragg
680f63a48c Remove all internal includes of cogl.h
The cogl.h header is meant to be the public header for including the 1.x
api used by Clutter so we should stop using that as a convenient way to
include all likely prototypes and typedefs. Actually we already do a
good job of listing the specific headers we depend on in each of the .c
files we have so mostly this patch just strip out the redundant
includes for cogl.h with a few fixups where that broke the build.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-20 23:12:45 +00:00
Damien Leone
8b70468598 Improve pixel format detection for fallback OpenGL rendering
The previous detection was based on bits per pixel only and would
consider bpp >= 24 as X888 or 8888 24-bit color depth formats.

This commit ensures we now use the newly added
_cogl_util_pixel_format_from_masks() api that returns a CoglPixelFormat
according to channel masks and color depth. This helps to add support
for more pixel formats.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-20 23:12:45 +00:00
Robert Bragg
1022c285c6 texture-pixmap-x11.h: define __COGL_H_INSIDE__
Ideally we wouldn't have exposed cogl-texture-pixmap-x11.h as a
top level header and would have just automatically included it in cogl.h
but we already have code that assumes it can be directly included.

This ensures we define __COGL_H_INSIDE__ as a reminder that it is a top
level header in case we later need to include other cogl internal cogl
headers which would cause a build time error without this defined.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-20 23:12:44 +00:00
Neil Roberts
8012eee31f Add _cogl_texture_get_type()
This adds an internal function to get the type of the underlying
hardware texture for any CoglTexture. It can return one of three
values to represent 2D textures, 3D textures or rectangle textures.
The idea is that this can be used as a replacement for
cogl_texture_get_gl_texture when only the target is required to make
it a bit less GL-centric. The implementation adds a new virtual
function which all of the texture backends now implement.

The enum is in a public header because a later patch will want to use
it from the CoglPipeline API. We may want to consider making the
function public too later.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-02-13 17:02:46 +00:00
Robert Bragg
15d43bb697 glx: Only call swap_buffer callbacks @ dispatch time
This ensures we don't call swap buffer notify callback functions
immediately when they are received since it could be awkward for
applications to ensure they have dropped all necessary locks if they
don't know when callbacks might be invoked.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-08 18:58:06 +00:00
Robert Bragg
0f33c942f2 kms: gracefully handle NULL save_state at cleanup
If we failed to save any crtc state then we skip trying to restore the
old state at cleanup.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-08 17:00:25 +00:00
Robert Bragg
1a638b6fd6 kms: Adds api to get at the kms file descriptor
This adds a cogl_kms_renderer_get_kms_fd() function that lets developers
access the kms file descriptor being used for controlling the kernel
mode setting.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-02-08 17:00:25 +00:00
Neil Roberts
99c651d2b4 Move the add_swap_buffers_callback functions out of the winsys
Instead of having each winsys implement its own list of callbacks the
list is now just attached directly to the CoglOnscreen using code in
cogl-onscreen.c. The winsys's can invoke this list of callbacks by
calling _cogl_onscreen_notify_swap_buffers(). All of the winsys's
would probably have a very similar implementation for this anyway and
I don't think it makes much sense to try and save the cost of a list
pointer in the CoglOnscreen struct.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-02-08 17:00:25 +00:00
Neil Roberts
139421de19 object: Remove the type member of CoglObjectClass
Unlike in GObject the type number for a CoglObject is entirely an
internal implementation detail so there is no need to make a GQuark to
make it safe to export out of the library. Instead we can just
directly use a fixed pointer address as the identifier for the type.
This patch makes it use the address of the class struct of the
identifier. This should make it faster to do type checks because it
does not need to call a function every time it wants to get the type
number.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-01-27 17:18:32 +00:00
Robert Bragg
87ce1b21f9 wayland: perform buffer resizes lazily at swap buffers
Resizing a wayland client framebuffer should not affect the viewport
of additional primitives drawn to that framebuffer before the next swap
buffers request nor should querying the framebuffer's width and height
be affected until the next swap buffers request completes.

This patch changes cogl_wayland_onscreen_resize() so it only saves the
new geometry as "pending" state internal to the given CoglOnscreen. Only
when cogl_framebuffer_swap_buffers() is next called will the pending
size be flushed to the wayland egl api.
2012-01-16 18:27:20 +00:00
Robert Bragg
e1bd0b2090 Swaps a few uses of gint for int
We've avoiding using the redundant glib typedefs such as guint, gint
gpointer etc and prefer to use the equivalent C types so this patch
removes a few uses of gint that slipped past review.
2012-01-16 18:27:20 +00:00
Robert Bragg
3161f1b0e6 template: Allow configuration of swap throttle
This adds cogl_onscreen_template_set_swap_throttled() api that allows
developers to specify their preference for swap buffer throttling
up-front as part of the onscreen template that is used to create a
CoglDisplay when initializing Cogl. This is desirable because some
platforms may not support configuring swap throttling on a per
framebuffer basis and also since applications often want to apply the
same policy to all onscreen framebuffers anyway.
2012-01-16 18:27:20 +00:00
Robert Bragg
a8513c1d77 renderer: Adds api to add/remove selection constraints
This allows applications to specify certain constraints that feed into
the process of selecting a CoglRenderer backend. For example
applications might depend on x11 for handling input and so they require
a backend that's also based on x11.
2012-01-16 18:27:19 +00:00
Rob Bradford
8632c65e79 wayland: Add a cogl_wayland_onscreen_resize function
This function will call into the Wayland EGL platform API and resize the
surface that the window is using and update the internal dimensions for
framebuffer and viewport to reflect the change.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-01-13 13:56:12 +00:00
Neil Roberts
cbbac5a2f5 Add a feature ID for the swap event notification
Previously the swap event notification feature was only accessible as
a winsys feature using the semi-internal
cogl_clutter_winsys_has_feature. This just adds a feature ID for it so
it can also be accessed via cogl_has_feature.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-01-09 18:59:59 +00:00
Robert Bragg
3bc70687ac Remove old fallback for vblank wait via manual drm ioctl
This workaround code has just been incrementally carried forward since
Cogl was integrated with Clutter but really we have no idea when this
code path was ever tested. Since the work around is from before the time
of the current Cogl developers we don't know anything about the
circumstances which led to this extreme workaround instead of pushing to
fix a driver.

It seems pretty likely we can push to fix any drm based drivers so
we're removing the workaround.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2012-01-05 20:31:09 +00:00
Neil Roberts
181b875a3d xlib: Internally retrieve XEvents
Previously we relied on the application to send all X events through
Cogl using cogl_xlib_renderer_handle_event. This breaks the
abstraction that an application shouldn't need to know what winsys
Cogl is using. Now that we have main loop integreation in Cogl, the
Xlib-based winsys's can report that Cogl needs to block on the file
descriptor of the X connection and it can manually handle the
events.

The event retrieval can be disabled by an application if it calls the
new cogl_xlib_renderer_set_event_retrieval_enabled() function. The
event retrieval will also automatically be disabled if the application
sets a foreign display.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-01-05 13:40:24 +00:00
Neil Roberts
7497475295 Add support for main loop integration
This adds two new functions:

void
cogl_poll_get_info (CoglContext *context,
                    CoglPollFD **poll_fds,
                    int *n_poll_fds,
                    gint64 *timeout);

void
cogl_poll_dispatch (CoglContext *context,
                    const CoglPollFD *poll_fds,
                    int n_poll_fds);

The application is expected to call the first function whenever it is
about to block to go idle, and the second function whenever it comes
out of idle. This gives Cogl winsys's the ability poll file
descriptors for events. For example when handing swap complete
notifications, it can report that it needs to block on a file
descriptor.

The two functions are backed by winsys virtual functions. There are
currently no implementations. The default handler for get_info just
reports no file descriptors and an infinite timeout.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-01-05 13:40:10 +00:00
Neil Roberts
24fe7c300c cogl-texture-pixmap-x11: Fix the foreach_sub_texture_in_region impl
The foreach_sub_texture_in_region implementation tries to forward the
function on to its child texture but it was mistakenly forwarding back
on to itself so it would just recurse endlessly and crash.
2011-12-20 12:46:50 +00:00
Neil Roberts
bdcbb8af4d Update the SDL winsys
The SDL winsys was missing a few minor features, such as the
implementation. This patch adds that in.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-14 16:45:17 +00:00
Neil Roberts
616d27f169 cogl-texture-2d: Fix checking for the EGL winsys
CoglTexture2D had an assert to verify that the EGL winsys was being
used. This doesn't make any sense any more because the EGL winsys
can't be used directly but instead it is just a base winsys for the
platform winsys's. To fix this this patch adds a set of 'criteria'
flags to each winsys, one of which is 'uses EGL'. CoglTexture2D can
use this to determine if the winsys is supported.

Eventually we might want to expose these flags publically so that an
application can select a winsys based on certain conditions. For
example, an application may need a winsys that uses X or EGL but
doesn't care exactly which one it is.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-14 16:41:16 +00:00
Neil Roberts
ff5bfc4a86 Rename the EGL_X11 winsys to EGL_XLIB
Eventually we might want to have an XCB-based EGL winsys. We already
have xlib-specific API in CoglRenderer (eg, to set a foreign display)
so the application needs to be able to specifically select between XCB
and XLIB.

This also removes the POWERVR part while renaming
COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT to
COGL_HAS_EGL_PLATFORM_XLIB_SUPPORT because the winsys is equally
applicable to Mesa.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-14 16:40:26 +00:00
Neil Roberts
3a4dce0c53 Move the EGL Android winsys out of cogl-winsys-egl
This moves all of the code specific to the Android platform out of
cogl-winsys-egl. It is completely untested apart from that it
compiles using a dummy android/native_window.h header.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-13 16:08:37 +00:00
Neil Roberts
d70c764da6 Move the EGL GDL winsys out of cogl-winsys-egl
This moves all of the code specific to the gdl winsys out of
cogl-winsys-egl. It is completely untested apart from that it
compiles.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-13 16:08:37 +00:00
Neil Roberts
f1d831d644 Move the EGL null winsys out of cogl-winsys-egl
This moves all of the code specific to the null winsys out of
cogl-winsys-egl.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-13 13:12:17 +00:00
Neil Roberts
a6b1f55546 kms: Don't use egl_surface_width/height
The egl_surface_width/height properties in CoglDisplayEGL were
accidentally being conditionally defined depending on KMS
support. They are not necessary because CoglDisplayKMS also already
stores the width/height and this was just copied over to the EGL
dipslay.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-13 13:12:16 +00:00
Neil Roberts
4dbef01ec3 winsys: Move Wayland-specific code out of the EGL winsys
All of the Wayland-specific code now lives in the EGL_WAYLAND winsys.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-12 17:41:43 +00:00
Neil Roberts
613a3390da winsys: Move X11/Xlib-specific code out of the EGL winsys
All of the X11/Xlib-specific code now lives in the EGL_X11 winsys.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-12 16:14:19 +00:00
Neil Roberts
a72a2c99fe Don't bother trying to accept NULL in _cogl_winsys_onscreen_bind
The GLX and EGL winsys backends had a check for when onscreen==NULL
in which case they would instead try to bind the dummy surface. This
wouldn't work however because it would have already crashed by that
point when it tried to get the Cogl context out of the onscreen. The
function needs a bit of refactoring before it could support this but
presumably nothing is relying on this anyway because it wouldn't work
so for now we can just remove it.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-12 16:14:18 +00:00
Neil Roberts
7f74712a79 Remove CoglXlibDisplay
CoglXlibDisplay just contained one member called dummy_xwin. This was
not shared outside of the respective winsys's so I don't think it
really makes sense to have a separate shared struct for it. It seems
more like an implementation detail that is specific to the winsys
because for example it may be that the EGL winsys could use the
surfaceless extension and not bother with a dummy window. This will
also make it easier to factor out the Xlib-specific data in
CoglDisplayEGL to the platform data.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-12 16:14:18 +00:00
Neil Roberts
a8f84af776 cogl-xlib-renderer: Move private data to cogl_object_set_user_data
Previously the Xlib renderer data was meant to be the first member of
whatever the winsys data is. This doesn't work well for the EGL winsys
because it only needs the Xlib data if the X11 platform is used. The
Xlib renderer data is now instead created on demand and connected to
the object using cogl_object_set_user_data. There is a new function to
get access to it.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-12 16:13:57 +00:00
Neil Roberts
dd75926c1a egl: Split out the KMS winsys as overrides of the EGL winsys
Instead of having #ifdefs to hook into the normal EGL winsys, the KMS
winsys now overrides any winsys functions that it wants. Where the
winsys wants to hook into a point within a function provided by the
EGL winsys there is a EGL-platform vtable which gets set on the EGL
renderer data during renderer_connect. The KMS-specific data on all of
the structures is now allocated separately by the KMS winsys and is
pointed to by a new 'platform' pointer in the EGL data.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-09 17:29:49 +00:00
Neil Roberts
93e6e2051f egl: Allow multiple EGL platforms
The #ifdefs in cogl-winsys-egl have been changed so that they
additionally check renderer->winsys_vtable->id for the corresponding
winsys ID so that multiple EGL platforms can be enabled.

The is a stop-gap solution until we can move all of the EGL platforms
into their own winsys files with overrides of the EGL vtable. However
with this approach we can move one platform at a time which will make
it easier.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-08 19:16:41 +00:00
Neil Roberts
a1e1527b69 Add a separate winsys vtable for each EGL platform
Instead of just having an "EGL" renderer, there is now a separate
winsys for each platform. Currently they just directly copy the vtable
for the EGL platform so it is still only possible to have one EGL
platform compiled into Cogl. However the intention is that the
winsys-specific code for each platform will be moved into override
functions in the corresponding platform winsys.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-08 17:38:25 +00:00
Rob Bradford
590e1c46f0 wayland: Add API to access the shell surface for the onscreen
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-08 16:21:57 +00:00
Rob Bradford
4928ca5a90 wayland: Port to latest Wayland API (to wl_surface_shell)
Requests for the shell to manipulate it's state for the surface are now
abstracted through a wl_shell_surface object rather through wl_shell as
before.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-08 16:19:50 +00:00
Neil Roberts
889e4aba9c kms: Check for the right surfaceless extension depending on driver
There are three separate EGL_KHR_surfaceless_* extensions depending on
which GL API is being used so we should probably check the right one
depending on which driver Cogl has selected.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-08 12:48:59 +00:00
Neil Roberts
7adf7c5e38 kms: Fix GLES2 support
There were two problems stopping the KMS winsys from working with a
GLES2 driver:

• When creating the EGL context, it was missing the attribute to
  select the client version so it would end up with the GLES1 API.

• When creating the depth buffer for the framebuffer it was using
  GL_DEPTH_COMPONENT but only GL_DEPTH_COMPONENT16 is supported on
  GLES. cogl-framebuffer already unconditionally uses this so it
  probably makes sense to do the same here.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-08 12:48:59 +00:00
Robert Bragg
79f20d08b6 wayland: Updates the wayland compositor side support
The compositor side wayland support enabling us to create textures from
wayland buffers needed updating since visuals were removed from the
wayland protocol.

This also fixes the #ifdef guards for the bind_wayland_display extension
in cogl-winsys-egl-feature-functions.h since it was mistakenly checking
that client-side wayland support had been enabled which won't be the
case.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-07 15:53:05 +00:00
Robert Bragg
14ddbd980b wayland: Add api to set a foreign shell
Since the wayland protocol doesn't currently provide a way to
retrospectively query the interfaces that get notified when a client
first connects then when using a foreign display with Cogl then we also
need api for telling cogl what compositor and shell objects to use. We
already had api for setting a foreign compositor so this patch just adds
api for setting a foreign shell.

This patch also adds documentation for all the wayland specific apis.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-07 15:53:05 +00:00
Neil Roberts
dba42715d4 egl-winsys: Bind the framebuffer before swapping
For some reason the EGL spec says that the surface passed to
eglSwapBuffers must be bound as the current surface for the swap to
work. Mesa validates that this is the case and returns an error from
the swap buffers call if not.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-12-07 12:08:15 +00:00
Robert Bragg
042dc7c8cd framebuffer: Optimize _cogl_framebuffer_flush_state()
Previously the cost of _cogl_framebuffer_state_flush() would always
scale by the total amount of state tracked by CoglFramebuffer even in
cases where we knew up-front that we only wanted to flush a subset of
the state or in cases where we requested to flush the same framebuffer
multiple times with no changes being made to the framebuffer.

We now track a set of state changed flags with each framebuffer and
track the current read/draw buffers as part of the CoglContext so that
we can quickly bail out when asked to flush the same framebuffer
multiple times with no changes.

_cogl_framebuffer_flush_state() now takes a mask of the state that we
want to flush and the implementation has been redesigned so that the
cost of checking what needs to be flushed and flushing those changes
now scales by how much state we actually plan to update.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-12-06 18:51:57 +00:00
Tomeu Vizoso
1de6575ca2 build: Add missing include in cogl-winsys-egl-private.h
We were missing APIENTRY.
2011-12-06 19:49:00 +01:00
Rob Bradford
7f2a896351 kms: Avoid using struct member before it is set
When saving the CRTC we were trying to use a struct member for the encoder
that wasn't valid at that point in time - instead use the local variable.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-30 15:37:09 +00:00
Robert Bragg
be40cbb8c3 build: include missing headers in cogl-winsys-egl-private.h
We were missing various platform header includes in
cogl-winsys-egl-private.h when building support for non KMS egl
platforms.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-28 23:19:45 +00:00
Robert Bragg
40b14c6084 kms: avoid using redundant g* and GL* types
A small, pedantic change to remove the use of redundant gint and GLuint
types instead of int and unsigned int.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-28 22:43:15 +00:00
Robert Bragg
056daad850 build: only include cogl-winsys-kms.h if KMS enabled
Only include cogl-winsys-kms.h in cogl-winsys-egl-private.h if KMS
support has been enabled.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-28 22:39:19 +00:00
Robert Bragg
aa6433d8c5 kms: Check for EGL_KHR_surfaceless_opengl extension
This adds a check for the EGL_KHR_surfaceless_opengl extension which we
depend on for being able to MakeCurrent (NO_SURFACE) as well as create a
context without and EGLConfig.

Reviewed-by: Rob Bradford <rob@linux.intel.com>
2011-11-28 17:38:17 +00:00
Robert Bragg
7a91c91994 kms: flatten setup_kms into _cogl_winsys_kms_display_setup
Since _cogl_winsys_kms_display_setup was basically just calling
setup_kms() it made sense to fold the code of setup_kms() back into the
_cogl_winsys_kms_display_setup() function.

Reviewed-by: Rob Bradford <rob@linux.intel.com>
2011-11-28 17:38:15 +00:00
Robert Bragg
607bfec48d kms: move Cogl*EGL typedefs to cogl-winsys-egl-private.h
So that the various internal Cogl*EGL typedefs can be available to
cogl-winsys-kms.c this moves them into cogl-winsys-egl-private.h

Reviewed-by: Rob Bradford <rob@linux.intel.com>
2011-11-28 17:37:31 +00:00
Rob Bradford
1b54c8023e kms: Add first version of "baremetal" backend for EGL on KMS
To start with this backend only supports creating a single CoglOnscreen
framebuffer and will automatically set is up to display fullscreen on
the first suitable crtc it can find.

To compile this backend - get some dribbly black candles, sacrifice a
goat and configure with: --enable-kms-egl-platform

Note: There is currently a problem with using GLES2 with this winsys
so you need to run with EGL_DRIVER=gl
Note: If you have problems with mesa crashing in XCB during
eglInitialize then you may need to explicitly run with EGL_PLATFORM=gbm

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-28 17:37:28 +00:00
Chun-wei Fan
80a9c3bb32 Update cogl/winsys/cogl-winsys-stub.c
Deal with c99ism... I know it's not pretty, but it is the way
to go with non-c99 compilers.  That's life...

Reviewed-by: Neil Roberts <neil@linux.intel.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-23 12:16:45 +00:00
Neil Roberts
037c0aa88c Move POPCOUNTL to cogl-util
This moves the POPCOUNTL macro from cogl-winsys-glx to cogl-util and
renames it to _cogl_util_popcountl so that it can be used in more
places. The fallback function for when the GCC builtin is not
available has been replaced with an 8-bit lookup table because the
HAKMEM implementation doesn't look like it would work when longs are
64-bit so it's not suitable for a general purpose function on 64-bit
architectures. Some of the pages regarding population counts seem to
suggest that using a lookup table is the fastest method anyway.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-16 16:32:11 +00:00
Rob Bradford
11d38e7ce8 wayland: Port to current Wayland
This change is one logical update to update the Wayland support. This
comprises of the following parts:

* Binding to both the shell and compositor global objects - necessary since
the API for setting top level status moved to the wl_shell interface
* The Wayland visual API went away and instead you setup the EGL surface
appropriately
* The message handling was refined to reflect the current behaviour - now
obsolete comments were removed and new comments updated

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 13:57:01 +00:00
Rob Bradford
00ca539845 wayland: Remove unused function
The function force_roundtrip was unused and required API that was
removed from Wayland.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-03 13:52:37 +00:00
Robert Bragg
061ef6ed06 glx: remove miss leading comment
There was a comment implying that if a rgba config has been requested
but no suitable config was found then we would automatically fall back
to an rgb config instead. Actually if no rgba visual is found we simply
fail without any automatic fall back because Cogl is not in a good
position to judge if automatic fall backs are acceptable for higher
level apis such as clutter.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-03 13:52:30 +00:00
Zan Dobersek
d8c47e25f2 Remove inclusion of Xlib headers in Cogl headers
Xlib headers define many trivially named objects which can later cause
name collision problems when only cogl.h header is included in a program
or library. Xlib headers are now only included through including the
standalone header cogl-xlib.h.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-11-01 15:55:53 +00:00
Robert Bragg
e0344468d8 docs: Adds various missing 2.0 sections and symbols
This adds a number of missing sections and symbols to the experimental
2.0 reference manual.
2011-11-01 12:03:04 +00:00
Robert Bragg
1ee861a82c framebuffer: adds cogl_framebuffer_get_samples_per_pixel
It's useful to be able to query back the number of
point_samples_per_pixel that may have previously be chosen using
cogl_framebuffer_set_samples_per_pixel().

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:03 +00:00
Robert Bragg
90f106117f texture: Make CoglTextureRectangle experimentally public
This exposes CoglTextureRectangle in the experimental cogl 2.0 api. For
now we just expose a single constructor;
cogl_texture_rectangle_new_with_size() but we can add more later.

This is part of going work to improve our texture apis with more
emphasis on providing low-level access to the varying semantics of
different texture types understood by the gpu instead of only trying to
present a lowest common denominator api.

CoglTextureRectangle is notably useful for never being restricted to
power of two sizes and for being sampled with non-normalized texture
coordinates which can be convenient for use a lookup tables in glsl due
to not needing separate uniforms for mapping normalized coordinates to
texels. Unlike CoglTexture2D though rectangle textures can't have a
mipmap and they only support the _CLAMP_TO_EDGE wrap mode.

Applications wanting to use CoglTextureRectangle should first check
cogl_has_feature (COGL_FEATURE_ID_TEXTURE_RECTANGLE).

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +00:00
Robert Bragg
b72f255c0a Start to reduce dependence on glib
Since we've had several developers from admirable projects say they
would like to use Cogl but would really prefer not to pull in
gobject,gmodule and glib as extra dependencies we are investigating if
we can get to the point where glib is only an optional dependency.
Actually we feel like we only make minimal use of glib anyway, so it may
well be quite straightforward to achieve this.

This adds a --disable-glib configure option that can be used to disable
features that depend on glib.

Actually --disable-glib doesn't strictly disable glib at this point
because it's more helpful if cogl continues to build as we make
incremental progress towards this.

The first use of glib that this patch tackles is the use of
g_return_val_if_fail and g_return_if_fail which have been replaced with
equivalent _COGL_RETURN_VAL_IF_FAIL and _COGL_RETURN_IF_FAIL macros.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +00:00
Robert Bragg
79719347c8 framebuffer: split out CoglOnscreen code
This factors out the CoglOnscreen code from cogl-framebuffer.c so we now
have cogl-onscreen.c, cogl-onscreen.h and cogl-onscreen-private.h.
Notably some of the functions pulled out are currently namespaced as
cogl_framebuffer but we know we are planning on renaming them to be in
the cogl_onscreen namespace; such as cogl_framebuffer_swap_buffers().

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:02 +00:00
Robert Bragg
1d8fd64e1c meta-texture: This publicly exposes CoglMetaTexture
CoglMetaTexture is an interface for dealing with high level textures
that may be comprised of one or more low-level textures internally. The
interface allows the development of primitive drawing APIs that can draw
with high-level textures (such as atlas textures) even though the
GPU doesn't natively understand these texture types.

There is currently just one function that's part of this interface:
cogl_meta_texture_foreach_in_region() which allows an application to
resolve the internal, low-level textures of a high-level texture.
cogl_rectangle() uses this API for example so that it can easily emulate
the _REPEAT wrap mode for textures that the hardware can't natively
handle repeating of.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:01 +00:00
Robert Bragg
426c8b8f41 features: Support more than 32 features!
Currently features are represented as bits in a 32bit mask so we
obviously can't have more than 32 features with that approach. The new
approach is to use the COGL_FLAGS_ macros which lets us handle bitmasks
without a size limit and we change the public api to accept individual
feature enums instead of a mask. This way there is no limit on the
number of features we can add to Cogl.

Instead of using cogl_features_available() there is a new
cogl_has_feature() function and for checking multiple features there is
cogl_has_features() which takes a zero terminated vararg list of
features.

In addition to being able to check for individual features this also
adds a way to query all the features currently available via
cogl_foreach_feature() which will call a callback for each feature.

Since the new functions take an explicit context pointer there is also
no longer any ambiguity over when users can first start to query
features.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-11-01 12:03:01 +00:00
Robert Bragg
a74c81ada3 onscreen: Support multisample based onscreen rendering
This adds support for multisample based rendering of onscreen windows
whereby multiple point samples per pixel can be requested and if the
hardware supports that it results in reduced aliasing (especially
considering the jagged edges of polygons)

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-10-28 19:10:16 +01:00
Robert Bragg
98e5a9c777 Rework how we search for winsys configs
When creating new onscreen framebuffers we need to take the
configuration in cogl terms and translate that into a configuration
applicable to any given winsys, e.g. an EGLConfig or a GLXFBConfig
or a PIXELFORMATDESCRIPTOR.

Also when we first create a context we typically have to do a very
similar thing because most OpenGL winsys APIs also associate a
framebuffer config with the context and all future configs need to be
compatible with that.

This patch introduces an internal CoglFramebufferConfig to wrap up some
of the configuration parameters that are common to CoglOnscreenTemplate
and to CoglFramebuffer so we aim to re-use code when dealing with the
above two problems.

This patch also aims to rework the winsys code so it can be more
naturally extended as we start adding more configureability to how
onscreen framebuffers are created.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-10-28 19:10:16 +01:00
Neil Roberts
1d67085e8a cogl-winsys-egl: Use the abstraction to update the window size
Previously the EGL backend was directly prodding the width/height
members of the framebuffer structure when a configure notify event is
received. However this doesn't set the dirty flag for the viewport so
Cogl will continue using the wrong viewport y offset. The GLX backend
is already using an abstraction for updating the size which does set
the flag. This patch just makes the EGL backend also use that
abstraction.
2011-10-17 17:33:42 +01:00
Robert Bragg
1f61868fed x11-tfp: don't call winsys x11_damage_notify without winsys
If we failed to create a native texture from pixmap via EGL or GLX then
we shouldn't call the winsys's texture_pixmap_x11_damage_notify
function. By doing the validation in cogl-texture-pixmap-x11.c the
winsys code can continue to assume that it doesn't need to verify there
is a valid tex_pixmap->winsys pointer.

Thanks to Damien Leone <dleone@nvidia.com> for catching this issue.

https://bugzilla.gnome.org/show_bug.cgi?id=660184
2011-10-12 14:24:44 +01:00
Damien Leone
895055c836 cogl-winsys-glx: fix texture format detection
The previous detection was based on color depth only to determine the
texture format to use in GLX. If that worked fine at depths 24 (RGB8)
and 32 (ARGB8), that would fail at depth 30 (BGR10) and fallback to
software instead of using the TFP extension.

This commit uses an efficient population count implementation to
compare the number of 1-bits in color masks against the color depth
requested by the X client. If they are not equal this means that an
alpha channel has been requested.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-10-01 16:44:55 +01:00
Robert Bragg
4c3dadd35e Add a strong CoglTexture type to replace CoglHandle
As part of the on going, incremental effort to purge the non type safe
CoglHandle type from the Cogl API this patch tackles most of the
CoglHandle uses relating to textures.

We'd postponed making this change for quite a while because we wanted to
have a clearer understanding of how we wanted to evolve the texture APIs
towards Cogl 2.0 before exposing type safety here which would be
difficult to change later since it would imply breaking APIs.

The basic idea that we are steering towards now is that CoglTexture
can be considered to be the most primitive interface we have for any
object representing a texture. The texture interface would provide
roughly these methods:

  cogl_texture_get_width
  cogl_texture_get_height
  cogl_texture_can_repeat
  cogl_texture_can_mipmap
  cogl_texture_generate_mipmap;
  cogl_texture_get_format
  cogl_texture_set_region
  cogl_texture_get_region

Besides the texture interface we will then start to expose types
corresponding to specific texture types: CoglTexture2D,
CoglTexture3D, CoglTexture2DSliced, CoglSubTexture, CoglAtlasTexture and
CoglTexturePixmapX11.

We will then also expose an interface for the high-level texture types
we have (such as CoglTexture2DSlice, CoglSubTexture and
CoglAtlasTexture) called CoglMetaTexture. CoglMetaTexture is an
additional interface that lets you iterate a virtual region of a meta
texture and get mappings of primitive textures to sub-regions of that
virtual region. Internally we already have this kind of abstraction for
dealing with sliced texture, sub-textures and atlas textures in a
consistent way, so this will just make that abstraction public. The aim
here is to clarify that there is a difference between primitive textures
(CoglTexture2D/3D) and some of the other high-level textures, and also
enable developers to implement primitives that can support meta textures
since they can only be used with the cogl_rectangle API currently.

The thing that's not so clean-cut with this are the texture constructors
we have currently; such as cogl_texture_new_from_file which no longer
make sense when CoglTexture is considered to be an interface.  These
will basically just become convenient factory functions and it's just a
bit unusual that they are within the cogl_texture namespace.  It's worth
noting here that all the texture type APIs will also have their own type
specific constructors so these functions will only be used for the
convenience of being able to create a texture without really wanting to
know the details of what type of texture you need.  Longer term for 2.0
we may come up with replacement names for these factory functions or the
other thing we are considering is designing some asynchronous factory
functions instead since it's so often detrimental to application
performance to be blocked waiting for a texture to be uploaded to the
GPU.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-21 15:27:03 +01:00
Adel Gadllah
671a4dfb34 winsys-glx: Fix synchronisation behaviour in _cogl_winsys_onscreen_swap_region
This patch basically restores the logic from 1.6.  There we assumed that
glXCopySubBuffer won't tear and thus only needs to be throttled to the
framerate, while glBlitFramebuffer needs to always wait to avoid
tearing.

With Nvidia drivers specifically we have seen that glBlitFramebuffer is
not synchronized. Eventually the plan is that Cogl will actually take
into consideration the underlying driver/hw vendor and driver version
and we may want to only mark glBlitFramebuffer un-synchronized on
Nvidia.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-09-19 16:40:06 +01:00
Robert Bragg
476ff37fa6 display: always ensure we have an onscreen_template
If the user doesn't explicitly pass an onscreen template then instead of
leaving display->onscreen_template as NULL we now instantiate a template
ourselves. This simplifies winsys code that might want to refer to the
template since it needn't first check for a NULL pointer.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-09-05 19:02:05 +01:00
Robert Bragg
3a2f94045e framebuffer: make _swap_region coords top-left relative
Cogl aims to consistently put the origin of 2D objects at the top-left
instead of the bottom left as OpenGL does, but there was an oversight
and the experimental cogl_framebuffer_swap_region API was accepting
coordinates relative to the bottom left. Cogl will now flip the user's
given rectangles to be relative to the bottom of the framebufffer before
sending them to APIs like glXCopySubBuffer and glBlitFramebuffer.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-12 15:28:43 +01:00
Damien Lespiau
89426a802f egl-gdl: Silence a gcc warning
gcc warns us that we should put some {} to make to which 'if's the
'else' belongs to very clear.

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

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-01 16:36:09 +01:00
Neil Roberts
38deb97478 cogl-winsys-wgl: Add a fallback for failed wglGetProcAddress
The documentation for wglGetProcAddress implies that it should only be
used for extension functions. The rest of Cogl assumes that it can
dynamically resolve all GL symbols so it would crash if this
happens. This patch makes it fallback to trying to resolve the symbol
using GModule to open the opengl32 library if wglGetProcAddress fails.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-08-01 14:08:42 +01:00
Chun-wei Fan
6256ad8a7b Update vtable.id in cogl-winsys-wgl.c
Change EGL id to WGL id.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-31 17:46:35 +01:00
Damien Lespiau
d4dc51849e egl: Make sure to free the underlying egl objects when the display is freed
If the display has been setup up, we should destroy the underlying
objects that the winsys has created. This can be done by calling the
winsys->destroy_display() function in _free.

Then, in that function, and for the NULL and GDL EGL platform we can
destroy the surface we have created in the setup_display() function
(through create_context()).

This allows to have clutter create a "dummy" display in
cogl_renderer_check_onscreen_template(), then free it, then recreate the
context and the surface that will be the final ones.

https://bugzilla.gnome.org/show_bug.cgi?id=655355
2011-07-29 11:50:15 +01:00
Damien Lespiau
2c3827aced egl-gdl: Provide defaults to be able to initialize a "dummy" context
If we are being called without any GDL specific call (either the plane
we want to render to or the swap chain length) we can provide sane
defaults to still be able to create a context and a surface.

https://bugzilla.gnome.org/show_bug.cgi?id=655355
2011-07-29 11:50:15 +01:00
Damien Lespiau
ff5a3503af egl-gdl: Make the egl winsys know about the GDL platform
The egl winsys has a few code paths depending on the platform we are
compiling for. The GDL platform needs those defined as well.

A few tweaks were needed here and there to make it compile again.

https://bugzilla.gnome.org/show_bug.cgi?id=655355
2011-07-29 11:50:15 +01:00