mutter/cogl/cogl-onscreen.c

712 lines
21 KiB
C
Raw Normal View History

/*
* Cogl
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2011, 2013 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl-util.h"
#include "cogl-onscreen-private.h"
#include "cogl-frame-info-private.h"
#include "cogl-framebuffer-private.h"
#include "cogl-onscreen-template-private.h"
#include "cogl-context-private.h"
#include "cogl-object-private.h"
#include "cogl1-context.h"
#include "cogl-closure-list-private.h"
#include "cogl-poll-private.h"
static void _cogl_onscreen_free (CoglOnscreen *onscreen);
Add -Wmissing-declarations to maintainer flags and fix problems This option to GCC makes it give a warning whenever a global function is defined without a declaration. This should catch cases were we've defined a function but forgot to put it in a header. In that case it is either only used within one file so we should make it static or we should declare it in a header. The following changes where made to fix problems: • Some functions were made static • cogl-path.h (the one containing the 1.0 API) was split into two files, one defining the functions and one defining the enums so that cogl-path.c can include the enum and function declarations from the 2.0 API as well as the function declarations from the 1.0 API. • cogl2-clip-state has been removed. This only had one experimental function called cogl_clip_push_from_path but as this is unstable we might as well remove it favour of the equivalent cogl_framebuffer_* API. • The GLX, SDL and WGL winsys's now have a private header to define their get_vtable function instead of directly declaring in the C file where it is called. • All places that were calling COGL_OBJECT_DEFINE need to have the cogl_is_whatever function declared so these have been added either as a public function or in a private header. • Some files that were not including the header containing their function declarations have been fixed to do so. • Any unused error quark functions have been removed. If we later want them we should add them back one by one and add a declaration for them in a header. • _cogl_is_framebuffer has been renamed to cogl_is_framebuffer and made a public function with a declaration in cogl-framebuffer.h • Similarly for CoglOnscreen. • cogl_vdraw_indexed_attributes is called cogl_framebuffer_vdraw_indexed_attributes in the header. The definition has been changed to match the header. • cogl_index_buffer_allocate has been removed. This had no declaration and I'm not sure what it's supposed to do. • CoglJournal has been changed to use the internal CoglObject macro so that it won't define an exported cogl_is_journal symbol. • The _cogl_blah_pointer_from_handle functions have been removed. CoglHandle isn't used much anymore anyway and in the few places where it is used I think it's safe to just use the implicit cast from void* to the right type. • The test-utils.h header for the conformance tests explicitly disables the -Wmissing-declaration option using a pragma because all of the tests declare their main function without a header. Any mistakes relating to missing declarations aren't really important for the tests. • cogl_quaternion_init_from_quaternion and init_from_matrix have been given declarations in cogl-quaternion.h Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-03-06 13:21:28 -05:00
COGL_OBJECT_DEFINE_WITH_CODE (Onscreen, onscreen,
_cogl_onscreen_class.virt_unref =
_cogl_framebuffer_unref);
static void
_cogl_onscreen_init_from_template (CoglOnscreen *onscreen,
CoglOnscreenTemplate *onscreen_template)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
_cogl_list_init (&onscreen->frame_closures);
_cogl_list_init (&onscreen->resize_closures);
_cogl_list_init (&onscreen->dirty_closures);
framebuffer->config = onscreen_template->config;
cogl_object_ref (framebuffer->config.swap_chain);
}
/* XXX: While we still have backend in Clutter we need a dummy object
* to represent the CoglOnscreen framebuffer that the backend
* creates... */
CoglOnscreen *
_cogl_onscreen_new (void)
{
CoglOnscreen *onscreen = g_new0 (CoglOnscreen, 1);
_COGL_GET_CONTEXT (ctx, NULL);
_cogl_framebuffer_init (COGL_FRAMEBUFFER (onscreen),
ctx,
COGL_FRAMEBUFFER_TYPE_ONSCREEN,
0x1eadbeef, /* width */
0x1eadbeef); /* height */
/* NB: make sure to pass positive width/height numbers here
* because otherwise we'll hit input validation assertions!*/
_cogl_onscreen_init_from_template (onscreen, ctx->display->onscreen_template);
COGL_FRAMEBUFFER (onscreen)->allocated = TRUE;
/* XXX: Note we don't initialize onscreen->winsys in this case. */
return _cogl_onscreen_object_new (onscreen);
}
CoglOnscreen *
cogl_onscreen_new (CoglContext *ctx, int width, int height)
{
CoglOnscreen *onscreen;
/* FIXME: We are assuming onscreen buffers will always be
premultiplied so we'll set the premult flag on the bitmap
format. This will usually be correct because the result of the
default blending operations for Cogl ends up with premultiplied
data in the framebuffer. However it is possible for the
framebuffer to be in whatever format depending on what
CoglPipeline is used to render to it. Eventually we may want to
add a way for an application to inform Cogl that the framebuffer
is not premultiplied in case it is being used for some special
purpose. */
onscreen = g_new0 (CoglOnscreen, 1);
_cogl_framebuffer_init (COGL_FRAMEBUFFER (onscreen),
ctx,
COGL_FRAMEBUFFER_TYPE_ONSCREEN,
width, /* width */
height); /* height */
_cogl_onscreen_init_from_template (onscreen, ctx->display->onscreen_template);
return _cogl_onscreen_object_new (onscreen);
}
static void
_cogl_onscreen_free (CoglOnscreen *onscreen)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys = _cogl_framebuffer_get_winsys (framebuffer);
CoglFrameInfo *frame_info;
_cogl_closure_list_disconnect_all (&onscreen->resize_closures);
_cogl_closure_list_disconnect_all (&onscreen->frame_closures);
_cogl_closure_list_disconnect_all (&onscreen->dirty_closures);
while ((frame_info = g_queue_pop_tail (&onscreen->pending_frame_infos)))
cogl_object_unref (frame_info);
g_queue_clear (&onscreen->pending_frame_infos);
if (framebuffer->context->window_buffer == COGL_FRAMEBUFFER (onscreen))
framebuffer->context->window_buffer = NULL;
winsys->onscreen_deinit (onscreen);
_COGL_RETURN_IF_FAIL (onscreen->winsys == NULL);
/* Chain up to parent */
_cogl_framebuffer_free (framebuffer);
g_free (onscreen);
}
static void
notify_event (CoglOnscreen *onscreen,
CoglFrameEvent event,
CoglFrameInfo *info)
{
_cogl_closure_list_invoke (&onscreen->frame_closures,
CoglFrameCallback,
onscreen, event, info);
}
static void
_cogl_dispatch_onscreen_cb (CoglContext *context)
{
CoglOnscreenEvent *event, *tmp;
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
CoglList queue;
/* Dispatching the event callback may cause another frame to be
* drawn which in may cause another event to be queued immediately.
* To make sure this loop will only dispatch one set of events we'll
* steal the queue and iterate that separately */
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
_cogl_list_init (&queue);
_cogl_list_insert_list (&queue, &context->onscreen_events_queue);
_cogl_list_init (&context->onscreen_events_queue);
_cogl_closure_disconnect (context->onscreen_dispatch_idle);
context->onscreen_dispatch_idle = NULL;
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
_cogl_list_for_each_safe (event, tmp, &queue, link)
{
CoglOnscreen *onscreen = event->onscreen;
CoglFrameInfo *info = event->info;
notify_event (onscreen, event->type, info);
cogl_object_unref (onscreen);
cogl_object_unref (info);
g_slice_free (CoglOnscreenEvent, event);
}
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
while (!_cogl_list_empty (&context->onscreen_dirty_queue))
{
CoglOnscreenQueuedDirty *qe =
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
_cogl_container_of (context->onscreen_dirty_queue.next, qe, link);
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
_cogl_list_remove (&qe->link);
_cogl_closure_list_invoke (&qe->onscreen->dirty_closures,
CoglOnscreenDirtyCallback,
qe->onscreen,
&qe->info);
cogl_object_unref (qe->onscreen);
g_slice_free (CoglOnscreenQueuedDirty, qe);
}
}
static void
_cogl_onscreen_queue_dispatch_idle (CoglOnscreen *onscreen)
{
CoglContext *ctx = COGL_FRAMEBUFFER (onscreen)->context;
if (!ctx->onscreen_dispatch_idle)
{
ctx->onscreen_dispatch_idle =
_cogl_poll_renderer_add_idle (ctx->display->renderer,
(CoglIdleCallback)
_cogl_dispatch_onscreen_cb,
ctx,
NULL);
}
}
void
_cogl_onscreen_queue_dirty (CoglOnscreen *onscreen,
const CoglOnscreenDirtyInfo *info)
{
CoglContext *ctx = COGL_FRAMEBUFFER (onscreen)->context;
CoglOnscreenQueuedDirty *qe = g_slice_new (CoglOnscreenQueuedDirty);
qe->onscreen = cogl_object_ref (onscreen);
qe->info = *info;
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
_cogl_list_insert (ctx->onscreen_dirty_queue.prev, &qe->link);
_cogl_onscreen_queue_dispatch_idle (onscreen);
}
void
_cogl_onscreen_queue_full_dirty (CoglOnscreen *onscreen)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglOnscreenDirtyInfo info;
info.x = 0;
info.y = 0;
info.width = framebuffer->width;
info.height = framebuffer->height;
_cogl_onscreen_queue_dirty (onscreen, &info);
}
void
_cogl_onscreen_queue_event (CoglOnscreen *onscreen,
CoglFrameEvent type,
CoglFrameInfo *info)
{
CoglContext *ctx = COGL_FRAMEBUFFER (onscreen)->context;
CoglOnscreenEvent *event = g_slice_new (CoglOnscreenEvent);
event->onscreen = cogl_object_ref (onscreen);
event->info = cogl_object_ref (info);
event->type = type;
Use the Wayland embedded linked list implementation instead of BSD's This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
2013-06-08 18:03:25 -04:00
_cogl_list_insert (ctx->onscreen_events_queue.prev, &event->link);
_cogl_onscreen_queue_dispatch_idle (onscreen);
}
void
cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles,
int n_rectangles)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys;
CoglFrameInfo *info;
_COGL_RETURN_IF_FAIL (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN);
info = _cogl_frame_info_new ();
info->frame_counter = onscreen->frame_counter;
g_queue_push_tail (&onscreen->pending_frame_infos, info);
/* FIXME: we shouldn't need to flush *all* journals here! */
cogl_flush ();
winsys = _cogl_framebuffer_get_winsys (framebuffer);
winsys->onscreen_swap_buffers_with_damage (onscreen,
rectangles, n_rectangles);
cogl_framebuffer_discard_buffers (framebuffer,
COGL_BUFFER_BIT_COLOR |
COGL_BUFFER_BIT_DEPTH |
COGL_BUFFER_BIT_STENCIL);
if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT))
{
CoglFrameInfo *info;
g_warn_if_fail (onscreen->pending_frame_infos.length == 1);
info = g_queue_pop_tail (&onscreen->pending_frame_infos);
_cogl_onscreen_queue_event (onscreen, COGL_FRAME_EVENT_SYNC, info);
_cogl_onscreen_queue_event (onscreen, COGL_FRAME_EVENT_COMPLETE, info);
cogl_object_unref (info);
}
onscreen->frame_counter++;
wayland: Don't delay resize if nothing is drawn since last swap 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)
2013-05-17 10:13:41 -04:00
framebuffer->mid_scene = FALSE;
}
void
cogl_onscreen_swap_buffers (CoglOnscreen *onscreen)
{
cogl_onscreen_swap_buffers_with_damage (onscreen, NULL, 0);
}
void
cogl_onscreen_swap_region (CoglOnscreen *onscreen,
const int *rectangles,
int n_rectangles)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys;
CoglFrameInfo *info;
_COGL_RETURN_IF_FAIL (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN);
info = _cogl_frame_info_new ();
info->frame_counter = onscreen->frame_counter;
g_queue_push_tail (&onscreen->pending_frame_infos, info);
/* FIXME: we shouldn't need to flush *all* journals here! */
cogl_flush ();
winsys = _cogl_framebuffer_get_winsys (framebuffer);
/* This should only be called if the winsys advertises
COGL_WINSYS_FEATURE_SWAP_REGION */
_COGL_RETURN_IF_FAIL (winsys->onscreen_swap_region != NULL);
winsys->onscreen_swap_region (COGL_ONSCREEN (framebuffer),
rectangles,
n_rectangles);
cogl_framebuffer_discard_buffers (framebuffer,
COGL_BUFFER_BIT_COLOR |
COGL_BUFFER_BIT_DEPTH |
COGL_BUFFER_BIT_STENCIL);
if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT))
{
CoglFrameInfo *info;
g_warn_if_fail (onscreen->pending_frame_infos.length == 1);
info = g_queue_pop_tail (&onscreen->pending_frame_infos);
_cogl_onscreen_queue_event (onscreen, COGL_FRAME_EVENT_SYNC, info);
_cogl_onscreen_queue_event (onscreen, COGL_FRAME_EVENT_COMPLETE, info);
cogl_object_unref (info);
}
onscreen->frame_counter++;
wayland: Don't delay resize if nothing is drawn since last swap 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)
2013-05-17 10:13:41 -04:00
framebuffer->mid_scene = FALSE;
}
int
cogl_onscreen_get_buffer_age (CoglOnscreen *onscreen)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys;
_COGL_RETURN_VAL_IF_FAIL (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN, 0);
winsys = _cogl_framebuffer_get_winsys (framebuffer);
if (!winsys->onscreen_get_buffer_age)
return 0;
return winsys->onscreen_get_buffer_age (onscreen);
}
#ifdef COGL_HAS_X11_SUPPORT
void
cogl_x11_onscreen_set_foreign_window_xid (CoglOnscreen *onscreen,
uint32_t xid,
CoglOnscreenX11MaskCallback update,
void *user_data)
{
/* We don't wan't applications to get away with being lazy here and not
* passing an update callback... */
_COGL_RETURN_IF_FAIL (update);
onscreen->foreign_xid = xid;
onscreen->foreign_update_mask_callback = update;
onscreen->foreign_update_mask_data = user_data;
}
uint32_t
cogl_x11_onscreen_get_window_xid (CoglOnscreen *onscreen)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
if (onscreen->foreign_xid)
return onscreen->foreign_xid;
else
{
const CoglWinsysVtable *winsys = _cogl_framebuffer_get_winsys (framebuffer);
/* This should only be called for x11 onscreens */
_COGL_RETURN_VAL_IF_FAIL (winsys->onscreen_x11_get_window_xid != NULL, 0);
return winsys->onscreen_x11_get_window_xid (onscreen);
}
}
uint32_t
cogl_x11_onscreen_get_visual_xid (CoglOnscreen *onscreen)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys = _cogl_framebuffer_get_winsys (framebuffer);
XVisualInfo *visinfo;
uint32_t id;
/* This should only be called for xlib based onscreens */
_COGL_RETURN_VAL_IF_FAIL (winsys->xlib_get_visual_info != NULL, 0);
visinfo = winsys->xlib_get_visual_info ();
id = (uint32_t)visinfo->visualid;
XFree (visinfo);
return id;
}
#endif /* COGL_HAS_X11_SUPPORT */
#ifdef COGL_HAS_WIN32_SUPPORT
void
cogl_win32_onscreen_set_foreign_window (CoglOnscreen *onscreen,
HWND hwnd)
{
onscreen->foreign_hwnd = hwnd;
}
HWND
cogl_win32_onscreen_get_window (CoglOnscreen *onscreen)
{
if (onscreen->foreign_hwnd)
return onscreen->foreign_hwnd;
else
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys =
_cogl_framebuffer_get_winsys (framebuffer);
/* This should only be called for win32 onscreens */
_COGL_RETURN_VAL_IF_FAIL (winsys->onscreen_win32_get_window != NULL, 0);
return winsys->onscreen_win32_get_window (onscreen);
}
}
#endif /* COGL_HAS_WIN32_SUPPORT */
CoglFrameClosure *
cogl_onscreen_add_frame_callback (CoglOnscreen *onscreen,
CoglFrameCallback callback,
void *user_data,
CoglUserDataDestroyCallback destroy)
{
return _cogl_closure_list_add (&onscreen->frame_closures,
callback,
user_data,
destroy);
}
void
cogl_onscreen_remove_frame_callback (CoglOnscreen *onscreen,
CoglFrameClosure *closure)
{
_COGL_RETURN_IF_FAIL (closure);
_cogl_closure_disconnect (closure);
}
typedef struct _SwapBufferCallbackState
{
CoglSwapBuffersNotify callback;
void *user_data;
} SwapBufferCallbackState;
static void
destroy_swap_buffers_callback_state (void *user_data)
{
g_slice_free (SwapBufferCallbackState, user_data);
}
static void
shim_swap_buffers_callback (CoglOnscreen *onscreen,
CoglFrameEvent event,
CoglFrameInfo *info,
void *user_data)
{
SwapBufferCallbackState *state = user_data;
/* XXX: Note that technically it is a change in semantics for this
* interface to forward _SYNC events here and also makes the api
* name somewhat missleading.
*
* In practice though this interface is currently used by
* applications for throttling, not because they are strictly
* interested in knowing when a frame has been presented and so
* forwarding _SYNC events should serve them better.
*/
if (event == COGL_FRAME_EVENT_SYNC)
state->callback (COGL_FRAMEBUFFER (onscreen), state->user_data);
}
unsigned int
cogl_onscreen_add_swap_buffers_callback (CoglOnscreen *onscreen,
CoglSwapBuffersNotify callback,
void *user_data)
{
CoglContext *ctx = COGL_FRAMEBUFFER (onscreen)->context;
SwapBufferCallbackState *state = g_slice_new (SwapBufferCallbackState);
CoglFrameClosure *closure;
unsigned int id = ctx->next_swap_callback_id++;
state->callback = callback;
state->user_data = user_data;
closure =
cogl_onscreen_add_frame_callback (onscreen,
shim_swap_buffers_callback,
state,
destroy_swap_buffers_callback_state);
g_hash_table_insert (ctx->swap_callback_closures,
GINT_TO_POINTER (id),
closure);
return id;
}
void
cogl_onscreen_remove_swap_buffers_callback (CoglOnscreen *onscreen,
unsigned int id)
{
CoglContext *ctx = COGL_FRAMEBUFFER (onscreen)->context;
CoglFrameClosure *closure = g_hash_table_lookup (ctx->swap_callback_closures,
GINT_TO_POINTER (id));
_COGL_RETURN_IF_FAIL (closure);
cogl_onscreen_remove_frame_callback (onscreen, closure);
}
void
cogl_onscreen_set_swap_throttled (CoglOnscreen *onscreen,
CoglBool throttled)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
framebuffer->config.swap_throttled = throttled;
if (framebuffer->allocated)
{
const CoglWinsysVtable *winsys =
_cogl_framebuffer_get_winsys (framebuffer);
winsys->onscreen_update_swap_throttled (onscreen);
}
}
void
cogl_onscreen_show (CoglOnscreen *onscreen)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys;
if (!framebuffer->allocated)
{
if (!cogl_framebuffer_allocate (framebuffer, NULL))
return;
}
winsys = _cogl_framebuffer_get_winsys (framebuffer);
if (winsys->onscreen_set_visibility)
winsys->onscreen_set_visibility (onscreen, TRUE);
}
void
cogl_onscreen_hide (CoglOnscreen *onscreen)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
if (framebuffer->allocated)
{
const CoglWinsysVtable *winsys =
_cogl_framebuffer_get_winsys (framebuffer);
if (winsys->onscreen_set_visibility)
winsys->onscreen_set_visibility (onscreen, FALSE);
}
}
void
_cogl_onscreen_notify_frame_sync (CoglOnscreen *onscreen, CoglFrameInfo *info)
{
notify_event (onscreen, COGL_FRAME_EVENT_SYNC, info);
}
void
_cogl_onscreen_notify_complete (CoglOnscreen *onscreen, CoglFrameInfo *info)
{
notify_event (onscreen, COGL_FRAME_EVENT_COMPLETE, info);
}
void
_cogl_onscreen_notify_resize (CoglOnscreen *onscreen)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
_cogl_closure_list_invoke (&onscreen->resize_closures,
CoglOnscreenResizeCallback,
onscreen,
framebuffer->width,
framebuffer->height);
}
void
_cogl_framebuffer_winsys_update_size (CoglFramebuffer *framebuffer,
int width, int height)
{
if (framebuffer->width == width && framebuffer->height == height)
return;
framebuffer->width = width;
framebuffer->height = height;
cogl_framebuffer_set_viewport (framebuffer, 0, 0, width, height);
if (!_cogl_has_private_feature (framebuffer->context,
COGL_PRIVATE_FEATURE_DIRTY_EVENTS))
_cogl_onscreen_queue_full_dirty (COGL_ONSCREEN (framebuffer));
}
void
cogl_onscreen_set_resizable (CoglOnscreen *onscreen,
CoglBool resizable)
{
CoglFramebuffer *framebuffer;
const CoglWinsysVtable *winsys;
if (onscreen->resizable == resizable)
return;
onscreen->resizable = resizable;
framebuffer = COGL_FRAMEBUFFER (onscreen);
if (framebuffer->allocated)
{
winsys = _cogl_framebuffer_get_winsys (COGL_FRAMEBUFFER (onscreen));
if (winsys->onscreen_set_resizable)
winsys->onscreen_set_resizable (onscreen, resizable);
}
}
CoglBool
cogl_onscreen_get_resizable (CoglOnscreen *onscreen)
{
return onscreen->resizable;
}
CoglOnscreenResizeClosure *
cogl_onscreen_add_resize_callback (CoglOnscreen *onscreen,
CoglOnscreenResizeCallback callback,
void *user_data,
CoglUserDataDestroyCallback destroy)
{
return _cogl_closure_list_add (&onscreen->resize_closures,
callback,
user_data,
destroy);
}
void
cogl_onscreen_remove_resize_callback (CoglOnscreen *onscreen,
CoglOnscreenResizeClosure *closure)
{
_cogl_closure_disconnect (closure);
}
CoglOnscreenDirtyClosure *
cogl_onscreen_add_dirty_callback (CoglOnscreen *onscreen,
CoglOnscreenDirtyCallback callback,
void *user_data,
CoglUserDataDestroyCallback destroy)
{
return _cogl_closure_list_add (&onscreen->dirty_closures,
callback,
user_data,
destroy);
}
void
cogl_onscreen_remove_dirty_callback (CoglOnscreen *onscreen,
CoglOnscreenDirtyClosure *closure)
{
_COGL_RETURN_IF_FAIL (closure);
_cogl_closure_disconnect (closure);
}
int64_t
cogl_onscreen_get_frame_counter (CoglOnscreen *onscreen)
{
return onscreen->frame_counter;
}