Since _cogl_pipeline_update_blend_enable() can sometimes show up quite
high in profiles; instead of calling
_cogl_pipeline_update_blend_enable() whenever we change pipeline state
that may affect blending we now just set a dirty flag and when we flush
a pipeline we check this dirty flag and lazily calculate whether blender
really needs to be enabled if it's set.
Since it turns out we were too optimistic in assuming most GL drivers
would recognize blending with ADD(src,0) is equivalent to disabling
GL_BLEND we now check this case ourselves so we can always explicitly
disable GL_BLEND if we know we don't need blending.
This introduces the idea of an 'unknown_color_alpha' boolean to the
pipeline flush code which is set whenever we can't guarantee that the
color attribute is opaque. For example this is set whenever a user
specifies a color attribute with 4 components when drawing a primitive.
This boolean needs to be cached along with every pipeline because
pipeline::real_blend_enabled depends on this and so we need to also call
_cogl_pipeline_update_blend_enable() if the status of this changes.
Incidentally with this patch we now no longer ever use
_cogl_pipeline_set_blend_enable() internally. For now the internal api
hasn't been removed though since we might want to consider re-purposing
it as a public api since it will now not conflict with our own internal
state tracking and could provide a more convenient way to disable
blending than setting a blend string.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit ab2ae18f3207514c91fa6fd9f2d3f2ed93a86497)
_cogl_egl_query_wayland_buffer was using _COGL_RETURN_IF_FAIL but the
function needs to return a CoglBool so it was giving a warning.
(cherry picked from commit d0290eb19fc9bf56fb24f8eab573e19966ea7e1a)
This updates Cogland and the three hello examples to use the dirty
callback. For Cogland, this removes the manual handling of X events
and for the other examples it removes the need to redraw continously.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 108e3c548b7866190845f163c84a05212718bd70)
This adds a callback that can be registered with
cogl_onscreen_add_dirty_callback which will get called whenever the
window system determines that the contents of the window is dirty and
needs to be redrawn. Under the two X-based winsys's, this is reported
off the back of the Expose events, under SDL it is reported from
SDL_VIDEOEXPOSE or SDL_WINDOWEVENT_EXPOSED and under Windows from the
WM_PAINT messages. The Wayland winsys doesn't really have the concept
of dirtying the buffer but in order to allow applications to work the
same way on all platforms it will emit the event when the surface is
first shown and whenever it is resized.
There is a private feature flag to specify whether dirty events are
supported. If the winsys does not set this then Cogl will simulate
dirty events by emitting one when the window is first allocated and
when it is resized. The only winsys's that don't set this flag are
things like KMS or the EGL null winsys where there is no windowing
system and showing and hiding the onscreen doesn't really make any
sense. In that case Cogl can assume the buffer will only become dirty
once when it is first allocated.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 85c5a9ba419b2247bd768284c79ee69164a0c098)
Conflicts:
cogl/cogl-private.h
After discussing with Kristian Høgsberg it seems that the semantics of
wl_egl_window_resize is meant to be that if nothing has been drawn to
the framebuffer since the last swap then the resize will take effect
immediately. Cogl was previously always delaying the call to
wl_egl_window_resize until the next swap. That meant that if you
wanted to resize the surface you would have to call
cogl_wayland_onscreen_resize and then redundantly draw a frame at the
old size so that you can swap to get the resize to occur before
drawing again at the right size. Typically an application would decide
to resize at the start of its paint sequence so it should be able to
just resize immediately.
In current Mesa master it seems that there is a bug which means that
it won't actually delay a resize that is done mid-scene and instead it
will just discard what came before. To get consistent behaviour in
Cogl, the code to delay the call to wl_egl_window_resize is still used
if it determines that the buffer is dirty. There is an existing
_cogl_framebuffer_mark_mid_scene call which was being used to track
when the framebuffer becomes dirty since the last clear. This function
is now also used to track a new flag to track whether something has
been drawn since the last swap. It is called ‘mid_scene’ under the
assumption that this may also be useful for other things later.
cogl_framebuffer_clear has been slightly altered to always call
_cogl_framebuffer_mark_mid_scene even if it determines that it doesn't
need to clear because the framebuffer should still be considered to be
in the middle of a scene. Adding a quad to the journal now also begins
the scene.
This also fixes a potential bug where it looks like pending_dx/dy were
never cleared so they would always be accumulated even after the
resize is flushed.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 945689a62903990a20abb87a85d2c96eb3985fe7)
In some later patches we want to be able to use the term ‘dirty’ as a
public facing concept which represents expose events from the window
system. In that case the internal concept of dirtying the framebuffer
is confusing, so this patch changes the name to instead mean that
we've doing something which causes the framebuffer to be in the middle
of a frame.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 88eed85b52c29f66659ea112038f3522c9bd864e)
If we delay setting the surface to toplevel until it is shown then
that gives the application an opportunity to avoid calling show so
that it can set its own surface type.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit ab59c3a421968d7f159d89ca2f0ba8a9f098cbf6)
Previously the WGL winsys was expecting the application to send all
windows messages to Cogl via the cogl_win32_renderer_handle_event
function. When using a GLib main loop we can make this work
transparently to the application with a GSource for the magic
G_WIN32_MSG_HANDLE file descriptor. That causes the GMainLoop to wake
up whenever a message is available.
This patch makes the WGL winsys add that magic value as a source fd.
This will only have any meaning if the application is using glib, but
it shouldn't matter because the cogl_poll_renderer_get_info function
is documented to only work on Unix-based winsys's anyway.
This patch is an API break because by default Cogl will now start
stealing all of the Windows messages. Something like Clutter that wants to handle
its own event retrieval would now need to call
cogl_win32_renderer_set_event_retrieval_enabled to stop Cogl from
stealing the events.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 99a7f84d7149f24f3e86c5d3562f9f2632ff6df8)
The implementation of cogl_wayland_texture_2d_new_from_buffer now uses
eglQueryWaylandBuffer to query the format of the buffer before trying to
create a texture from the buffer. This makes sure we don't try and
create a texture from YUV buffers for instance that may actually require
multiple textures. We now also report an error when we don't understand
the buffer type or format.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 79252d4e419e2462c5bc89ea4614b40bddc932c5)
This removes the various checks for != COGL_DRIVER_GLES1 when tracking
blend state that was trying to avoid checking the equation or alpha
component factors when they are known to be fixed on gles1. Now we just
rely on the opengl driver to do the right thing for the different
drivers and ignore the differences in the general pipeline state
tracking.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit f67c7eaf23e1e2088e9956cb2b66dfdc9abc8b3b)
Instead of simply relying on the emscripten mainloop api to wake us up
periodically so that we can poll for SDL events we now pause the
emscripten mainloop whenever no redraw is queued and instead hook an
input event listener into the real browser mainloop to resume the
emscripten mainloop whenever input is received. This way the example
can go to sleep while there's no input to handle.
This provides a simple example of binding custom javascript into native
code.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit a8b1e2eda491dc7c44c84cd47e160c7b8ba0f792)
This enables basic Emscripten support in Cogl via the SDL winsys.
Assuming you have setup an emscripten toolchain you can configure Cogl
like this:
emconfigure ./configure --enable-debug --enable-emscripten
Building the examples will build .html files that can be loaded directly
by a WebGL enabled browser.
Note: at this point the emscripten support has just barely been smoke
tested so it's expected that as we continue to build on this we will
learn about more things we need to change in Cogl to full support this
environment.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit a3bc2e7539391b074e697839dfae60b69c37cf10)
The ARB_sync api depends on a GLsync type which may not be available if
GL_ARB_sync isn't defined, such as when building for gles2 only. This
guards the prototypes with #ifdef GL_ARB_sync to fix compilation when a
GLsync type isn't defined.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit ba79020e0f5b102e8b25cd831c408dd68d241297)
Fixes 'undefined reference to cogl_error_free' when using g++.
Signed-off-by: Andreas Oberritter <obi@saftware.de>
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 41c54fcaba5b4bf76a0e943bac6bca777f3dae2f)
cogl_framebuffer_add_fence creates a synchronisation fence, which will
invoke a user-specified callback when the GPU has finished executing all
commands provided to it up to that point in time.
Support is currently provided for GL 3.x's GL_ARB_sync extension, and
EGL's EGL_KHR_fence_sync (when used with OpenGL ES).
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>
https://bugzilla.gnome.org/show_bug.cgi?id=691752
(cherry picked from commit e6d37470da9294adc1554c0a8c91aa2af560ed9f)
This adds a _cogl_poll_renderer_add_source() function that we can use
within cogl to hook into the mainloop without necessarily having a file
descriptor to poll. Since the intention is to use this to support
polling for fence completions this also updates the
CoglPollCheckCallback type to take a timeout pointer so sources can
optionally update the timeout that will be passed to poll.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 81c1ce0ffce4e75e08622e20848405987e00b3cc)
If this happens, XRRGetScreenResources will return NULL, so just treat
that like nothing happened.
https://bugzilla.gnome.org/show_bug.cgi?id=699431
Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 57a79912ac70080a2f9cbe65181a25b00bf1192a)
This makes sure we include cogl-defines.h in cogl-matrix.h before
checking if COGL_HAS_GYPE_SUPPORT is defined
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit aa5ba324bb3b2ce77be29942f8716d61919cefeb)
Since 906e1b5eb535a86 Cogland no longer redraws constantly but instead
only draws once at startup and then again whenever a client attaches a
new buffer. Sometimes however it seems that the first paint will get
lost perhaps because it is sent before the window is fully mapped. As
it was previously not handling expose events it would not paint again
until the first client is connected so there would be a blank window
which looks broken.
This patch makes it handle Expose events when it detects that Cogl is
using an X backend. On other backends it will resort to queuing a
redraw every 16ms as it did before.
Although this is probably a bit overkill for such a small example, it
seems like a good idea to only redraw when we think it's necessary so
that we can be sure that the mechanism works. Handling the expose
events means we can have at least one platform where we can test this.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 99cf15b285302243395873d78f05a5895c173eef)
Previously if a client sent a commit message without attaching a new
buffer then it would end up detaching the existing buffer because
surface->pending.buffer would be NULL. This patch makes it explicitly
track when an attach is sent for a commit and so that it can avoid
making any changes otherwise. This fixes cases where GTK apps would
send a damage event without a new buffer.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit aa412b9c709120bd8d88a014010c448f3b9fcfb7)
This adds api to be able requests a swap_buffers and also pass a list of
damage rectangles that can be passed on to a compositor to enable it to
minimize how much of the screen it needs to recompose.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 0d9684c7b7c2018bb42715c369555330d38514a2)
Instead of driving event dispatching through a per winsys poll_dispatch
vfunc its now possible to associate a check and dispatch function with
each file descriptor that is registered for polling. This means we can
remove the winsys get_dispatch_timeout and poll_dispatch vfuncs and it
also makes it easier for more orthogonal internal components to add file
descriptors for polling to the mainloop.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 627947622df36dd529b9dc60a3ae9e6083532b19)
This adds a _cogl_poll_renderer_add_idle api that can be used internally
for queuing an idle callback without needing to make any assumption
about the system mainloop that is being used. This is now used to avoid
having the _cogl_poll_renderer_dispatch() directly check for all kinds of
events to dispatch, and to avoid having the winsys dispatch vfuncs need
to directly know about CoglContext. This means we can now avoid having a
back reference from CoglRenderer to the CoglContext.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit a1e169f18f4257caec58760adccfe4ec09b9805d)
This adds some utility code to help us manage lists of closures
consistently within Cogl. The utilities are from Rig and were originally
written by Neil Roberts.
This adapts the way we track CoglOnscreen resize and frame closures to
use the new utilities.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 2e15fc76eb29bf5932418f7ee80f1fcb2f6a816c)
This updates the cogl_poll_ apis to allow dispatching events before we
have a CoglContext and to also enables pollfd state to be changed in a
more add-hoc way by different Cogl components by replacing the
winsys->get_poll_info with _cogl_poll_renderer_add/remove_fd functions
and a winsys->get_dispatch_timeout vfunc.
One of the intentions here is that applications should be able to run
their mainloop before creating a CoglContext to potentially get events
relating to CoglOutputs.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 667e58c9cb2662aef5f44e580a9eda42dc8d0176)
When adding the frame callback API in 70040166 we decided on a common
idiom for adding callbacks which would return an opaque pointer
representing the closure for the callback. This pointer can then be
used to later remove the callback. The closure can also contain an
optional callback to invoke when the user data parameter is destroyed.
The resize callback didn't work this way and instead had an integer
handle to identify the closure. This patch changes it to work the same
way as the frame callback.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 33164c4b04d253ebe0ff41b12c1e90232c519274)
This adds support for optionally providing a foreign Wayland surface to
a CoglOnscreen before allocation. Setting a foreign surface prevents
Cogl from creating a toplevel Wayland shell surface for the OnScreen.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit e447d9878f3bcfe5fe336d367238383b02879223)
This prevents leaking the Wayland shell surface associated with a Cogl
OnScreen when it is finalised.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 760fc9f3af5475530262b82a55df311fceca358a)
This adds compiler symbol deprecation declarations for old Cogl APIs so
that users can easily see via compiler warning when they are using these
symbols, and also see a hint for what the apis should be replaced with.
So that users of Cogl can manage when to show these warnings this
introduces a scheme borrowed from glib whereby you can declare what
version of the Cogl api you are using:
COGL_VERSION_MIN_REQUIRED can be defined to indicate the oldest Cogl api
that the application wants to use. Cogl will only warn about
deprecations for symbols that were deprecated earlier than this required
version. If this is left undefined then by default Cogl will warn about
all deprecations.
COGL_VERSION_MAX_ALLOWED can be defined to indicate the newest api
that the application uses. If the application uses symbols newer than
this then Cogl will give a warning about that.
This patch removes the need to maintain the COGL_DISABLE_DEPRECATED
guards around deprecated symbols.
This patch fixes a few uses of deprecated symbols in the examples/
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Call wl_display_dispatch on POLLIN. This follows the implementation
in weston/clients/window.c and improves integration of input events,
at least.
Signed-off-by: Andreas Oberritter <obi@saftware.de>
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 323fe1887487f19c3e26aa6b7644de31d8d0a532)
Some of the examples and tests are using functions from -lm. With some
linkers, if we don't expicitly link against it an error will be
reported. This patch adds the library to all of the examples even
though not all of them use math functions because I don't think it
will do any harm and it will save us having to remember to add it if
an example later starts using some math functions.
https://bugzilla.gnome.org/show_bug.cgi?id=697330
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 66a1aeaee1f7cdcdd505f5745277723a43d714b6)
Conflicts:
examples/Makefile.am
tests/conform/Makefile.am
tests/micro-perf/Makefile.am
‘sincos’ is a GNU extension. cogl-gles2-gears was using it without
defining _GNU_SOURCE so it was generating some annoying warnings. This
patch fixes it by making the example include config.h which will end
up defining _GNU_SOURCE.
In addition this patch adds a configure check for the function and
provides a fallback if it's not available.
https://bugzilla.gnome.org/show_bug.cgi?id=697330
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit eb5c92952e1882c95cfd6debc69a2c9efff096b9)
https://bugzilla.gnome.org/show_bug.cgi?id=697330
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit e3cc008e7a26af462871448561e4cde0f95bfdf9)
https://bugzilla.gnome.org/show_bug.cgi?id=697330
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit a7b4930e14add7d955c22f396178b71083dfb52f)
Conflicts:
cogl/Makefile.am
The first vertex in the triangle vertices used in the cogl-hello
example (which were copied into a few other examples) for some reason
has a semi-transparent alpha component. However the colour needs to be
pre-multiplied and the red component was still 0xff so the colour is
effectively invalid and the transparency isn't shown. This patch just
sets the alpha component to 0xff to make it less confusing.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 461879986ec012556b4e680b73e36d440927faaa)
Cogland works a lot better with an EGL context because then Mesa will
automatically set up the wl_drm object and it can accept DRM buffers.
However Cogland is still useful with GLX because it can gracefully
fallback to accepting only SHM buffers. This patch therefore makes it
first try creating and connecting a renderer with the EGL constraint,
but if that doesn't work it will try again without it.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 05ddc7d75e77538b5de22d4336d4a444d122063b)
When a Wayland compositor gets a commit it only needs to redraw the
region specified by the pending damage event. Previously Cogland was
ignoring damage events for non-shm buffers and just always queuing a
redraw after a commit event. This patch changes it to queue a redraw
only in response to a damage event. In practice this doesn't really
make much difference because Cogland doesn't do anything clever to
handle updating a sub-region of the screen, but it more costly matches
the model a compositor should use.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 15f00609e41f689234ee8d5b2f9e95fb74612d12)
If the shell surface is requested twice then Cogland will hit an error
path but it would end up leaking the CoglandShellSurface struct it
allocated.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 622d41b04c2689a8e4fb6e1769aaf887a04242e8)
The handler for the destroy signal on the pending buffer was not
correctly being removed if the same buffer is committed twice to the
surface. It was also not being cleared if the surface is destroyed
before the pending buffer is committed.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 11683476a7a62cd14a10d84fd52f2cb4b47e33a0)
Fixes compilation with C++ compiler.
Signed-off-by: Andreas Oberritter <obi@saftware.de>
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 7b3c6dd7f6810f3c8dec62904daa887c917ab7e2)
When a pipeline is added to the cache, a normal copy would previously be
made to use as the key in the hash table. This copy keeps a reference
to the real pipeline which means all of the resources it contains are
retained forever, even if they aren't necessary to generate the hash.
This patch changes it to create a trimmed down copy that only has the
state necessary to generate the hash. A new function called
_cogl_pipeline_deep_copy is added which makes a new pipeline that is
directly a child of the root pipeline. It then copies over the
pertinent state from the original pipeline. The pipeline state is
copied using the existing _cogl_pipeline_copy_differences function.
There was no equivalent function for the layer state so I have added
one.
That way the pipeline key doesn't have the texture data state and it
doesn't hold a reference to the original pipeline so it should be much
cheaper to keep around.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit e27e01c1215e7e7c7c0183ded11dd769bb112c5c)
Calculating the hash value for a pipeline can be a bit expensive.
Previously when adding a new pipeline to the hash table we would end
up calculating the hash value once when checking whether the pipeline
is already in the hash table and then again when adding the pipeline
to the hash table. Ideally GHashTable would provide some API to add an
entry with a precalculated hash value to avoid the recalculation, but
seeing as it doesn't do that we can force it to avoid recalculating by
storing the hash value as part of the struct we are using for the key.
That way the hash func passed to GHashTable can simply return the
precalculated value and we can calculate the hash outside of the
GHashTable calls.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 4a0460a452fd1be382fd5a92d8cfd5e0cdfd4403)
The pipeline cache contains three separate hash tables, one for the
state affecting the vertex shaders, one for the fragment shaders and
one for the resulting combined program. Previously these hash tables
had a fair bit of duplicated code to calculate the hashes, check for
equality and copy the pipeline when it is added. This patch moves the
common bits of code to a new type called CoglPipelineHashTable which
just wraps a GHashTable with a given set of state flags to use for
hashing and checking for equality.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 402796430c839038339e531363b8c2463f9b2a9e)
Conflicts:
cogl/Makefile.am
Currently when a unique pipeline is created and added to the pipeline
cache that pipeline will live forever which includes keeping a
reference to any large resources that the pipeline has such as
textures. These textures don't actually need to be kept for the
pipeline to be used as a key in the hash table so ideally we wouldn't
do this. This test case tries rendering with a pipeline that has
textures and then checks whether the textures are successfully
destroyed after the pipeline is unreffed. The test is currently marked
as a known failure because the pipeline cache will prevent them from
being destroyed.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 0056f805dadd46b966d57f66b02890b8c29971ac)
The quartz image backend is using functions from the
ApplicationServices framework and I was getting linker errors if I
didn't use this option. I'm not sure how anyone managed to build it
before without this.
https://bugzilla.gnome.org/show_bug.cgi?id=696730
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 54d9139a929560d6703428371b38b83e7d965f45)
Since 67cad9c0 and f7735e141a the bitmap allocation and mapping
functions now take an extra error argument. The quartz image backend
was missed in this update so Cogl would fail to compile if
--enable-quartz-image is used.
https://bugzilla.gnome.org/show_bug.cgi?id=696730
Reviewed-by: Robert Bragg <robert@linux.intel.com>
(cherry picked from commit 1827965befccf331b0787f71cb191d370640a9de)