2007-03-22 18:21:59 +00:00
|
|
|
/* Clutter.
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Copyright (C) 2006-2007 OpenedHand
|
|
|
|
*
|
|
|
|
* 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
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2007-03-22 18:21:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "clutter-backend-glx.h"
|
|
|
|
#include "clutter-stage-glx.h"
|
|
|
|
#include "clutter-glx.h"
|
2009-11-30 17:47:55 +00:00
|
|
|
#include "clutter-profile.h"
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2010-10-21 11:16:05 +00:00
|
|
|
#include "clutter-actor-private.h"
|
2010-10-21 10:29:09 +00:00
|
|
|
#include "clutter-debug.h"
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 12:32:04 +00:00
|
|
|
#include "clutter-device-manager.h"
|
2010-10-21 10:29:09 +00:00
|
|
|
#include "clutter-event.h"
|
|
|
|
#include "clutter-enum-types.h"
|
|
|
|
#include "clutter-feature.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-stage-private.h"
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
#include "cogl/cogl.h"
|
2007-04-27 21:13:06 +00:00
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
#include <GL/glx.h>
|
|
|
|
#include <GL/gl.h>
|
|
|
|
|
2009-11-30 17:47:55 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-08-09 10:29:03 +00:00
|
|
|
#ifdef HAVE_DRM
|
|
|
|
#include <drm.h>
|
|
|
|
#endif
|
2009-11-30 17:47:55 +00:00
|
|
|
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 12:32:04 +00:00
|
|
|
static void clutter_stage_window_iface_init (ClutterStageWindowIface *iface);
|
|
|
|
static void clutter_event_translator_iface_init (ClutterEventTranslatorIface *iface);
|
2008-04-04 15:02:11 +00:00
|
|
|
|
2011-01-21 10:49:12 +00:00
|
|
|
static ClutterStageWindowIface *clutter_stage_window_parent_iface = NULL;
|
|
|
|
static ClutterEventTranslatorIface *clutter_event_translator_parent_iface = NULL;
|
|
|
|
|
|
|
|
#define clutter_stage_glx_get_type _clutter_stage_glx_get_type
|
2009-08-13 11:34:07 +00:00
|
|
|
|
2008-04-04 15:02:11 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (ClutterStageGLX,
|
2011-01-21 10:49:12 +00:00
|
|
|
clutter_stage_glx,
|
2008-04-04 15:02:11 +00:00
|
|
|
CLUTTER_TYPE_STAGE_X11,
|
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 12:32:04 +00:00
|
|
|
clutter_stage_window_iface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_EVENT_TRANSLATOR,
|
|
|
|
clutter_event_translator_iface_init));
|
2007-03-22 18:21:59 +00:00
|
|
|
|
|
|
|
static void
|
2009-08-13 11:34:07 +00:00
|
|
|
clutter_stage_glx_unrealize (ClutterStageWindow *stage_window)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2009-08-13 11:34:07 +00:00
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
|
2010-01-14 14:03:23 +00:00
|
|
|
ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (stage_window);
|
2011-02-14 12:00:31 +00:00
|
|
|
ClutterBackendX11 *backend_x11 = stage_x11->backend;
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2008-04-04 15:02:11 +00:00
|
|
|
/* Note unrealize should free up any backend stage related resources */
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 12:32:04 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "Unrealizing GLX stage [%p]", stage_glx);
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
clutter_x11_trap_x_errors ();
|
2007-07-06 09:22:43 +00:00
|
|
|
|
2010-01-14 14:03:23 +00:00
|
|
|
if (stage_glx->glxwin != None)
|
|
|
|
{
|
|
|
|
glXDestroyWindow (backend_x11->xdpy, stage_glx->glxwin);
|
|
|
|
stage_glx->glxwin = None;
|
|
|
|
}
|
|
|
|
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 12:32:04 +00:00
|
|
|
_clutter_stage_x11_destroy_window_untrapped (stage_x11);
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2009-08-03 13:50:10 +00:00
|
|
|
XSync (backend_x11->xdpy, False);
|
2007-07-22 22:40:18 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
clutter_x11_untrap_x_errors ();
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
2009-08-13 11:34:07 +00:00
|
|
|
static gboolean
|
|
|
|
clutter_stage_glx_realize (ClutterStageWindow *stage_window)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2010-03-17 17:41:52 +00:00
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
|
|
|
|
ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (stage_window);
|
2008-06-23 09:55:42 +00:00
|
|
|
ClutterBackendX11 *backend_x11;
|
2010-03-17 17:41:52 +00:00
|
|
|
ClutterBackendGLX *backend_glx;
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2009-05-11 11:36:14 +00:00
|
|
|
CLUTTER_NOTE (ACTOR, "Realizing stage '%s' [%p]",
|
2009-08-13 11:34:07 +00:00
|
|
|
G_OBJECT_TYPE_NAME (stage_window),
|
|
|
|
stage_window);
|
2007-03-22 18:21:59 +00:00
|
|
|
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 12:32:04 +00:00
|
|
|
if (!_clutter_stage_x11_create_window (stage_x11))
|
|
|
|
return FALSE;
|
2008-01-31 23:10:30 +00:00
|
|
|
|
2011-02-14 12:00:31 +00:00
|
|
|
backend_x11 = stage_x11->backend;
|
|
|
|
backend_glx = CLUTTER_BACKEND_GLX (backend_x11);
|
|
|
|
|
2010-01-14 14:03:23 +00:00
|
|
|
if (stage_glx->glxwin == None)
|
|
|
|
{
|
|
|
|
int major;
|
|
|
|
int minor;
|
|
|
|
GLXFBConfig config;
|
|
|
|
|
|
|
|
/* Try and create a GLXWindow to use with extensions dependent on
|
|
|
|
* GLX versions >= 1.3 that don't accept regular X Windows as GLX
|
2011-01-18 12:59:49 +00:00
|
|
|
* drawables.
|
|
|
|
*/
|
2010-01-14 14:03:23 +00:00
|
|
|
if (glXQueryVersion (backend_x11->xdpy, &major, &minor) &&
|
|
|
|
major == 1 && minor >= 3 &&
|
|
|
|
_clutter_backend_glx_get_fbconfig (backend_glx, &config))
|
|
|
|
{
|
|
|
|
stage_glx->glxwin = glXCreateWindow (backend_x11->xdpy,
|
|
|
|
config,
|
|
|
|
stage_x11->xwin,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 20:37:01 +00:00
|
|
|
#ifdef GLX_INTEL_swap_event
|
glx: Unconditionally select X11/GLX events
Currently, we select input events and GLX events conditionally,
depending on whether the user has disabled event retrieval.
We should, instead, unconditionally select input events even with event
retrieval disabled because we need to guarantee that the Clutter
internal state is maintained when calling clutter_x11_handle_event()
without requiring applications or embedding toolkits to select events
themselves. If we did that, we'd have to document the events to be
selected, and also update applications and embedding toolkits each time
we added a new mask, or a new class of events - something that's clearly
not possible.
See:
http://bugzilla.clutter-project.org/show_bug.cgi?id=998
for the rationale of why we did conditional selection. It is now clear
that a compositor should clear out the input region, since it cannot
assume a perfectly clean slate coming from us.
See:
http://bugzilla.clutter-project.org/show_bug.cgi?id=2228
for an example of things that break if we do conditional event
selection on GLX events. In that specific case, the X11 server ≤ 1.8
always pushed GLX events on the queue, even without selecting them; this
has been fixed in the X11 server ≥ 1.9, which means that applications
like Mutter or toolkit integration libraries like Clutter-GTK would stop
working on recent Intel drivers providing the GLX_INTEL_swap_event
extension.
This change has been tested with Mutter and Clutter-GTK.
2010-08-03 15:11:52 +00:00
|
|
|
if (clutter_feature_available (CLUTTER_FEATURE_SWAP_EVENTS))
|
|
|
|
{
|
event/x11: Rework the way we translate X11 events
This is a lump commit that is fairly difficult to break down without
either breaking bisecting or breaking the test cases.
The new design for handling X11 event translation works this way:
- ClutterBackend::translate_event() has been added as the central
point used by a ClutterBackend implementation to translate a
native event into a ClutterEvent;
- ClutterEventTranslator is a private interface that should be
implemented by backend-specific objects, like stage
implementations and ClutterDeviceManager sub-classes, and
allows dealing with class-specific event translation;
- ClutterStageX11 implements EventTranslator, and deals with the
stage-relative X11 events coming from the X11 event source;
- ClutterStageGLX overrides EventTranslator, in order to
deal with the INTEL_GLX_swap_event extension, and it chains up
to the X11 default implementation;
- ClutterDeviceManagerX11 has been split into two separate classes,
one that deals with core and (optionally) XI1 events, and the
other that deals with XI2 events; the selection is done at run-time,
since the core+XI1 and XI2 mechanisms are mutually exclusive.
All the other backends we officially support still use their own
custom event source and translation function, but the end goal is to
migrate them to the translate_event() virtual function, and have the
event source be a shared part of Clutter core.
2011-01-04 12:32:04 +00:00
|
|
|
GLXDrawable drawable = stage_glx->glxwin
|
|
|
|
? stage_glx->glxwin
|
|
|
|
: stage_x11->xwin;
|
glx: Unconditionally select X11/GLX events
Currently, we select input events and GLX events conditionally,
depending on whether the user has disabled event retrieval.
We should, instead, unconditionally select input events even with event
retrieval disabled because we need to guarantee that the Clutter
internal state is maintained when calling clutter_x11_handle_event()
without requiring applications or embedding toolkits to select events
themselves. If we did that, we'd have to document the events to be
selected, and also update applications and embedding toolkits each time
we added a new mask, or a new class of events - something that's clearly
not possible.
See:
http://bugzilla.clutter-project.org/show_bug.cgi?id=998
for the rationale of why we did conditional selection. It is now clear
that a compositor should clear out the input region, since it cannot
assume a perfectly clean slate coming from us.
See:
http://bugzilla.clutter-project.org/show_bug.cgi?id=2228
for an example of things that break if we do conditional event
selection on GLX events. In that specific case, the X11 server ≤ 1.8
always pushed GLX events on the queue, even without selecting them; this
has been fixed in the X11 server ≥ 1.9, which means that applications
like Mutter or toolkit integration libraries like Clutter-GTK would stop
working on recent Intel drivers providing the GLX_INTEL_swap_event
extension.
This change has been tested with Mutter and Clutter-GTK.
2010-08-03 15:11:52 +00:00
|
|
|
|
2011-01-18 12:59:49 +00:00
|
|
|
/* we unconditionally select this event because we rely on it to
|
|
|
|
* advance the master clock, and drive redraw/relayout, animations
|
|
|
|
* and event handling.
|
glx: Unconditionally select X11/GLX events
Currently, we select input events and GLX events conditionally,
depending on whether the user has disabled event retrieval.
We should, instead, unconditionally select input events even with event
retrieval disabled because we need to guarantee that the Clutter
internal state is maintained when calling clutter_x11_handle_event()
without requiring applications or embedding toolkits to select events
themselves. If we did that, we'd have to document the events to be
selected, and also update applications and embedding toolkits each time
we added a new mask, or a new class of events - something that's clearly
not possible.
See:
http://bugzilla.clutter-project.org/show_bug.cgi?id=998
for the rationale of why we did conditional selection. It is now clear
that a compositor should clear out the input region, since it cannot
assume a perfectly clean slate coming from us.
See:
http://bugzilla.clutter-project.org/show_bug.cgi?id=2228
for an example of things that break if we do conditional event
selection on GLX events. In that specific case, the X11 server ≤ 1.8
always pushed GLX events on the queue, even without selecting them; this
has been fixed in the X11 server ≥ 1.9, which means that applications
like Mutter or toolkit integration libraries like Clutter-GTK would stop
working on recent Intel drivers providing the GLX_INTEL_swap_event
extension.
This change has been tested with Mutter and Clutter-GTK.
2010-08-03 15:11:52 +00:00
|
|
|
*/
|
|
|
|
glXSelectEvent (backend_x11->xdpy,
|
|
|
|
drawable,
|
|
|
|
GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK);
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
glx: Unconditionally select X11/GLX events
Currently, we select input events and GLX events conditionally,
depending on whether the user has disabled event retrieval.
We should, instead, unconditionally select input events even with event
retrieval disabled because we need to guarantee that the Clutter
internal state is maintained when calling clutter_x11_handle_event()
without requiring applications or embedding toolkits to select events
themselves. If we did that, we'd have to document the events to be
selected, and also update applications and embedding toolkits each time
we added a new mask, or a new class of events - something that's clearly
not possible.
See:
http://bugzilla.clutter-project.org/show_bug.cgi?id=998
for the rationale of why we did conditional selection. It is now clear
that a compositor should clear out the input region, since it cannot
assume a perfectly clean slate coming from us.
See:
http://bugzilla.clutter-project.org/show_bug.cgi?id=2228
for an example of things that break if we do conditional event
selection on GLX events. In that specific case, the X11 server ≤ 1.8
always pushed GLX events on the queue, even without selecting them; this
has been fixed in the X11 server ≥ 1.9, which means that applications
like Mutter or toolkit integration libraries like Clutter-GTK would stop
working on recent Intel drivers providing the GLX_INTEL_swap_event
extension.
This change has been tested with Mutter and Clutter-GTK.
2010-08-03 15:11:52 +00:00
|
|
|
#endif /* GLX_INTEL_swap_event */
|
2009-05-13 21:21:48 +00:00
|
|
|
|
2009-08-13 11:34:07 +00:00
|
|
|
/* chain up to the StageX11 implementation */
|
2011-01-21 10:49:12 +00:00
|
|
|
return clutter_stage_window_parent_iface->realize (stage_window);
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 20:37:01 +00:00
|
|
|
static int
|
|
|
|
clutter_stage_glx_get_pending_swaps (ClutterStageWindow *stage_window)
|
|
|
|
{
|
|
|
|
ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (stage_window);
|
|
|
|
|
|
|
|
return stage_glx->pending_swaps;
|
|
|
|
}
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
static void
|
2011-01-21 10:49:12 +00:00
|
|
|
clutter_stage_glx_class_init (ClutterStageGLXClass *klass)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-21 10:49:12 +00:00
|
|
|
clutter_stage_glx_init (ClutterStageGLX *stage)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2008-04-04 15:02:11 +00:00
|
|
|
}
|
|
|
|
|
2009-11-30 17:47:55 +00:00
|
|
|
static gboolean
|
|
|
|
clutter_stage_glx_has_redraw_clips (ClutterStageWindow *stage_window)
|
|
|
|
{
|
|
|
|
ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (stage_window);
|
|
|
|
|
2010-11-23 16:05:44 +00:00
|
|
|
/* NB: at the start of each new frame there is an implied clip that
|
|
|
|
* clips everything (i.e. nothing would be drawn) so we need to make
|
|
|
|
* sure we return True in the un-initialized case here.
|
|
|
|
*
|
|
|
|
* NB: a clip width of 0 means a full stage redraw has been queued
|
|
|
|
* so we effectively don't have any redraw clips in that case.
|
|
|
|
*/
|
|
|
|
if (!stage_glx->initialized_redraw_clip ||
|
|
|
|
(stage_glx->initialized_redraw_clip &&
|
|
|
|
stage_glx->bounding_redraw_clip.width != 0))
|
2009-11-30 17:47:55 +00:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_stage_glx_ignoring_redraw_clips (ClutterStageWindow *stage_window)
|
|
|
|
{
|
|
|
|
ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (stage_window);
|
|
|
|
|
2010-11-23 16:05:44 +00:00
|
|
|
/* NB: a clip width of 0 means a full stage redraw is required */
|
2009-11-30 17:47:55 +00:00
|
|
|
if (stage_glx->initialized_redraw_clip &&
|
|
|
|
stage_glx->bounding_redraw_clip.width == 0)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A redraw clip represents (in stage coordinates) the bounding box of
|
|
|
|
* something that needs to be redraw. Typically they are added to the
|
|
|
|
* StageWindow as a result of clutter_actor_queue_clipped_redraw() by
|
|
|
|
* actors such as ClutterGLXTexturePixmap. All redraw clips are
|
|
|
|
* discarded after the next paint.
|
|
|
|
*
|
|
|
|
* A NULL stage_clip means the whole stage needs to be redrawn.
|
|
|
|
*
|
|
|
|
* What we do with this information:
|
|
|
|
* - we keep track of the bounding box for all redraw clips
|
|
|
|
* - when we come to redraw; if the bounding box is smaller than the
|
|
|
|
* stage we scissor the redraw to that box and use
|
|
|
|
* GLX_MESA_copy_sub_buffer to present the redraw to the front
|
2011-02-14 12:00:31 +00:00
|
|
|
* buffer.
|
2009-11-30 17:47:55 +00:00
|
|
|
*
|
2011-02-14 12:00:31 +00:00
|
|
|
* XXX - In theory, we should have some sort of heuristics to promote
|
|
|
|
* a clipped redraw to a full screen redraw; in reality, it turns out
|
|
|
|
* that promotion is fairly expensive. See the Clutter bug described
|
|
|
|
* at: http://bugzilla.clutter-project.org/show_bug.cgi?id=2136 .
|
2009-11-30 17:47:55 +00:00
|
|
|
*
|
|
|
|
* TODO - we should use different heuristics depending on whether the
|
|
|
|
* framebuffer is on screen and not redirected by a compositor VS
|
|
|
|
* offscreen (either due to compositor redirection or because we are
|
|
|
|
* rendering to a CoglOffscreen framebuffer)
|
|
|
|
*
|
|
|
|
* When not redirected glXCopySubBuffer (on intel hardware at least)
|
|
|
|
* will block the GPU until the vertical trace is at the optimal point
|
|
|
|
* so the copy can be done without tearing. In this case we don't want
|
|
|
|
* to copy tall regions because they increase the average time spent
|
|
|
|
* blocking the GPU.
|
|
|
|
*
|
|
|
|
* When rendering offscreen (CoglOffscreen or redirected by
|
|
|
|
* compositor) then no extra synchronization is needed before the copy
|
|
|
|
* can start.
|
|
|
|
*
|
|
|
|
* In all cases we need to consider that glXCopySubBuffer implies a
|
|
|
|
* blit which may be avoided by promoting to a full stage redraw if:
|
|
|
|
* - the framebuffer is redirected offscreen or a CoglOffscreen.
|
|
|
|
* - the framebuffer is onscreen and fullscreen.
|
|
|
|
* By promoting to a full stage redraw we trade off the cost involved
|
|
|
|
* in rasterizing the extra pixels vs avoiding to use a blit to
|
|
|
|
* present the back buffer.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
clutter_stage_glx_add_redraw_clip (ClutterStageWindow *stage_window,
|
|
|
|
ClutterGeometry *stage_clip)
|
|
|
|
{
|
|
|
|
ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (stage_window);
|
|
|
|
|
|
|
|
/* If we are already forced to do a full stage redraw then bail early */
|
|
|
|
if (clutter_stage_glx_ignoring_redraw_clips (stage_window))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* A NULL stage clip means a full stage redraw has been queued and
|
2010-11-23 16:05:44 +00:00
|
|
|
* we keep track of this by setting a zero width
|
2009-11-30 17:47:55 +00:00
|
|
|
* stage_glx->bounding_redraw_clip */
|
2010-03-19 11:39:23 +00:00
|
|
|
if (stage_clip == NULL)
|
2009-11-30 17:47:55 +00:00
|
|
|
{
|
|
|
|
stage_glx->bounding_redraw_clip.width = 0;
|
2010-09-08 00:41:01 +00:00
|
|
|
stage_glx->initialized_redraw_clip = TRUE;
|
2009-11-30 17:47:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-08 00:41:01 +00:00
|
|
|
/* Ignore requests to add degenerate/empty clip rectangles */
|
2010-03-19 18:18:17 +00:00
|
|
|
if (stage_clip->width == 0 || stage_clip->height == 0)
|
|
|
|
return;
|
|
|
|
|
2009-11-30 17:47:55 +00:00
|
|
|
if (!stage_glx->initialized_redraw_clip)
|
|
|
|
{
|
|
|
|
stage_glx->bounding_redraw_clip.x = stage_clip->x;
|
|
|
|
stage_glx->bounding_redraw_clip.y = stage_clip->y;
|
|
|
|
stage_glx->bounding_redraw_clip.width = stage_clip->width;
|
|
|
|
stage_glx->bounding_redraw_clip.height = stage_clip->height;
|
|
|
|
}
|
2010-03-18 17:55:01 +00:00
|
|
|
else if (stage_glx->bounding_redraw_clip.width > 0)
|
2009-11-30 17:47:55 +00:00
|
|
|
{
|
2011-02-14 12:00:31 +00:00
|
|
|
clutter_geometry_union (&stage_glx->bounding_redraw_clip,
|
|
|
|
stage_clip,
|
2010-03-18 17:55:01 +00:00
|
|
|
&stage_glx->bounding_redraw_clip);
|
2009-11-30 17:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
redraw_area = (stage_glx->bounding_redraw_clip.width *
|
|
|
|
stage_glx->bounding_redraw_clip.height);
|
|
|
|
stage_area = stage_x11->xwin_width * stage_x11->xwin_height;
|
|
|
|
|
|
|
|
/* Redrawing and blitting >70% of the stage is assumed to be more
|
|
|
|
* expensive than redrawing the additional 30% to avoid the blit.
|
|
|
|
*
|
|
|
|
* FIXME: This threshold was plucked out of thin air!
|
2011-02-14 12:00:31 +00:00
|
|
|
*
|
|
|
|
* The threshold has been disabled after verifying that it indeed
|
|
|
|
* made redraws more expensive than intended; see bug reference:
|
|
|
|
*
|
|
|
|
* http://bugzilla.clutter-project.org/show_bug.cgi?id=2136
|
2009-11-30 17:47:55 +00:00
|
|
|
*/
|
|
|
|
if (redraw_area > (stage_area * 0.7f))
|
|
|
|
{
|
|
|
|
g_print ("DEBUG: clipped redraw too big, forcing full redraw\n");
|
2010-11-23 16:05:44 +00:00
|
|
|
/* Set a zero width clip to force a full redraw */
|
2009-11-30 17:47:55 +00:00
|
|
|
stage_glx->bounding_redraw_clip.width = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
stage_glx->initialized_redraw_clip = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-09 10:29:03 +00:00
|
|
|
#ifdef HAVE_DRM
|
2009-11-30 17:47:55 +00:00
|
|
|
static int
|
|
|
|
drm_wait_vblank(int fd, drm_wait_vblank_t *vbl)
|
|
|
|
{
|
|
|
|
int ret, rc;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ret = ioctl(fd, DRM_IOCTL_WAIT_VBLANK, vbl);
|
2010-08-09 10:29:03 +00:00
|
|
|
vbl->request.type &= ~_DRM_VBLANK_RELATIVE;
|
2009-11-30 17:47:55 +00:00
|
|
|
rc = errno;
|
|
|
|
}
|
|
|
|
while (ret && rc == EINTR);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2010-08-09 10:29:03 +00:00
|
|
|
#endif /* HAVE_DRM */
|
2009-11-30 17:47:55 +00:00
|
|
|
|
|
|
|
static void
|
2010-06-03 19:03:20 +00:00
|
|
|
wait_for_vblank (ClutterBackendGLX *backend_glx)
|
2009-11-30 17:47:55 +00:00
|
|
|
{
|
2010-06-03 19:03:20 +00:00
|
|
|
if (backend_glx->vblank_type == CLUTTER_VBLANK_NONE)
|
|
|
|
return;
|
2009-11-30 17:47:55 +00:00
|
|
|
|
2010-06-03 19:03:20 +00:00
|
|
|
if (backend_glx->wait_video_sync)
|
|
|
|
{
|
|
|
|
unsigned int retraceCount;
|
2009-11-30 17:47:55 +00:00
|
|
|
|
2010-06-03 19:03:20 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "Waiting for vblank (wait_video_sync)");
|
|
|
|
backend_glx->get_video_sync (&retraceCount);
|
|
|
|
backend_glx->wait_video_sync (2,
|
|
|
|
(retraceCount + 1) % 2,
|
|
|
|
&retraceCount);
|
|
|
|
}
|
2010-07-14 18:46:23 +00:00
|
|
|
else
|
2010-06-03 19:03:20 +00:00
|
|
|
{
|
2010-08-09 10:29:03 +00:00
|
|
|
#ifdef HAVE_DRM
|
2010-06-03 19:03:20 +00:00
|
|
|
drm_wait_vblank_t blank;
|
2009-11-30 17:47:55 +00:00
|
|
|
|
2010-06-03 19:03:20 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "Waiting for vblank (drm)");
|
2010-08-09 10:29:03 +00:00
|
|
|
blank.request.type = _DRM_VBLANK_RELATIVE;
|
2010-06-03 19:03:20 +00:00
|
|
|
blank.request.sequence = 1;
|
|
|
|
blank.request.signal = 0;
|
|
|
|
drm_wait_vblank (backend_glx->dri_fd, &blank);
|
2010-08-09 10:29:03 +00:00
|
|
|
#else
|
|
|
|
CLUTTER_NOTE (BACKEND, "No vblank mechanism found");
|
|
|
|
#endif /* HAVE_DRM */
|
2009-11-30 17:47:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-04 15:09:41 +00:00
|
|
|
static void
|
|
|
|
clutter_stage_glx_redraw (ClutterStageWindow *stage_window)
|
2009-11-30 17:47:55 +00:00
|
|
|
{
|
|
|
|
ClutterBackendX11 *backend_x11;
|
|
|
|
ClutterBackendGLX *backend_glx;
|
2011-02-04 15:09:41 +00:00
|
|
|
ClutterStageX11 *stage_x11;
|
|
|
|
ClutterStageGLX *stage_glx;
|
|
|
|
GLXDrawable drawable;
|
|
|
|
unsigned int video_sync_count;
|
|
|
|
gboolean may_use_clipped_redraw;
|
|
|
|
gboolean use_clipped_redraw;
|
|
|
|
|
2009-11-30 17:47:55 +00:00
|
|
|
CLUTTER_STATIC_TIMER (painting_timer,
|
|
|
|
"Redrawing", /* parent */
|
|
|
|
"Painting actors",
|
|
|
|
"The time spent painting actors",
|
|
|
|
0 /* no application private data */);
|
|
|
|
CLUTTER_STATIC_TIMER (swapbuffers_timer,
|
|
|
|
"Redrawing", /* parent */
|
|
|
|
"glXSwapBuffers",
|
|
|
|
"The time spent blocked by glXSwapBuffers",
|
|
|
|
0 /* no application private data */);
|
2010-06-05 10:51:32 +00:00
|
|
|
CLUTTER_STATIC_TIMER (blit_sub_buffer_timer,
|
2009-11-30 17:47:55 +00:00
|
|
|
"Redrawing", /* parent */
|
2010-06-05 10:51:32 +00:00
|
|
|
"glx_blit_sub_buffer",
|
|
|
|
"The time spent in _glx_blit_sub_buffer",
|
2009-11-30 17:47:55 +00:00
|
|
|
0 /* no application private data */);
|
|
|
|
|
2011-02-04 15:09:41 +00:00
|
|
|
stage_x11 = CLUTTER_STAGE_X11 (stage_window);
|
2011-01-21 10:49:12 +00:00
|
|
|
if (stage_x11->xwin == None)
|
|
|
|
return;
|
|
|
|
|
2011-02-04 15:09:41 +00:00
|
|
|
stage_glx = CLUTTER_STAGE_GLX (stage_window);
|
|
|
|
|
|
|
|
backend_x11 = stage_x11->backend;
|
|
|
|
backend_glx = CLUTTER_BACKEND_GLX (backend_x11);
|
2009-11-30 17:47:55 +00:00
|
|
|
|
|
|
|
CLUTTER_TIMER_START (_clutter_uprof_context, painting_timer);
|
|
|
|
|
2010-09-07 22:07:52 +00:00
|
|
|
if (G_LIKELY (backend_glx->can_blit_sub_buffer) &&
|
2010-11-23 16:05:44 +00:00
|
|
|
/* NB: a zero width redraw clip == full stage redraw */
|
2010-09-08 00:15:00 +00:00
|
|
|
stage_glx->bounding_redraw_clip.width != 0 &&
|
2010-09-08 00:18:30 +00:00
|
|
|
/* some drivers struggle to get going and produce some junk
|
|
|
|
* frames when starting up... */
|
|
|
|
G_LIKELY (stage_glx->frame_count > 3) &&
|
2010-09-08 00:15:00 +00:00
|
|
|
/* While resizing a window clipped redraws are disabled to avoid
|
|
|
|
* artefacts. See clutter-event-x11.c:event_translate for a
|
|
|
|
* detailed explanation */
|
|
|
|
G_LIKELY (stage_x11->clipped_redraws_cool_off == 0))
|
2011-01-21 10:49:12 +00:00
|
|
|
{
|
|
|
|
may_use_clipped_redraw = TRUE;
|
|
|
|
}
|
2010-09-07 22:07:52 +00:00
|
|
|
else
|
|
|
|
may_use_clipped_redraw = FALSE;
|
|
|
|
|
|
|
|
if (may_use_clipped_redraw &&
|
2009-11-30 17:47:55 +00:00
|
|
|
G_LIKELY (!(clutter_paint_debug_flags &
|
|
|
|
CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS)))
|
2010-09-07 22:07:52 +00:00
|
|
|
use_clipped_redraw = TRUE;
|
|
|
|
else
|
|
|
|
use_clipped_redraw = FALSE;
|
|
|
|
|
|
|
|
if (use_clipped_redraw)
|
2009-11-30 17:47:55 +00:00
|
|
|
{
|
|
|
|
cogl_clip_push_window_rectangle (stage_glx->bounding_redraw_clip.x,
|
|
|
|
stage_glx->bounding_redraw_clip.y,
|
|
|
|
stage_glx->bounding_redraw_clip.width,
|
|
|
|
stage_glx->bounding_redraw_clip.height);
|
2011-02-04 15:09:41 +00:00
|
|
|
_clutter_stage_do_paint (stage_x11->wrapper,
|
|
|
|
&stage_glx->bounding_redraw_clip);
|
2009-11-30 17:47:55 +00:00
|
|
|
cogl_clip_pop ();
|
|
|
|
}
|
|
|
|
else
|
2011-02-04 15:09:41 +00:00
|
|
|
_clutter_stage_do_paint (stage_x11->wrapper, NULL);
|
2009-11-30 17:47:55 +00:00
|
|
|
|
2011-02-04 15:09:41 +00:00
|
|
|
if (may_use_clipped_redraw &&
|
|
|
|
G_UNLIKELY ((clutter_paint_debug_flags & CLUTTER_DEBUG_REDRAWS)))
|
2010-09-07 22:07:52 +00:00
|
|
|
{
|
|
|
|
static CoglMaterial *outline = NULL;
|
2011-02-04 15:09:41 +00:00
|
|
|
ClutterGeometry *clip = &stage_glx->bounding_redraw_clip;
|
|
|
|
ClutterActor *actor = CLUTTER_ACTOR (stage_x11->wrapper);
|
2010-09-07 22:07:52 +00:00
|
|
|
CoglHandle vbo;
|
|
|
|
float x_1 = clip->x;
|
|
|
|
float x_2 = clip->x + clip->width;
|
|
|
|
float y_1 = clip->y;
|
|
|
|
float y_2 = clip->y + clip->height;
|
|
|
|
float quad[8] = {
|
|
|
|
x_1, y_1,
|
|
|
|
x_2, y_1,
|
|
|
|
x_2, y_2,
|
|
|
|
x_1, y_2
|
|
|
|
};
|
|
|
|
CoglMatrix modelview;
|
|
|
|
|
|
|
|
if (outline == NULL)
|
|
|
|
{
|
|
|
|
outline = cogl_material_new ();
|
|
|
|
cogl_material_set_color4ub (outline, 0xff, 0x00, 0x00, 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
vbo = cogl_vertex_buffer_new (4);
|
|
|
|
cogl_vertex_buffer_add (vbo,
|
|
|
|
"gl_Vertex",
|
|
|
|
2, /* n_components */
|
|
|
|
COGL_ATTRIBUTE_TYPE_FLOAT,
|
|
|
|
FALSE, /* normalized */
|
|
|
|
0, /* stride */
|
|
|
|
quad);
|
|
|
|
cogl_vertex_buffer_submit (vbo);
|
|
|
|
|
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_matrix_init_identity (&modelview);
|
2011-02-04 15:09:41 +00:00
|
|
|
_clutter_actor_apply_modelview_transform (actor, &modelview);
|
2010-09-07 22:07:52 +00:00
|
|
|
cogl_set_modelview_matrix (&modelview);
|
|
|
|
cogl_set_source (outline);
|
|
|
|
cogl_vertex_buffer_draw (vbo, COGL_VERTICES_MODE_LINE_LOOP,
|
|
|
|
0 , 4);
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
cogl_object_unref (vbo);
|
|
|
|
}
|
|
|
|
|
2009-11-30 17:47:55 +00:00
|
|
|
cogl_flush ();
|
|
|
|
CLUTTER_TIMER_STOP (_clutter_uprof_context, painting_timer);
|
|
|
|
|
2011-01-21 10:49:12 +00:00
|
|
|
drawable = stage_glx->glxwin
|
|
|
|
? stage_glx->glxwin
|
|
|
|
: stage_x11->xwin;
|
2009-11-30 17:47:55 +00:00
|
|
|
|
2010-06-03 19:03:20 +00:00
|
|
|
/* If we might ever use _clutter_backend_glx_blit_sub_buffer then we
|
|
|
|
* always need to keep track of the video_sync_count so that we can
|
|
|
|
* throttle blits.
|
|
|
|
*
|
|
|
|
* Note: we get the count *before* we issue any glXCopySubBuffer or
|
|
|
|
* blit_sub_buffer request in case the count would go up before
|
|
|
|
* returning control to us.
|
|
|
|
*/
|
|
|
|
if (backend_glx->can_blit_sub_buffer && backend_glx->get_video_sync)
|
|
|
|
backend_glx->get_video_sync (&video_sync_count);
|
|
|
|
|
2009-11-30 17:47:55 +00:00
|
|
|
/* push on the screen */
|
2010-09-07 22:07:52 +00:00
|
|
|
if (use_clipped_redraw)
|
2009-11-30 17:47:55 +00:00
|
|
|
{
|
|
|
|
ClutterGeometry *clip = &stage_glx->bounding_redraw_clip;
|
|
|
|
ClutterGeometry copy_area;
|
2011-02-04 15:09:41 +00:00
|
|
|
ClutterActor *actor;
|
2009-11-30 17:47:55 +00:00
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND,
|
2010-06-05 10:51:32 +00:00
|
|
|
"_glx_blit_sub_buffer (window: 0x%lx, "
|
2009-11-30 17:47:55 +00:00
|
|
|
"x: %d, y: %d, "
|
|
|
|
"width: %d, height: %d)",
|
|
|
|
(unsigned long) drawable,
|
|
|
|
stage_glx->bounding_redraw_clip.x,
|
|
|
|
stage_glx->bounding_redraw_clip.y,
|
|
|
|
stage_glx->bounding_redraw_clip.width,
|
|
|
|
stage_glx->bounding_redraw_clip.height);
|
|
|
|
|
|
|
|
/* XXX: It seems there will be a race here in that the stage
|
|
|
|
* window may be resized before glXCopySubBufferMESA is handled
|
|
|
|
* and so we may copy the wrong region. I can't really see how
|
|
|
|
* we can handle this with the current state of X but at least
|
|
|
|
* in this case a full redraw should be queued by the resize
|
|
|
|
* anyway so it should only exhibit temporary artefacts.
|
|
|
|
*/
|
2011-02-04 15:09:41 +00:00
|
|
|
actor = CLUTTER_ACTOR (stage_x11->wrapper);
|
|
|
|
copy_area.y = clutter_actor_get_height (actor)
|
2011-01-21 10:49:12 +00:00
|
|
|
- clip->y
|
|
|
|
- clip->height;
|
2009-11-30 17:47:55 +00:00
|
|
|
copy_area.x = clip->x;
|
|
|
|
copy_area.width = clip->width;
|
|
|
|
copy_area.height = clip->height;
|
|
|
|
|
2010-06-03 19:03:20 +00:00
|
|
|
/* glXCopySubBufferMESA and glBlitFramebuffer are not integrated
|
|
|
|
* with the glXSwapIntervalSGI mechanism which we usually use to
|
|
|
|
* throttle the Clutter framerate to the vertical refresh and so
|
|
|
|
* we have to manually wait for the vblank period...
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Here 'is_synchronized' only means that the blit won't cause a
|
|
|
|
* tear, ie it won't prevent multiple blits per retrace if they
|
|
|
|
* can all be performed in the blanking period. If that's the
|
|
|
|
* case then we still want to use the vblank sync menchanism but
|
|
|
|
* we only need it to throttle redraws.
|
|
|
|
*/
|
|
|
|
if (!backend_glx->blit_sub_buffer_is_synchronized)
|
|
|
|
{
|
|
|
|
/* XXX: note that glXCopySubBuffer, at least for Intel, is
|
|
|
|
* synchronized with the vblank but glBlitFramebuffer may
|
|
|
|
* not be so we use the same scheme we do when calling
|
|
|
|
* glXSwapBuffers without the swap_control extension and
|
|
|
|
* call glFinish () before waiting for the vblank period.
|
|
|
|
*
|
|
|
|
* See where we call glXSwapBuffers for more details.
|
|
|
|
*/
|
|
|
|
glFinish ();
|
2011-02-04 15:09:41 +00:00
|
|
|
wait_for_vblank (backend_glx);
|
2010-06-03 19:03:20 +00:00
|
|
|
}
|
|
|
|
else if (backend_glx->get_video_sync)
|
|
|
|
{
|
|
|
|
/* If we have the GLX_SGI_video_sync extension then we can
|
|
|
|
* be a bit smarter about how we throttle blits by avoiding
|
|
|
|
* any waits if we can see that the video sync count has
|
|
|
|
* already progressed. */
|
|
|
|
if (backend_glx->last_video_sync_count == video_sync_count)
|
2011-02-04 15:09:41 +00:00
|
|
|
wait_for_vblank (backend_glx);
|
2010-06-03 19:03:20 +00:00
|
|
|
}
|
|
|
|
else
|
2011-02-04 15:09:41 +00:00
|
|
|
wait_for_vblank (backend_glx);
|
2010-06-03 19:03:20 +00:00
|
|
|
|
2010-06-05 10:51:32 +00:00
|
|
|
CLUTTER_TIMER_START (_clutter_uprof_context, blit_sub_buffer_timer);
|
|
|
|
_clutter_backend_glx_blit_sub_buffer (backend_glx,
|
|
|
|
drawable,
|
|
|
|
copy_area.x,
|
|
|
|
copy_area.y,
|
|
|
|
copy_area.width,
|
|
|
|
copy_area.height);
|
|
|
|
CLUTTER_TIMER_STOP (_clutter_uprof_context, blit_sub_buffer_timer);
|
2009-11-30 17:47:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "glXSwapBuffers (display: %p, window: 0x%lx)",
|
|
|
|
backend_x11->xdpy,
|
|
|
|
(unsigned long) drawable);
|
|
|
|
|
|
|
|
/* If we have GLX swap buffer events then glXSwapBuffers will return
|
|
|
|
* immediately and we need to track that there is a swap in
|
|
|
|
* progress... */
|
|
|
|
if (clutter_feature_available (CLUTTER_FEATURE_SWAP_EVENTS))
|
|
|
|
stage_glx->pending_swaps++;
|
|
|
|
|
2010-06-09 01:42:01 +00:00
|
|
|
if (backend_glx->vblank_type != CLUTTER_VBLANK_GLX_SWAP &&
|
|
|
|
backend_glx->vblank_type != CLUTTER_VBLANK_NONE)
|
2010-06-03 19:03:20 +00:00
|
|
|
{
|
|
|
|
/* If we are going to wait for VBLANK manually, we not only
|
|
|
|
* need to flush out pending drawing to the GPU before we
|
|
|
|
* sleep, we need to wait for it to finish. Otherwise, we
|
|
|
|
* may end up with the situation:
|
|
|
|
*
|
|
|
|
* - We finish drawing - GPU drawing continues
|
|
|
|
* - We go to sleep - GPU drawing continues
|
|
|
|
* VBLANK - We call glXSwapBuffers - GPU drawing continues
|
|
|
|
* - GPU drawing continues
|
|
|
|
* - Swap buffers happens
|
|
|
|
*
|
|
|
|
* Producing a tear. Calling glFinish() first will cause us
|
|
|
|
* to properly wait for the next VBLANK before we swap. This
|
|
|
|
* obviously does not happen when we use _GLX_SWAP and let
|
|
|
|
* the driver do the right thing
|
|
|
|
*/
|
|
|
|
glFinish ();
|
|
|
|
|
2011-02-04 15:09:41 +00:00
|
|
|
wait_for_vblank (backend_glx);
|
2010-06-03 19:03:20 +00:00
|
|
|
}
|
2010-06-03 19:03:20 +00:00
|
|
|
|
2009-11-30 17:47:55 +00:00
|
|
|
CLUTTER_TIMER_START (_clutter_uprof_context, swapbuffers_timer);
|
|
|
|
glXSwapBuffers (backend_x11->xdpy, drawable);
|
|
|
|
CLUTTER_TIMER_STOP (_clutter_uprof_context, swapbuffers_timer);
|
2011-02-04 15:09:41 +00:00
|
|
|
|
2011-01-12 22:06:58 +00:00
|
|
|
_cogl_swap_buffers_notify ();
|
2009-11-30 17:47:55 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 19:03:20 +00:00
|
|
|
backend_glx->last_video_sync_count = video_sync_count;
|
|
|
|
|
2009-11-30 17:47:55 +00:00
|
|
|
/* reset the redraw clipping for the next paint... */
|
|
|
|
stage_glx->initialized_redraw_clip = FALSE;
|
2010-09-08 00:18:30 +00:00
|
|
|
|
|
|
|
stage_glx->frame_count++;
|
2009-11-30 17:47:55 +00:00
|
|
|
}
|
2011-02-04 15:09:41 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
|
|
|
|
{
|
|
|
|
clutter_stage_window_parent_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
iface->realize = clutter_stage_glx_realize;
|
|
|
|
iface->unrealize = clutter_stage_glx_unrealize;
|
|
|
|
iface->get_pending_swaps = clutter_stage_glx_get_pending_swaps;
|
|
|
|
|
|
|
|
iface->add_redraw_clip = clutter_stage_glx_add_redraw_clip;
|
|
|
|
iface->has_redraw_clips = clutter_stage_glx_has_redraw_clips;
|
|
|
|
iface->ignoring_redraw_clips = clutter_stage_glx_ignoring_redraw_clips;
|
|
|
|
iface->redraw = clutter_stage_glx_redraw;
|
|
|
|
|
|
|
|
/* the rest is inherited from ClutterStageX11 */
|
|
|
|
}
|
|
|
|
|
|
|
|
static ClutterTranslateReturn
|
|
|
|
clutter_stage_glx_translate_event (ClutterEventTranslator *translator,
|
|
|
|
gpointer native,
|
|
|
|
ClutterEvent *event)
|
|
|
|
{
|
|
|
|
#ifdef GLX_INTEL_swap_event
|
|
|
|
ClutterBackendGLX *backend_glx;
|
|
|
|
XEvent *xevent = native;
|
|
|
|
|
|
|
|
backend_glx = CLUTTER_BACKEND_GLX (clutter_get_default_backend ());
|
|
|
|
|
|
|
|
if (xevent->type == (backend_glx->event_base + GLX_BufferSwapComplete))
|
|
|
|
{
|
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (translator);
|
|
|
|
ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (translator);
|
|
|
|
GLXBufferSwapComplete *swap_complete_event;
|
|
|
|
|
|
|
|
swap_complete_event = (GLXBufferSwapComplete *) xevent;
|
|
|
|
|
|
|
|
if (stage_x11->xwin == swap_complete_event->drawable)
|
|
|
|
{
|
|
|
|
/* Early versions of the swap_event implementation in Mesa
|
|
|
|
* deliver BufferSwapComplete event when not selected for,
|
|
|
|
* so if we get a swap event we aren't expecting, just ignore it.
|
|
|
|
*
|
|
|
|
* https://bugs.freedesktop.org/show_bug.cgi?id=27962
|
|
|
|
*/
|
|
|
|
if (stage_glx->pending_swaps > 0)
|
|
|
|
stage_glx->pending_swaps--;
|
|
|
|
|
|
|
|
return CLUTTER_TRANSLATE_REMOVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* chain up to the common X11 implementation */
|
|
|
|
return clutter_event_translator_parent_iface->translate_event (translator,
|
|
|
|
native,
|
|
|
|
event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_event_translator_iface_init (ClutterEventTranslatorIface *iface)
|
|
|
|
{
|
|
|
|
clutter_event_translator_parent_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
iface->translate_event = clutter_stage_glx_translate_event;
|
|
|
|
}
|