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>
This extension lets you upload texture data from a subregion of a
buffer by passing GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_PIXELS and
GL_UNPACK_SKIP_ROWS to glPixelStore. When this extension is available
the GLES texture driver will now avoid making a copy of the bitmap
when a subregion is used.
Note that Mesa doesn't currently advertise this extension but I've
made a patch to propose it:
http://lists.freedesktop.org/archives/mesa-dev/2012-March/020191.html
This extension allows an application to upload data in BGRA format. We
can use this to avoid a conversion in Cogl whenever it is given BGRA
data. This is quite useful when uploading data generated by Cairo
because at least on little-endian architectures that ends up as BGRA.
The patch just makes the pixel_format_to_gl implementation return
GL_BGRA_EXT for the data format and internal format whenever
COGL_PIXEL_FORMAT_BGRA_8888{,_PRE} is used.
A small caveat with this patch is that once a texture is created as
GL_BGRA, when later using glTexSubImage2D to update the texture it
must always be given data as GL_BGRA. Currently this just works out
because we store the internal format of a texture as a CoglPixelFormat
and we already swizzle the data if it does not match exactly on GLES.
However if we later switch to using a different enum for internal
formats then we might lose the ability to store the component ordering
so we'll have to think of another way to do this.
Cogl already had a vtable for the texture driver. This ended up being
used for some things that are not strictly related to texturing such
as converting between pixel formats and GL enums. Some other functions
that are driver dependent such as updating the features were not
indirected through a vtable but instead switched directly by looking
at the ctx->driver enum value. This patch normalises to the two uses
by adding a separate vtable for driver functions not related to
texturing and moves the pixel format conversion functions to it from
the texture driver vtable. It also adds a context parameter to all of
the functions in the new driver vtable so that they won't have to rely
on the global context.
It looks like the then-clause of the AS_IF macro needs to be in square
brackets otherwise the configure script gets generated wrong and you
get this output when you run it:
configure: line 17339: COGL_PANGO_DEP_CFLAGS: command not found
configure: line 17340: C: command not found
configure: line 17341: COGL_PANGO_DEP_LIBS: command not found
configure: line 17342: linker: command not found
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Because the wayland-client-protocol.h header defines symbols that
collide with the wayland-server-protocol.h header we allow applications
to explicitly ensure that they are only including one at a time by
exposing corresponding <cogl/cogl-wayland-client.h> and
<cogl/cogl-wayland-server.h> headers. This also adds a missing guard to
cogl-texture-2d.h that it isn't included directly.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
The fallback code using stb-image.c was missed out in the upgrade to
cogl_bitmap_new_for_data from commit d18b59d9e6 so it wouldn't
compile.
Reviewed-by: Robert Bragg <robert@linux.intel.com>