Commit Graph

208 Commits

Author SHA1 Message Date
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
Damien Lespiau
9ca3308892 egl: Guard the feature discovery of eglCreateImage()
EGLImageKHR might not be defined, the rest of the code seems to guard it
with #ifdef EGL_KHR_image_base.

https://bugzilla.gnome.org/show_bug.cgi?id=655216
2011-07-29 11:44:55 +01:00
Robert Bragg
912d46817e glx: Bail from _renderer_connect if not GL driver
The GLX winsys is only compatible with GL drivers so we now bail out
from cogl-winsys-glx.c:_cogl_winsys_renderer_connect if a GLES driver
has been chosen.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-28 20:44:46 +01:00
Robert Bragg
6e6620e089 egl: pass EGL_NO_CONTEXT to eglCreateImage for tfp
When passing the EGL_NATIVE_PIXMAP_KHR target to eglCreateImage the
EGL_KHR_image_pixmap extension explicitly states that EGL_NO_CONTEXT
must also be passed so we are now careful to do this.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-28 20:44:32 +01:00
Neil Roberts
d259a87602 Don't use the 'NULL' GModule to resolve GL symbols
Previously, _cogl_get_proc_address had a fallback to resolve the
symbol using g_module_open(NULL) to get the symbol from anywhere in
the address space. The EGL backend ends up using this on some drivers
because eglGetProcAddress isn't meant to return a pointer for core
functions. This causes problems if something in the process is linking
against a different GL library, for example Cairo may be linking
against libGL itself. In this case it may end up resolving symbols
from the GL library even if GLES is being used.

This patch removes the fallback. The EGL version now has its own
fallback instead which passes the existing libgl_module from the
renderer to g_module_symbol so that it should only get symbols from
that library or its dependency chain. The GLX and WGL winsys only call
glXGetProcAddress and wglGetProcAddress. The stub winsys does however
continue using the global symbol lookup.

The internal _cogl_get_proc_address function has been renamed to
_cogl_renderer_get_proc_address because it needs a connected renderer
to work so it could be considered to be a renderer method. The pointer
to the renderer is passed down to the winsys backends so that it can
use the data attached to the renderer to get the module pointers.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-07-27 16:10:02 +01:00
Neil Roberts
03c4b20931 Specify the full filename when g_module_open'ing the GL library
Instead of using g_module_build_path with the short name of the GL
library (eg, "GL") and relying on glib to add the suffix and prefix,
the configure script now directly encodes the full name including the
version number (eg, "libGL.so.1"). This is necessary because distros
don't always install the non-versioned suffix for the library.

The GLES libraries are left without the version suffix because it's
not clear what should be placed here and I can't find any
documentation from Khronos to clarify this. Mesa seems to install a
file called libGLESv2.so.2 but the IMG SDK doesn't install any
versioned library. There is an example of dynamically loading
libGLESv2 in the Chromium source code and that does not use the
version suffix even though it does use the version suffix for GL. This
implies that it's at least fairly normal to load the unversioned name
for GLES.

https://bugzilla.gnome.org/show_bug.cgi?id=654593
2011-07-19 15:12:10 +01:00
Robert Bragg
6d79657f76 egl: if texture_pixmap_x11_create fails free priv data
This makes sure the egl winsys frees the private egl_tex_pixmap state if
in _cogl_winsys_texture_pixmap_x11_create if there is a failure to
create an EGLImage.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-18 16:49:07 +01:00
Robert Bragg
02ba1a7345 texture-pixmap-x11: set ->winsys = NULL if _create fails
If _cogl_winsys_texture_pixmap_x11_create() fails then implicitly no
private state has been associated with the given tex_pixmap. Since that
winsys isn't associated with it we explicitly set tex_pixmap->winsys =
NULL.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-18 16:49:07 +01:00
Robert Bragg
c058b50ac0 texture-pixmap-x11: initialize ->use_winsys_texture
This ensures that tex_pixmap->use_winsys_texture is always initialized
during cogl_texture_pixmap_x11_new - either according to the result of
winsys->texture_pixmap_x11_create, or if the winsys doesn't support tfp
we explicitly initialize to FALSE.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-07-18 16:49:07 +01:00
Neil Roberts
231be91fb0 Combine _cogl_context_check_gl_version and update_features into one
The _cogl_context_check_gl_version function is meant to be called once
Cogl has a GL context so that it can check whether the context found
is supported by Cogl. However, only the stub winsys was calling this
and it was doing it before Cogl had a chance to retrieve the function
pointer for glString so it would just crash. This patch combines the
two functions into one so that _cogl_context_update_features returns a
gboolean and a GError. Then it can just check the context itself.

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

