Since 5967dad2400d32c we have stopped using glib types such as guint16
and guint32 in favour of the equivalent c99 types such as uint16_t and
uint32_t. When that patch was tested we must have used a configuration
that just happened to include <stdint.h> because we have since seen that
builds can fail due to missing c99 typedefs. This patch explicitly
includes stdint.h in cogl-types.h.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit c1e2220a4314071482d2d5638688b6bcf83882a2)
The check for whether the compiler supports _Static_assert didn't work
properly because the AC_TRY_COMPILE function puts the source
definition in its own main function. The test therefore ends up
declaring a nested main function which GCC allows. If _Static_assert
isn't available then it just looks like an implicit declaration of a
function which only causes a warning in GCC so it would still compile.
This patch changes it to use AC_COMPILE_IFELSE instead. This macro
makes it possible to specify the complete source code so
_Static_assert can be called from the global scope. AC_LANG_PROGRAM is
used to generate the program. For extra aesthetics it now also
generates a 'checking for...' message while the script is running.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 9657938c3083a782234e1e9f05ab5ae88a6bc5ab)
The existing functions for stroking and filling a path depend on the
global framebuffer and source stacks. These are now replaced with
cogl_framebuffer_{stroke,fill}_path which get explicitly passed the
framebuffer and pipeline.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 713a8f8160bc5884b091c69eb7a84b069e0950e6)
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)
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.
This adds a _COGL_STATIC_ASSERT macro that can be used for compile time
assertions in C code. If supported by the compiler this macro uses
_Static_assert so that a message can be printed out if the assertion
fails.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 465b39a764f2720e77678cafa56acb0e69007ffd)
The code for loading a CoglBitmap from a file was missed when
upgrading to the new cogl_bitmap_new_for_data function in commit
d18b59d9e6 so it wouldn't compile. This changes it to use
_cogl_bitmap_new_with_malloc_buffer to allocate the buffer.
https://bugzilla.gnome.org/show_bug.cgi?id=672533
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 5b785dd441a83024333e0a2f2b83d067f891194f)
cogl_path_new now takes a CoglContext pointer which it keeps a pointer
to instead of relying on the global context.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit afc63f8211c230f8fd1f7801f9085627c46a8661)
Since we can't change the api on this branch this just applies
the internal cleanups so we depend less on _COGL_GET_CONTEXT
This splits the GL header inclusion from cogl-defines.h into a
separate headear called cogl-gl-header.h which we will only include
internally. That way we don't leak GL declarations out of our public
headers. The texture functions that were using GLenum and GLuint in
the public header have now changed to just use unsigned int. Note
however that if an EGL winsys is enabled then it will still publicly
include an EGL header. This is a bit more awkward to fix because we
have public API which returns an EGLDisplay and we can't determine
what type that is.
There is also a conformance test which just verifies that no GL header
has been included while compiling. The test isn't added to
test-conform-main because it doesn't actually test anything at
runtime.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit ef5680d3fda5df929dbd0b420c8f598ded58dfee)
cogl_framebuffer_draw_multitextured_rectangles is not in the public
API list, it is instead _cogl_framebuffer_draw_multitextured_rectangles,
which is private.
(Sorry, I forgot to add the reviewed by line for the same patch in the
cogl-1.10 branch :P)
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 4fc6cf5e3c1478bc0a29dfaf2f6d9e84b9d29ccd)
We need to filter out all the *-egl-* sources as well, as the original
filter did not filter out the Wayland EGL sources
(Sorry, I forgot to add the reviewed by line for the same patch in the
cogl-1.10 branch :P)
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 3d4cb887a28d3bc2cde9e4e7cdd20a71c34a2eaa)
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>
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>
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>
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>
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>
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>
If a NULL display is passed to cogl_context_new() then it has to
implicitly create a CoglRenderer and CoglDisplay and propagate any
resulting errors back to the user. Previously the implementation relied
on passing a NULL renderer to cogl_display_new() as the means for
implicitly connecting to a renderer. The problem with this though is
that cogl_display_new() isn't designed to ever return NULL but if it
failed to connect to a renderer automatically it would do and then
cogl_context_new would pass NULL to cogl_display_setup() leading to a
crash.
This patch changes the implementation of cogl_context_new() to now
explicitly create a CoglRenderer and connect to it if a NULL display is
given. This way we can easily propagate any errors. In addition
cogl_display_new has been changed to abort if it fails to implicitly
connect to a renderer due to a NULL renderer argument.
An application needing to gracefully handle problems connecting to a
renderer at runtime should manually instantiate and connect a renderer
passing a GError argument to cogl_renderer_connect.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
If we fail to allocate the onscreen framebuffer when first requesting 4x
msaa then we now print the GError message.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Instead of using cogl_rectangle() this example now uses
cogl_framebuffer_draw_rectangle(). This fixes a crash due to the example
not pushing a current framebuffer before calling cogl_rectangle().
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Cogl internally will call g_type_init if necessary so the cogl-crate
example doesn't need to do this explicitly.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
If we fail to load the crate texture then we now print error->message to
hopefully give more insight into the failure to the user.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
cogl-sampler-cache-private.h was including a header which doesn't
exist so the build was broken. The header comes from a patch which
hasn't been pushed to master yet which splits including GL/gl.h out of
cogl-defines.h into a separate header. I added the inclusion to make
it pick up the GL defines but it doesn't need to do this yet because
cogl-context.h is still including the GL header. I didn't notice the
failure because I still had a cogl-gl-header.h lying around from a
previous build with the patch.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Mesa before version 8.0.2 has a slow read pixels path that gets used
with the Intel driver where it converts all of the pixels into a
floating point representation and back even if the data is being read
into exactly the same format. There is however a faster path using the
blitter when reading into a PBO with BGRA format. It works out faster
to read into a PBO and then memcpy back out into the application's
buffer even though it adds an extra memcpy. This patch adds a
workaround in cogl_framebuffer_read_pixels_into_bitmap when it detects
this situation. In that case it will create a temporary CoglBitmap
using cogl_bitmap_new_with_size, read into it and then memcpy the data
back out.
The main impetus for this patch is that Gnome Shell has implemented
this workaround directly using GL calls but it seems like the kind of
thing that would sit better at the Cogl layer.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
This adds a CoglGpuInfo struct to the CoglContext which contains some
enums describing the GL driver in use. This currently includes the
driver package (ie, is it Mesa) the version number of the package and
the vendor of the GPU (ie, is it by Intel). There is also a bitmask
which will contain the workarounds that we should do for that
particular driver configuration. The struct is initialised on context
creation by using a series of string comparisons on the strings
returned from glGetString.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
The Intel driver currently has an optimisation when calling
glReadPixels into a PBO so that it will use a blit instead of the Mesa
fallback path. However this only works if the GL_PACK_ALIGNMENT is
exactly 1, even if this would be equivalent to a higher alignment
value because the bpp*width is already aligned. To make it more likely
to hit this fast path, we now detect this situation and explicitly use
an alignment of 1. To make this work the texture driver needs to be
passed down the bpp*width as well as the rowstride when configuring
the alignment.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Instead of having a series of if-statements this adds an inline
function to calculate the alignment directly using ffs which is
probably slightly faster. Admittedly this is a pointless
micro-optimisation but I think it makes the code looks a bit neater
anyway.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
GL_ARB_sampler_objects provides a GL object which overrides the
sampler state part of a texture object with different values. The
sampler state that Cogl currently exposes is the wrap modes and
filters. Cogl exposes the state as part of the pipeline layer state
but without this extension GL only exposes it as part of the texture
object state. This means that it won't work to use a single texture
multiple times in one primitive with different sampler states. It also
makes switching between different sampler states with a single texture
not terribly efficient because it has to change the texture object
state every time.
This patch adds a cache for sampler states in a shared hash table
attached to the CoglContext. The entire set of parameters for the
sampler state is used as the key for the hash table. When a unique
state is encountered the sampler cache will create a new entry,
otherwise it will return a const pointer to an existing entry. That
means we can have a single pointer to represent any combination of
sampler state.
Pipeline layers now just store this single pointer rather than storing
all of the sampler state. The two separate state flags for wrap modes
and filters have now been combined into one. It should be faster to
compare the sampler state now because instead of comparing each value
it can just compare the pointers to the cached sampler entries. The
hash table of cached sampler states should only need to perform its
more expensive hash on the state when a property is changed on a
pipeline, not every time it is flushed.
When the sampler objects extension is available each cached sampler
state will also get a sampler object to represent it. The common code
to flush the GL state will now simply bind this object to a unit
instead of flushing the state though the CoglTexture when possible.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Two of the meta texture constructors which take a flags parameter were
ignoring the COGL_TEXTURE_NO_AUTO_MIPMAP flag when creating an
underlying CoglTexture2D. These have now been fixed to call
cogl_primitive_texture_set_auto_mipmap after constructing the texture.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
This adds public constructors which take a CoglBitmap to all primitive
texture types. This constructor should be considered the canonical
constructor for initializing the texture with data because it should
be possible to wrap any type of data in a CoglBitmap. Having at least
this single constructor avoids the need to have an explosion of
constructors such as new_from_data, new_from_pixel_buffer and
new_from_file etc.
The already available internal bitmap constructor for CoglTexture2D
has had its flags parameter removed under the assumption that flags do
not make sense for primitive textures. The meta constructor
cogl_texture_new_from_bitmap now just explicitly calls set_auto_mipmap
after constructing the texture depending on the value of the
COGL_TEXTURE_NO_AUTO_MIPMAP flag.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
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>
This adds a context member to CoglBitmap which stores the context it
was created with. That way it can be used in texture constructors
which use a bitmap. There is also an internal private function to get
the context out of the bitmap which all of the texture constructors
now use. _cogl_texture_3d_new_from_bitmap has had its context
parameter removed so that it more closely matches the other bitmap
constructors.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
The previous code to initialise the depth state on the default
pipeline wasn't initialising the magic number. If you later tried to
retrieve the depth state using cogl_pipeline_get_depth_state you would
end up with an invalid depth state struct and you would just get
warnings if you tried to use it for anything. This patch just replaces
the initialisation with a call to cogl_depth_state_init because it
uses the same values anyway.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
get_texture_bits_via_offscreen does not check the return value of
cogl_framebuffer_read_pixels_into_bitmap which results into never
using the fallback path texture_get_cb.
cogl_framebuffer_read_pixels_into_bitmap does not check whether the framebuffer
is properly allocated though; so fix that as well.
https://bugzilla.gnome.org/show_bug.cgi?id=673137
Reviewed-by: Neil Roberts <neil@linux.intel.com>