Reviewed-by: Robert Bragg <robert@linux.intel.com>
2011-07-18 15:41:35 +01:00
Robert Bragg
1527b017c5 build: don't referencing wayland syms if not available
cogl-winsys-egl-feature-functions.h was unconditionally depending on the
struct wl_display type being defined. This guards the check for the
"WL_bind_wayland_display" extension with
 #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-07-13 19:06:19 +01:00
Neil Roberts
b2e735ff7f Dynamically load the GL or GLES library
The GL or GLES library is now dynamically loaded by the CoglRenderer
so that it can choose between GL, GLES1 and GLES2 at runtime. The
library is loaded by the renderer because it needs to be done before
calling eglInitialize. There is a new environment variable called
COGL_DRIVER to choose between gl, gles1 or gles2.

The #ifdefs for HAVE_COGL_GL, HAVE_COGL_GLES and HAVE_COGL_GLES2 have
been changed so that they don't assume the ifdefs are mutually
exclusive. They haven't been removed entirely so that it's possible to
compile the GLES backends without the the enums from the GL headers.

When using GLX the winsys additionally dynamically loads libGL because
that also contains the GLX API. It can't be linked in directly because
that would probably conflict with the GLES API if the EGL is
selected. When compiling with EGL support the library links directly
to libEGL because it doesn't contain any GL API so it shouldn't have
any conflicts.

When building for WGL or OSX Cogl still directly links against the GL
API so there is a #define in config.h so that Cogl won't try to dlopen
the library.

Cogl-pango previously had a #ifdef to detect when the GL backend is
used so that it can sneakily pass GL_QUADS to
cogl_vertex_buffer_draw. This is now changed so that it queries the
CoglContext for the backend. However to get this to work Cogl now
needs to export the _cogl_context_get_default symbol and cogl-pango
needs some extra -I flags to so that it can include
cogl-context-private.h
2011-07-11 12:57:38 +01:00
Neil Roberts
2b119b07da Use all core GL functions through indirect pointers
cogl-ext-functions.h now contains definitions for all of the core GL
and GLES functions that we would normally link to directly. All of the
code has changed to access them through the cogl context pointer. The
GE macro now takes an extra parameter to specify the context because
the macro itself needs to make GL calls but various points in the Cogl
source use different names for the context variable.
2011-07-08 15:35:46 +01:00
Neil Roberts
dae02a99a5 Move all of the GL function pointers directly to CoglContext
Instead of storing all of the feature function pointers in the driver
specific data of the CoglContext they are now all stored directly in
CoglContext. There is a single header containing the description of
the functions which gets included by cogl-context.h. There is a single
function in cogl-feature-private.c to check for all of these
functions.

The name of the function pointer variables have been changed from
ctx->drv.pf_glWhatever to just ctx->glWhatever.

The feature flags that get set when an extension is available are now
separated from the table of extensions. This is necessary because
different extensions can mean different things on GLES and GL. For
example, having access to glMapBuffer implies read and write support
on GL but only write support on GLES. The flags are instead set in the
driver specific init function by checking whether the function
pointers were successfully resolved.

_cogl_feature_check has been changed to assume the feature is
supported if any of the listed extensions are available instead of
requiring all of them. This makes it more convenient to specify
alternate names for the extension. Nothing else had previously listed
more than one name for an extension so this shouldn't cause any
problems.
2011-07-07 02:05:42 +01:00
Robert Bragg
6940114b6e egl: look for EGL_IMAGE_FROM_X11_PIXMAP as winsys feature
instead of looking at the ctx->private_feature_flags to determine if
Cogl supports creating an EGLImage from a X Pixmap we now check the
renderer private features instead since these are what get setup in
check_egl_extensions. The conflicting flags defined in cogl-internal.h
should be removed since they are un-used.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-07-05 14:10:31 +01:00
Robert Bragg
ffe3788b85 egl: fix tracking of priv features in check_egl_extensions
check_egl_extensions was mistakenly always ORing in the priv flags of
the first feature_data entry instead of referencing the i variable to
index into the array of feature data after determining that an extension
is available.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-07-05 14:03:48 +01:00
Robert Bragg
f0366907d3 build: egl fix typo introduced by 3b64a439f0
The XEvent argument for event_filter_cb was named "event" but the rest
of the function is expecting a variable named "xevent".
2011-06-30 15:00:58 +01:00
Robert Bragg
cd6e1d183d Updates wayland symbol names to be consistent
This updates the public wayland symbols to follow the pattern
cogl_wayland_blah instead of cogl_blah_wayland.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-06-30 14:34:46 +01:00
Robert Bragg
89562dda73 work towards consistent platform file/symbol naming
we've got into a bit of a mess with how we name platform specific
symbols and files, so this is a first pass at trying to tidy that up.

All platform specific symbols should be named like
cogl_<platform>_symbol_name and similarly files should be named like
cogl-<platform>-filename.c

This patch tackles the X11 specific renderer/display APIs as a start.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-06-30 14:34:33 +01:00
Robert Bragg
3b64a439f0 replace public native_event APIs with typesafe APIs
This adds Xlib and Win32 typesafe replacements for
cogl_renderer_handle_native_event, cogl_renderer_add_native_filter,
cogl_renderer_remove_native_filter. The old functions are kept as an
implementation detail so we can share code.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-06-30 14:33:13 +01:00
Robert Bragg
b3a105c576 renderer: Expose winsys ID setter/getters
This adds API to let you override the choice of Cogl's winsys backend.
Previously it was only possible to override the winsys using the
COGL_RENDERER environment variable, but it's useful for something like
Clutter to be able to control the winsys via API without needing
environment variable tricks. This also adds API to query back the
winsys chosen by Cogl, in case you don't set an explicit override.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-06-30 14:33:11 +01:00
Robert Bragg
a1234ee8d1 Add internal _cogl_init() function
This adds a _cogl_init function for Cogl that we expect to be the first
thing called before anything else is done with Cogl. It's not a public
API so it's expected that all entry points for Cogl that might be the
first function used should call _cogl_init().

We currently call _cogl_init() in these functions:
  cogl_renderer_new
  cogl_display_new
  cogl_context_new
  cogl_android_set_native_window

_cogl_init() can be called multiple times, and only the first call has
any affect.

For example _cogl_init() gives us a place check and parse the COGL_DEBUG
environment variable.

Since we don't have any need to parse command line arguments (we can
always get user configuration options from the environment) our init
function doesn't require argc/argv pointers.

By saying up front that we aren't interested in command line arguments
that means we can avoid the mess that is GOption based library
initialization which is extremely fragile due to its lack of dependency
tracking between modules.

Signed-off-by: Neil Roberts <neil@linux.intel.com>
2011-06-30 14:33:11 +01:00
Neil Roberts
6d1371e0e9 cogl-texture-pixmap-x11: Fix the can_hardware_repeat wrapper
The wrapper for the can_hardware_repeat had a cut and paste error so
it would call the wrong function on the child texture.

Many thanks to Owen Taylor for finding this bug.
2011-06-10 18:43:56 +01:00
Robert Bragg
5022ec54d2 replace _xlib_add_filter use with _cogl_renderer API
Instead of using _cogl_xlib_add/remove_filter we now use
_cogl_renderer_add/remove_native_filter. The _cogl_xlib_add_filter API
was only required as a stop gap while EGL support was still in Clutter
because in that case we were using the stub winsys and didn't have a
CoglRenderer.
2011-06-01 20:44:42 +01:00
Robert Bragg
8c35a6bb7c remove _cogl_xlib_trap/untrap_errors wrappers
This removes the redundant _cogl_xlib_trap/untrap_errors functions that
simply wrap equivalent functions in the _cogl_renderer_xlib namespace.
These were originally only required while the EGL winsys was being
handled in clutter and so there wasn't a CoglRenderer in all cases.
2011-06-01 20:44:42 +01:00
Robert Bragg
4a97fc0a1e egl: fix some #ifdef guards
In the winsys vtable .xlib_get_visual_info and
.onscreen_x11_get_window_xid should be guarded by the
COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT because they need to be there
if cogl is configured with --enable-xlib-egl-platform but not if just
configured with --enable-xlib.
2011-06-01 20:44:42 +01:00
Robert Bragg
656f28de2f glx: make sure _cogl_winsys_get_proc_address is static
Make sure not to export _cogl_winsys_get_proc_address outside of
cogl-winsys-glx.c
2011-06-01 20:44:42 +01:00
Robert Bragg
a29a76dbab Adds _cogl_wayland_texture_2d_new_from_buffer API
This adds internal API to be able to wrap a wayland buffer as a
CoglTexture2D. There is a --enable-wayland-egl-server option to decide
if Cogl should support this feature and potentially any EGL based winsys
could support this through the EGL_KHR_image_base and
EGL_WL_bind_display extensions.
2011-06-01 20:44:42 +01:00
Robert Bragg
8714d99300 egl: Add x11 texture-from-pixmap support
By using the EGL_KHR_image_base/pixmap extensions this adds support for
wrapping X11 pixmaps as CoglTexture2D textures. Clutter will
automatically take advantage of this if using the
ClutterX11TexturePixmap actor.
2011-06-01 20:44:42 +01:00
Robert Bragg
60b25615fd Add _cogl_egl_texture_2d_new_from_image API
This adds an internal texture_2d constructor that can wrap an EGLImage
as a CoglTexture2D. The plan is to utilize this for texture-from-pixmap
support with EGL as well as creating textures from wayland buffers.
2011-06-01 20:44:42 +01:00
Robert Bragg
52aada8442 egl: Check EGL extension as early as possible
Instead of waiting until initializing a CoglContext we now check EGL
extensions after calling eglInitialize.
2011-06-01 20:44:41 +01:00
Robert Bragg
be15bf75e4 Add internal _cogl_get_proc_address
This adds an internal _cogl_get_proc_address that doesn't need a
CoglContext. This will enable us to check driver features earlier.
2011-06-01 20:44:41 +01:00
Robert Bragg
b380fed23d Make stub winsys into a proper winsys backend
Instead of the stub winsys being a special case set of #ifdef'd code
used when COGL_HAS_FULL_WINSYS wasn't defined, the stub winsys now
implements a CoglWinsysVtable like all other winsys backends (it's just
that everything is a NOP). This way we can get rid of the
COGL_HAS_FULL_WINSYS define and also the stub winsys can be runtime
selected whereas before it was incompatible with all other winsys
backends.
2011-06-01 20:44:41 +01:00
Robert Bragg
ee7cc9e788 Make CoglTexture2D public as experimental API
This exposes a CoglTexture2D typedef and adds the following experimental
API:
    cogl_is_texture_2d
    cogl_texture_2d_new_with_size
    cogl_texture_2d_new_from_data
    cogl_texture_2d_new_from_foreign

Since this is experimental API you need to define
COGL_ENABLE_EXPERIMENTAL_API before including cogl.h.

Note: With these new entrypoints we now expect a CoglContext pointer to
be passed in, instead of assuming there is a default context. The aim is
that for Cogl 2.0 we won't have a default context so this is a step in
that direction.
2011-06-01 20:44:41 +01:00
Robert Bragg
5a9b92a4a5 Revert "Initial build of a Quartz winsys stub"
This reverts commit b2e41f1bfa.

We are backing out the quartz specific stub winsys since we can simply
use the generic stub winsys on quartz until we develop a standalone
winsys. Since we plan on removing all special cases for the stub winsys
by handling with a winsys vtable like all the others it's better if we
don't introduce a quartz specific stub.
2011-06-01 20:21:59 +01:00
Robert Bragg
891a9c33c5 Revert "quartz: Remove X11 ifdefs"
This reverts commit eb81ec945c.

We are backing out the quartz specific stub winsys since we can simply
use the generic stub winsys on quartz until we develop a standalone
winsys. Since we plan on removing all special cases for the stub winsys
by handling with a winsys vtable like all the others it's better if we
don't introduce a quartz specific stub.
2011-06-01 20:21:59 +01:00
Emmanuele Bassi
eb81ec945c quartz: Remove X11 ifdefs 2011-05-25 16:47:38 +01:00
Emmanuele Bassi
b2e41f1bfa Initial build of a Quartz winsys stub 2011-05-24 23:08:59 +01:00
Damien Lespiau
f436582114 android: Add support for an EGL/Android winsys
The native window type of the EGL/Android winsys is ANativeWinow*. The
Android NDK gives you a pointer to this ANativeWindow and you just need
to configure that window using the EGLConfig you are choosing when
creating the context.

This means you have to know the ANativeWindow* window before creating
the context. This is solved here by just having a global variable you
can set with cogl_android_set_native_window() before creating the
context. This is a bit ugly though, and it conceptually belongs to the
OnScreen creation to know which ANativeWindow* to use. This would need a
"lazy context creation" mechanism, waiting for the user to create the
OnScreen to initialize the GL context.
2011-05-17 15:24:54 +01:00
Damien Lespiau
d384466a58 winsys-egl: Use g_clear_error() between two context creation tries
When try_create_context() returns saying that it has to be run again to
try to create a context with an alternate configuration, it might not
have a GError set (and in fact it does not right now).
g_clear_error() handles that case where error is still NULL;
2011-05-17 15:24:54 +01:00
Damien Lespiau
dd5a1c888b gles1: Include GLES/egl.h or EGL/egl.h depending on the implementation
Early implementations provided only a GLES/egl.h while Khronos's
implementer guide now states EGL/egl.h is the One. Some implementations
keep a GLES/egl.h wrapper around EGL/egl.h for backward compatibility
while others provide EGL/egl.h only.

Also took the opportunity to factorize a bit this inclusion in
cogl-defines.h.
2011-05-17 15:24:54 +01:00
Robert Bragg
2282455f27 wayland: Allow setting foreign display/compositor
To support toolkits targeting wayland and using Cogl we allow toolkits
to be responsible for connecting to a wayland display and asking Cogl to
use the toolkit owned display and compositor object. Note: eventually
the plan is that wayland will allow retrospective querying of objects so
we won't need the foreign compositor API when Cogl can simply query it
from the foreign display.
2011-05-11 16:46:52 +01:00
Robert Bragg
653d59af04 Explicitly set EGL_PLATFORM=wayland for wayland winsys
The EGL API doesn't provide for a way to explicitly select a platform
when the driver can support multiple. Mesa allows selection using an
EGL_PLATFORM environment variable though so we set that to "wayland"
when we know that's what we want.
2011-05-11 16:44:08 +01:00
Neil Roberts
463603f1a0 cogl-winsys: Fix freeing a CoglOnscreen
All of the winsys backends didn't handle cleaning up the CoglOnscreen
properly so that they would assert in cogl_onscreen_free because the
winsys pointer is never freed. They also didn't cope if deinit is
called before init (which will be the case if an onscreen is created
and freed without being allocated).
2011-05-10 20:23:39 +01:00
Neil Roberts
6654533e40 cogl-winsys-wgl: Plug leak on error from SetPixelFormat
When SetPixelFormat fails, the DC would get released but none of the
other resources would be freed. This patch makes it call
_cogl_winsys_onscreen_deinit on failure to clean up all of the
resources. The patch looks big because it moves the onscreen_deinit
and onscreen_bind functions.
2011-05-10 19:53:00 +01:00