mutter/clutter/clutter/clutter-stage.c

4551 lines
141 KiB
C
Raw Normal View History

2006-05-29 08:59:36 +00:00
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2006 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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
2006-05-29 08:59:36 +00:00
*/
/**
* ClutterStage:
*
* Top level visual element to which actors are placed.
*
* #ClutterStage is a top level 'window' on which child actors are placed
* and manipulated.
*
2018-10-19 09:15:54 +02:00
* #ClutterStage is a proxy actor, wrapping the backend-specific implementation
* (a #StageWindow) of the windowing system. It is possible to subclass
* #ClutterStage, as long as every overridden virtual function chains up to the
* parent class corresponding function.
*/
#include "config.h"
2006-06-05 Emmanuele Bassi <ebassi@openedhand.com> * clutter-color.h: * clutter-color.c: Reimplement ClutterColor as a boxed type; add convenience API for color handling, like: add, subtract, shade, HSL color-space conversion, packing and unpacking. * clutter-private.h: Update ClutterMainContext, and export the main context pointer here. * clutter-rectangle.h: * clutter-rectangle.c: Update the color-related code; make clutter_rectangle_new() and empty constructor and provide clutter_rectangle_new_with_color(); provide color setter and getter API. * clutter-label.h: * clutter-label.c: Rename the "font" property to "font-name"; update the color-related code to the new ClutterColor object; rename clutter_label_new() to clutter_label_new_with_text(), and add setters and getters for the properties. * clutter-marshal.list: Add VOID:OBJECT and VOID:BOXED marshallers generators. * clutter-stage.h: * clutter-stage.c: Rework the API: provide a default constructor for a singleton object, named clutter_stage_get_default(), which supercedes the clutter_stage() function in clutter-main; provide new events: button-press-event, button-release-event, key-press-event and key-release-event; update the color-related code; (clutter_stage_snapshot): Allow negative width and height when taking a snapshot (meaning: use full width/height). (clutter_stage_get_element_at_pos): Rename clutter_stage_pick(). * clutter-element.c (clutter_element_paint): Clean up the stage and color related code. * clutter-event.h: * clutter-event.c: Add generic ClutterAnyEvent type; add clutter_event_new(), clutter_event_copy() and clutter_event_free(); make ClutterEvent a boxed type. * clutter-main.h: * clutter-main.c: Remove clutter_stage(); add clutter_main_quit(), for cleanly quitting from clutter_main(); add multiple mainloops support; allocate the ClutterCntx instead of adding it to the stack; re-work the ClutterEvent dispatching. * clutter-group.c (clutter_group_add), (clutter_group_remove): Keep a reference on the element when added to a ClutterGroup. * examples/rects.py * examples/test.c: * examples/test-text.c: * examples/video-cube.c: * examples/super-oh.c: * examples/test-video.c: Update.
2006-06-05 13:38:31 +00:00
#include <math.h>
#include "clutter/clutter-stage.h"
#include "clutter/clutter-action-private.h"
#include "clutter/clutter-actor-private.h"
#include "clutter/clutter-backend-private.h"
#include "clutter/clutter-context-private.h"
#include "clutter/clutter-debug.h"
#include "clutter/clutter-enum-types.h"
#include "clutter/clutter-event-private.h"
#include "clutter/clutter-frame-clock.h"
#include "clutter/clutter-frame.h"
#include "clutter/clutter-grab-private.h"
#include "clutter/clutter-input-device-private.h"
#include "clutter/clutter-input-only-actor.h"
#include "clutter/clutter-main.h"
#include "clutter/clutter-marshal.h"
#include "clutter/clutter-mutter.h"
#include "clutter/clutter-paint-context-private.h"
#include "clutter/clutter-paint-volume-private.h"
#include "clutter/clutter-pick-context-private.h"
#include "clutter/clutter-private.h"
#include "clutter/clutter-seat-private.h"
#include "clutter/clutter-stage-manager-private.h"
#include "clutter/clutter-stage-private.h"
#include "clutter/clutter-stage-view-private.h"
#include "clutter/clutter-private.h"
2006-05-29 08:59:36 +00:00
#include "cogl/cogl.h"
#define MAX_FRUSTA 64
clutter: Introduce geometric picking Currently, Clutter does picking by drawing with Cogl and reading the pixel that's beneath the given point. Since Cogl has a journal that records drawing operations, and has optimizations to read a single pixel from a list of rectangle, it would be expected that we would hit this fast path and not flush the journal while picking. However, that's not the case: dithering, clipping with scissors, etc, can all flush the journal, issuing commands to the GPU and making picking slow. On NVidia-based systems, this glReadPixels() call is extremely costly. Introduce geometric picking, and avoid using the Cogl journal entirely. Do this by introducing a stack of actors in ClutterStage. This stack is cached, but for now, don't use the cache as much as possible. The picking routines are still tied to painting. When projecting the actor vertexes, do it manually and take the modelview matrix of the framebuffer into account as well. CPU usage on an Intel i7-7700, tested with two different GPUs/drivers: | | Intel | Nvidia | | ------: | --------: | -----: | | Moving the mouse: | | Before | 10% | 10% | | After | 6% | 6% | | Moving a window: | | Before | 23% | 81% | | After | 19% | 40% | Closes: https://gitlab.gnome.org/GNOME/mutter/issues/154, https://gitlab.gnome.org/GNOME/mutter/issues/691 Helps significantly with: https://gitlab.gnome.org/GNOME/mutter/issues/283, https://gitlab.gnome.org/GNOME/mutter/issues/590, https://gitlab.gnome.org/GNOME/mutter/issues/700 v2: Fix code style issues Simplify quadrilateral checks Remove the 0.5f hack Differentiate axis-aligned rectangles https://gitlab.gnome.org/GNOME/mutter/merge_requests/189
2018-08-02 19:03:30 +08:00
typedef struct _PickRecord
{
graphene_point_t vertex[4];
clutter: Introduce geometric picking Currently, Clutter does picking by drawing with Cogl and reading the pixel that's beneath the given point. Since Cogl has a journal that records drawing operations, and has optimizations to read a single pixel from a list of rectangle, it would be expected that we would hit this fast path and not flush the journal while picking. However, that's not the case: dithering, clipping with scissors, etc, can all flush the journal, issuing commands to the GPU and making picking slow. On NVidia-based systems, this glReadPixels() call is extremely costly. Introduce geometric picking, and avoid using the Cogl journal entirely. Do this by introducing a stack of actors in ClutterStage. This stack is cached, but for now, don't use the cache as much as possible. The picking routines are still tied to painting. When projecting the actor vertexes, do it manually and take the modelview matrix of the framebuffer into account as well. CPU usage on an Intel i7-7700, tested with two different GPUs/drivers: | | Intel | Nvidia | | ------: | --------: | -----: | | Moving the mouse: | | Before | 10% | 10% | | After | 6% | 6% | | Moving a window: | | Before | 23% | 81% | | After | 19% | 40% | Closes: https://gitlab.gnome.org/GNOME/mutter/issues/154, https://gitlab.gnome.org/GNOME/mutter/issues/691 Helps significantly with: https://gitlab.gnome.org/GNOME/mutter/issues/283, https://gitlab.gnome.org/GNOME/mutter/issues/590, https://gitlab.gnome.org/GNOME/mutter/issues/700 v2: Fix code style issues Simplify quadrilateral checks Remove the 0.5f hack Differentiate axis-aligned rectangles https://gitlab.gnome.org/GNOME/mutter/merge_requests/189
2018-08-02 19:03:30 +08:00
ClutterActor *actor;
int clip_stack_top;
} PickRecord;
typedef struct _PickClipRecord
{
int prev;
graphene_point_t vertex[4];
clutter: Introduce geometric picking Currently, Clutter does picking by drawing with Cogl and reading the pixel that's beneath the given point. Since Cogl has a journal that records drawing operations, and has optimizations to read a single pixel from a list of rectangle, it would be expected that we would hit this fast path and not flush the journal while picking. However, that's not the case: dithering, clipping with scissors, etc, can all flush the journal, issuing commands to the GPU and making picking slow. On NVidia-based systems, this glReadPixels() call is extremely costly. Introduce geometric picking, and avoid using the Cogl journal entirely. Do this by introducing a stack of actors in ClutterStage. This stack is cached, but for now, don't use the cache as much as possible. The picking routines are still tied to painting. When projecting the actor vertexes, do it manually and take the modelview matrix of the framebuffer into account as well. CPU usage on an Intel i7-7700, tested with two different GPUs/drivers: | | Intel | Nvidia | | ------: | --------: | -----: | | Moving the mouse: | | Before | 10% | 10% | | After | 6% | 6% | | Moving a window: | | Before | 23% | 81% | | After | 19% | 40% | Closes: https://gitlab.gnome.org/GNOME/mutter/issues/154, https://gitlab.gnome.org/GNOME/mutter/issues/691 Helps significantly with: https://gitlab.gnome.org/GNOME/mutter/issues/283, https://gitlab.gnome.org/GNOME/mutter/issues/590, https://gitlab.gnome.org/GNOME/mutter/issues/700 v2: Fix code style issues Simplify quadrilateral checks Remove the 0.5f hack Differentiate axis-aligned rectangles https://gitlab.gnome.org/GNOME/mutter/merge_requests/189
2018-08-02 19:03:30 +08:00
} PickClipRecord;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
typedef struct _EventReceiver
{
ClutterActor *actor;
ClutterEventPhase phase;
ClutterAction *action;
} EventReceiver;
typedef struct _PointerDeviceEntry
{
ClutterStage *stage;
ClutterInputDevice *device;
ClutterEventSequence *sequence;
graphene_point_t coords;
ClutterActor *current_actor;
MtkRegion *clear_area;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
unsigned int press_count;
ClutterActor *implicit_grab_actor;
GArray *event_emission_chain;
} PointerDeviceEntry;
typedef struct _ClutterStagePrivate
2006-05-29 08:59:36 +00:00
{
/* the stage implementation */
ClutterStageWindow *impl;
ClutterPerspective perspective;
graphene_matrix_t projection;
graphene_matrix_t inverse_projection;
graphene_matrix_t view;
float viewport[4];
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
gchar *title;
ClutterActor *key_focused_actor;
ClutterGrab *topmost_grab;
ClutterGrabState grab_state;
GQueue *event_queue;
GPtrArray *cur_event_actors;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
GArray *cur_event_emission_chain;
GSList *pending_relayouts;
int update_freeze_count;
gboolean update_scheduled;
GHashTable *pointer_devices;
GHashTable *touch_sequences;
clutter: Add private API to support resource scale affecting layout For ClutterText, the resource scale the text is drawn with affects the size of the allocation: ClutterText will choose a font scale based on the resource scale, and that font scale can lead to a slight difference in size compared to the unscaled font. We currently handle that by queuing a relayout inside the "resource-scale-changed" signal handler. This solution is a bit problematic though since it will take one more allocation cycle until the allocation is actually updated after a scale-change, so the actor is painted using the wrong allocation for one frame. Also the current solution can lead to relayout loops in a few cases, for example if a ClutterText is located near the edge on a 1x scaled monitor and is moved to intersect a 2x scaled monitor: Now the resource scale will change to 2 and a new allocation box is calculated; if this allocation box is slightly smaller than the old one because of the new font scale, the allocation won't intersect the 2x scaled monitor again and the resource scale switches back to 1. Now the allocation gets larger again and intersects the 2x scaled monitor again. This commit introduces a way to properly support those actors: In case an actors resource scale might affect its allocation, it should call the private function clutter_actor_queue_immediate_relayout(). This will make sure the actor gets a relayout before the upcoming paint happens afte every resource scale change. Also potential relayout loops can be handled by the actors themselves using a "phase" argument that's passed to implementations of the calculate_resource_scale() vfunc. The new API is private because resource scales are not meant to be used in a way where the scale affects the allocation. With ClutterText and the current behavior of Pango, that can't be avoid though, so we need it anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
2020-04-10 14:54:11 +02:00
guint actor_needs_immediate_relayout : 1;
} ClutterStagePrivate;
2006-05-29 08:59:36 +00:00
enum
{
PROP_0,
PROP_PERSPECTIVE,
PROP_TITLE,
PROP_KEY_FOCUS,
PROP_IS_GRABBED,
PROP_LAST
2006-05-29 08:59:36 +00:00
};
static GParamSpec *obj_props[PROP_LAST] = { NULL, };
2006-05-29 08:59:36 +00:00
enum
{
ACTIVATE,
DEACTIVATE,
DELETE_EVENT,
BEFORE_UPDATE,
PREPARE_FRAME,
BEFORE_PAINT,
AFTER_PAINT,
AFTER_UPDATE,
PAINT_VIEW,
PRESENTED,
GL_VIDEO_MEMORY_PURGED,
2006-05-29 08:59:36 +00:00
LAST_SIGNAL
};
static guint stage_signals[LAST_SIGNAL] = { 0, };
2006-06-05 Emmanuele Bassi <ebassi@openedhand.com> * clutter-color.h: * clutter-color.c: Reimplement ClutterColor as a boxed type; add convenience API for color handling, like: add, subtract, shade, HSL color-space conversion, packing and unpacking. * clutter-private.h: Update ClutterMainContext, and export the main context pointer here. * clutter-rectangle.h: * clutter-rectangle.c: Update the color-related code; make clutter_rectangle_new() and empty constructor and provide clutter_rectangle_new_with_color(); provide color setter and getter API. * clutter-label.h: * clutter-label.c: Rename the "font" property to "font-name"; update the color-related code to the new ClutterColor object; rename clutter_label_new() to clutter_label_new_with_text(), and add setters and getters for the properties. * clutter-marshal.list: Add VOID:OBJECT and VOID:BOXED marshallers generators. * clutter-stage.h: * clutter-stage.c: Rework the API: provide a default constructor for a singleton object, named clutter_stage_get_default(), which supercedes the clutter_stage() function in clutter-main; provide new events: button-press-event, button-release-event, key-press-event and key-release-event; update the color-related code; (clutter_stage_snapshot): Allow negative width and height when taking a snapshot (meaning: use full width/height). (clutter_stage_get_element_at_pos): Rename clutter_stage_pick(). * clutter-element.c (clutter_element_paint): Clean up the stage and color related code. * clutter-event.h: * clutter-event.c: Add generic ClutterAnyEvent type; add clutter_event_new(), clutter_event_copy() and clutter_event_free(); make ClutterEvent a boxed type. * clutter-main.h: * clutter-main.c: Remove clutter_stage(); add clutter_main_quit(), for cleanly quitting from clutter_main(); add multiple mainloops support; allocate the ClutterCntx instead of adding it to the stack; re-work the ClutterEvent dispatching. * clutter-group.c (clutter_group_add), (clutter_group_remove): Keep a reference on the element when added to a ClutterGroup. * examples/rects.py * examples/test.c: * examples/test-text.c: * examples/video-cube.c: * examples/super-oh.c: * examples/test-video.c: Update.
2006-06-05 13:38:31 +00:00
static const ClutterColor default_stage_color = { 255, 255, 255, 255 };
static void free_pointer_device_entry (PointerDeviceEntry *entry);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
static void free_event_receiver (EventReceiver *receiver);
static void clutter_stage_update_view_perspective (ClutterStage *stage);
static void clutter_stage_set_viewport (ClutterStage *stage,
float width,
float height);
actor: defer queue-redraw signaling Instead of immediately, recursively emitting the "queue-redraw" signal when clutter_actor_queue_redraw is called we now defer this process until all stage updates are complete. This allows us to aggregate repeated _queue_redraw requests for the same actor avoiding redundant paint volume transformations. By deferring we also increase the likelihood that the actor will have a valid paint volume since it will have an up to date allocation; this in turn means we will more often be able to automatically queue clipped redraws which can have a big impact on performance. Here's an outline of the actor queue redraw mechanism: The process starts in clutter_actor_queue_redraw or _clutter_actor_queue_redraw_with_clip. These functions queue an entry in a list associated with the stage which is a list of actors that queued a redraw while updating the timelines, performing layouting and processing other mainloop sources before the next paint starts. We aim to minimize the processing done at this point because there is a good chance other events will happen while updating the scenegraph that would invalidate any expensive work we might otherwise try to do here. For example we don't try and resolve the screen space bounding box of an actor at this stage so as to minimize how much of the screen redraw because it's possible something else will happen which will force a full redraw anyway. When all updates are complete and we come to paint the stage (see _clutter_stage_do_update) then we iterate this list and actually emit the "queue-redraw" signals for each of the listed actors which will bubble up to the stage for each actor and at that point we will transform the actors paint volume into screen coordinates to determine the clip region for what needs to be redrawn in the next paint. Note: actors are allowed to queue a redraw in reseponse to a queue-redraw signal so we repeat the processing of the list until it remains empty. An example of when this happens is for Clone actors or clutter_texture_new_from_actor actors which need to queue a redraw if their source queues a redraw.
2010-09-10 01:33:02 +01:00
G_DEFINE_TYPE_WITH_PRIVATE (ClutterStage, clutter_stage, CLUTTER_TYPE_ACTOR)
actor: defer queue-redraw signaling Instead of immediately, recursively emitting the "queue-redraw" signal when clutter_actor_queue_redraw is called we now defer this process until all stage updates are complete. This allows us to aggregate repeated _queue_redraw requests for the same actor avoiding redundant paint volume transformations. By deferring we also increase the likelihood that the actor will have a valid paint volume since it will have an up to date allocation; this in turn means we will more often be able to automatically queue clipped redraws which can have a big impact on performance. Here's an outline of the actor queue redraw mechanism: The process starts in clutter_actor_queue_redraw or _clutter_actor_queue_redraw_with_clip. These functions queue an entry in a list associated with the stage which is a list of actors that queued a redraw while updating the timelines, performing layouting and processing other mainloop sources before the next paint starts. We aim to minimize the processing done at this point because there is a good chance other events will happen while updating the scenegraph that would invalidate any expensive work we might otherwise try to do here. For example we don't try and resolve the screen space bounding box of an actor at this stage so as to minimize how much of the screen redraw because it's possible something else will happen which will force a full redraw anyway. When all updates are complete and we come to paint the stage (see _clutter_stage_do_update) then we iterate this list and actually emit the "queue-redraw" signals for each of the listed actors which will bubble up to the stage for each actor and at that point we will transform the actors paint volume into screen coordinates to determine the clip region for what needs to be redrawn in the next paint. Note: actors are allowed to queue a redraw in reseponse to a queue-redraw signal so we repeat the processing of the list until it remains empty. An example of when this happens is for Clone actors or clutter_texture_new_from_actor actors which need to queue a redraw if their source queues a redraw.
2010-09-10 01:33:02 +01:00
static void
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
clutter_stage_get_preferred_width (ClutterActor *self,
Remove Units from the public API With the recent change to internal floating point values, ClutterUnit has become a redundant type, defined to be a float. All integer entry points are being internally converted to floating point values to be passed to the GL pipeline with the least amount of conversion. ClutterUnit is thus exposed as just a "pixel with fractionary bits", and not -- as users might think -- as generic, resolution and device independent units. not that it was the case, but a definitive amount of people was convinced it did provide this "feature", and was flummoxed about the mere existence of this type. So, having ClutterUnit exposed in the public API doubles the entry points and has the following disadvantages: - we have to maintain twice the amount of entry points in ClutterActor - we still do an integer-to-float implicit conversion - we introduce a weird impedance between pixels and "pixels with fractionary bits" - language bindings will have to choose what to bind, and resort to manually overriding the API + *except* for language bindings based on GObject-Introspection, as they cannot do manual overrides, thus will replicate the entire set of entry points For these reason, we should coalesces every Actor entry point for pixels and for ClutterUnit into a single entry point taking a float, like: void clutter_actor_set_x (ClutterActor *self, gfloat x); void clutter_actor_get_size (ClutterActor *self, gfloat *width, gfloat *height); gfloat clutter_actor_get_height (ClutterActor *self); etc. The issues I have identified are: - we'll have a two cases of compiler warnings: - printf() format of the return values from %d to %f - clutter_actor_get_size() taking floats instead of unsigned ints - we'll have a problem with varargs when passing an integer instead of a floating point value, except on 64bit platforms where the size of a float is the same as the size of an int To be clear: the *intent* of the API should not change -- we still use pixels everywhere -- but: - we remove ambiguity in the API with regard to pixels and units - we remove entry points we get to maintain for the whole 1.0 version of the API - we make things simpler to bind for both manual language bindings and automatic (gobject-introspection based) ones - we have the simplest API possible while still exposing the capabilities of the underlying GL implementation
2009-05-06 16:44:47 +01:00
gfloat for_height,
gfloat *min_width_p,
gfloat *natural_width_p)
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (self));
MtkRectangle geom;
if (priv->impl == NULL)
return;
_clutter_stage_window_get_geometry (priv->impl, &geom);
if (min_width_p)
*min_width_p = geom.width;
if (natural_width_p)
*natural_width_p = geom.width;
}
static void
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
clutter_stage_get_preferred_height (ClutterActor *self,
Remove Units from the public API With the recent change to internal floating point values, ClutterUnit has become a redundant type, defined to be a float. All integer entry points are being internally converted to floating point values to be passed to the GL pipeline with the least amount of conversion. ClutterUnit is thus exposed as just a "pixel with fractionary bits", and not -- as users might think -- as generic, resolution and device independent units. not that it was the case, but a definitive amount of people was convinced it did provide this "feature", and was flummoxed about the mere existence of this type. So, having ClutterUnit exposed in the public API doubles the entry points and has the following disadvantages: - we have to maintain twice the amount of entry points in ClutterActor - we still do an integer-to-float implicit conversion - we introduce a weird impedance between pixels and "pixels with fractionary bits" - language bindings will have to choose what to bind, and resort to manually overriding the API + *except* for language bindings based on GObject-Introspection, as they cannot do manual overrides, thus will replicate the entire set of entry points For these reason, we should coalesces every Actor entry point for pixels and for ClutterUnit into a single entry point taking a float, like: void clutter_actor_set_x (ClutterActor *self, gfloat x); void clutter_actor_get_size (ClutterActor *self, gfloat *width, gfloat *height); gfloat clutter_actor_get_height (ClutterActor *self); etc. The issues I have identified are: - we'll have a two cases of compiler warnings: - printf() format of the return values from %d to %f - clutter_actor_get_size() taking floats instead of unsigned ints - we'll have a problem with varargs when passing an integer instead of a floating point value, except on 64bit platforms where the size of a float is the same as the size of an int To be clear: the *intent* of the API should not change -- we still use pixels everywhere -- but: - we remove ambiguity in the API with regard to pixels and units - we remove entry points we get to maintain for the whole 1.0 version of the API - we make things simpler to bind for both manual language bindings and automatic (gobject-introspection based) ones - we have the simplest API possible while still exposing the capabilities of the underlying GL implementation
2009-05-06 16:44:47 +01:00
gfloat for_width,
gfloat *min_height_p,
gfloat *natural_height_p)
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (self));
MtkRectangle geom;
if (priv->impl == NULL)
return;
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
_clutter_stage_window_get_geometry (priv->impl, &geom);
if (min_height_p)
*min_height_p = geom.height;
if (natural_height_p)
*natural_height_p = geom.height;
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
}
static void
clutter_stage_add_redraw_clip (ClutterStage *stage,
MtkRectangle *clip)
{
GList *l;
for (l = clutter_stage_peek_stage_views (stage); l; l = l->next)
{
ClutterStageView *view = l->data;
if (!clip)
{
clutter_stage_view_add_redraw_clip (view, NULL);
}
else
{
MtkRectangle view_layout;
MtkRectangle intersection;
clutter_stage_view_get_layout (view, &view_layout);
if (mtk_rectangle_intersect (&view_layout, clip,
&intersection))
clutter_stage_view_add_redraw_clip (view, &intersection);
}
}
}
static inline void
queue_full_redraw (ClutterStage *stage)
{
ClutterStageWindow *stage_window;
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return;
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
/* Just calling clutter_actor_queue_redraw will typically only
* redraw the bounding box of the children parented on the stage but
* in this case we really need to ensure that the full stage is
* redrawn so we add a NULL redraw clip to the stage window. */
stage_window = _clutter_stage_get_window (stage);
if (stage_window == NULL)
return;
clutter_stage_add_redraw_clip (stage, NULL);
}
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
static void
clutter_stage_allocate (ClutterActor *self,
const ClutterActorBox *box)
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (self));
ClutterActorBox alloc = CLUTTER_ACTOR_BOX_INIT_ZERO;
float new_width, new_height;
float width, height;
MtkRectangle window_size;
ClutterActorBox children_box;
ClutterLayoutManager *layout_manager = clutter_actor_get_layout_manager (self);
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
if (priv->impl == NULL)
return;
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
/* the current allocation */
clutter_actor_box_get_size (box, &width, &height);
/* the current Stage implementation size */
_clutter_stage_window_get_geometry (priv->impl, &window_size);
children_box.x1 = children_box.y1 = 0.f;
children_box.x2 = box->x2 - box->x1;
children_box.y2 = box->y2 - box->y1;
CLUTTER_NOTE (LAYOUT,
"Following allocation to %.2fx%.2f",
width, height);
clutter_actor_set_allocation (self, box);
clutter_layout_manager_allocate (layout_manager,
self,
&children_box);
if (window_size.width != CLUTTER_NEARBYINT (width) ||
window_size.height != CLUTTER_NEARBYINT (height))
{
_clutter_stage_window_resize (priv->impl,
CLUTTER_NEARBYINT (width),
CLUTTER_NEARBYINT (height));
}
/* set the viewport to the new allocation */
clutter_actor_get_allocation_box (self, &alloc);
clutter_actor_box_get_size (&alloc, &new_width, &new_height);
clutter_stage_set_viewport (CLUTTER_STAGE (self), new_width, new_height);
}
static void
setup_clip_frustum (ClutterStage *stage,
const MtkRectangle *clip,
graphene_frustum_t *frustum)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
MtkRectangle geom;
graphene_point3d_t camera_position;
graphene_point3d_t p[4];
graphene_plane_t planes[6];
graphene_vec4_t v;
int i;
_clutter_stage_window_get_geometry (priv->impl, &geom);
CLUTTER_NOTE (CLIPPING, "Creating stage clip frustum for "
"x=%d, y=%d, width=%d, height=%d",
clip->x, clip->y, clip->width, clip->height);
camera_position = GRAPHENE_POINT3D_INIT_ZERO;
p[0] = GRAPHENE_POINT3D_INIT (MAX (clip->x, 0), MAX (clip->y, 0), 0.f);
p[2] = GRAPHENE_POINT3D_INIT (MIN (clip->x + clip->width, geom.width),
MIN (clip->y + clip->height, geom.height),
0.f);
for (i = 0; i < 2; i++)
{
float w = 1.0;
cogl_graphene_matrix_project_point (&priv->view,
&p[2 * i].x,
&p[2 * i].y,
&p[2 * i].z,
&w);
}
graphene_point3d_init (&p[1], p[2].x, p[0].y, p[0].z);
graphene_point3d_init (&p[3], p[0].x, p[2].y, p[0].z);
for (i = 0; i < 4; i++)
{
graphene_plane_init_from_points (&planes[i],
&camera_position,
&p[i],
&p[(i + 1) % 4]);
}
graphene_vec4_init (&v, 0.f, 0.f, -1.f, priv->perspective.z_near);
graphene_plane_init_from_vec4 (&planes[4], &v);
graphene_vec4_init (&v, 0.f, 0.f, 1.f, priv->perspective.z_far);
graphene_plane_init_from_vec4 (&planes[5], &v);
graphene_frustum_init (frustum,
&planes[0], &planes[1],
&planes[2], &planes[3],
&planes[4], &planes[5]);
}
static void
clutter_stage_do_paint_view (ClutterStage *stage,
ClutterStageView *view,
ClutterFrame *frame,
const MtkRegion *redraw_clip)
{
ClutterPaintContext *paint_context;
MtkRectangle clip_rect;
g_autoptr (GArray) clip_frusta = NULL;
graphene_frustum_t clip_frustum;
ClutterPaintNode *root_node;
CoglFramebuffer *fb;
ClutterColor bg_color;
int n_rectangles;
ClutterPaintFlag paint_flags;
n_rectangles = redraw_clip ? mtk_region_num_rectangles (redraw_clip) : 0;
if (redraw_clip && n_rectangles < MAX_FRUSTA)
{
int i;
clip_frusta = g_array_sized_new (FALSE, FALSE,
sizeof (graphene_frustum_t),
n_rectangles);
for (i = 0; i < n_rectangles; i++)
{
clip_rect = mtk_region_get_rectangle (redraw_clip, i);
setup_clip_frustum (stage, &clip_rect, &clip_frustum);
g_array_append_val (clip_frusta, clip_frustum);
}
}
else
{
clip_frusta = g_array_sized_new (FALSE, FALSE,
sizeof (graphene_frustum_t),
1);
if (redraw_clip)
clip_rect = mtk_region_get_extents (redraw_clip);
else
clutter_stage_view_get_layout (view, &clip_rect);
setup_clip_frustum (stage, &clip_rect, &clip_frustum);
g_array_append_val (clip_frusta, clip_frustum);
}
paint_flags = clutter_stage_view_get_default_paint_flags (view);
paint_context = clutter_paint_context_new_for_view (view,
redraw_clip,
clip_frusta,
paint_flags);
if (frame)
clutter_paint_context_assign_frame (paint_context, frame);
clutter_actor_get_background_color (CLUTTER_ACTOR (stage), &bg_color);
bg_color.alpha = 255;
fb = clutter_stage_view_get_framebuffer (view);
root_node = clutter_root_node_new (fb, &bg_color, COGL_BUFFER_BIT_DEPTH);
clutter_paint_node_set_static_name (root_node, "Stage (root)");
clutter_paint_node_paint (root_node, paint_context);
clutter_paint_node_unref (root_node);
clutter_actor_paint (CLUTTER_ACTOR (stage), paint_context);
clutter_paint_context_destroy (paint_context);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
}
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
/* This provides a common point of entry for painting the scenegraph
* for picking or painting...
*/
void
clutter_stage_paint_view (ClutterStage *stage,
ClutterStageView *view,
const MtkRegion *redraw_clip,
ClutterFrame *frame)
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
if (!priv->impl)
return;
COGL_TRACE_BEGIN_SCOPED (ClutterStagePaintView, "Clutter::Stage::paint_view()");
if (g_signal_has_handler_pending (stage, stage_signals[PAINT_VIEW],
0, TRUE))
g_signal_emit (stage, stage_signals[PAINT_VIEW], 0, view, redraw_clip, frame);
else
CLUTTER_STAGE_GET_CLASS (stage)->paint_view (stage, view, redraw_clip, frame);
}
void
clutter_stage_emit_before_update (ClutterStage *stage,
ClutterStageView *view,
ClutterFrame *frame)
{
g_signal_emit (stage, stage_signals[BEFORE_UPDATE], 0, view, frame);
}
void
clutter_stage_emit_prepare_frame (ClutterStage *stage,
ClutterStageView *view,
ClutterFrame *frame)
{
g_signal_emit (stage, stage_signals[PREPARE_FRAME], 0, view, frame);
}
void
clutter_stage_emit_before_paint (ClutterStage *stage,
ClutterStageView *view,
ClutterFrame *frame)
{
g_signal_emit (stage, stage_signals[BEFORE_PAINT], 0, view, frame);
}
void
clutter_stage_emit_after_paint (ClutterStage *stage,
ClutterStageView *view,
ClutterFrame *frame)
{
g_signal_emit (stage, stage_signals[AFTER_PAINT], 0, view, frame);
paint volumes: another pass at the design This is a fairly extensive second pass at exposing paint volumes for actors. The API has changed to allow clutter_actor_get_paint_volume to fail since there are times - such as when an actor isn't a descendent of the stage - when the volume can't be determined. Another example is when something has connected to the "paint" signal of the actor and we simply have no way of knowing what might be drawn in that handler. The API has also be changed to return a const ClutterPaintVolume pointer (transfer none) so we can avoid having to dynamically allocate the volumes in the most common/performance critical code paths. Profiling was showing the slice allocation of volumes taking about 1% of an apps time, for some fairly basic tests. Most volumes can now simply be allocated on the stack; for clutter_actor_get_paint_volume we return a pointer to &priv->paint_volume and if we need a more dynamic allocation there is now a _clutter_stage_paint_volume_stack_allocate() mechanism which lets us allocate data which expires at the start of the next frame. The API has been extended to make it easier to implement get_paint_volume for containers by using clutter_actor_get_transformed_paint_volume and clutter_paint_volume_union. The first allows you to query the paint volume of a child but transformed into parent actor coordinates. The second lets you combine volumes together so you can union all the volumes for a container's children and report that as the container's own volume. The representation of paint volumes has been updated to consider that 2D actors are the most common. The effect apis, clutter-texture and clutter-group have been update accordingly.
2010-09-07 18:04:19 +01:00
}
void
clutter_stage_after_update (ClutterStage *stage,
ClutterStageView *view,
ClutterFrame *frame)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
g_signal_emit (stage, stage_signals[AFTER_UPDATE], 0, view, frame);
priv->update_scheduled = FALSE;
}
static gboolean
clutter_stage_get_paint_volume (ClutterActor *self,
ClutterPaintVolume *volume)
{
/* Returning False effectively means Clutter has to assume it covers
* everything... */
return FALSE;
}
static void
clutter_stage_realize (ClutterActor *self)
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (self));
gboolean is_realized;
g_assert (priv->impl != NULL);
is_realized = _clutter_stage_window_realize (priv->impl);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
if (!is_realized)
self->flags &= ~CLUTTER_ACTOR_REALIZED;
}
static void
clutter_stage_unrealize (ClutterActor *self)
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (self));
/* and then unrealize the implementation */
g_assert (priv->impl != NULL);
_clutter_stage_window_unrealize (priv->impl);
self->flags &= ~CLUTTER_ACTOR_REALIZED;
}
static void
clutter_stage_show (ClutterActor *self)
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (self));
CLUTTER_ACTOR_CLASS (clutter_stage_parent_class)->show (self);
/* Possibly do an allocation run so that the stage will have the
right size before we map it */
clutter_stage_maybe_relayout (self);
g_assert (priv->impl != NULL);
_clutter_stage_window_show (priv->impl, TRUE);
}
static void
clutter_stage_hide_all (ClutterActor *self)
{
ClutterActorIter iter;
ClutterActor *child;
clutter_actor_hide (self);
/* we don't do a recursive hide_all(), to maintain the old invariants
* from ClutterGroup
*/
clutter_actor_iter_init (&iter, self);
while (clutter_actor_iter_next (&iter, &child))
clutter_actor_hide (child);
}
static void
clutter_stage_hide (ClutterActor *self)
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (self));
g_assert (priv->impl != NULL);
_clutter_stage_window_hide (priv->impl);
CLUTTER_ACTOR_CLASS (clutter_stage_parent_class)->hide (self);
}
static void
clutter_stage_emit_key_focus_event (ClutterStage *stage,
gboolean focus_in)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
if (priv->key_focused_actor == NULL)
return;
_clutter_actor_set_has_key_focus (CLUTTER_ACTOR (stage), focus_in);
g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_KEY_FOCUS]);
}
static void
clutter_stage_real_activate (ClutterStage *stage)
{
clutter_stage_emit_key_focus_event (stage, TRUE);
}
static void
clutter_stage_real_deactivate (ClutterStage *stage)
{
clutter_stage_emit_key_focus_event (stage, FALSE);
}
void
_clutter_stage_queue_event (ClutterStage *stage,
ClutterEvent *event,
gboolean copy_event)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = clutter_stage_get_instance_private (stage);
g_queue_push_tail (priv->event_queue,
copy_event ? clutter_event_copy (event) : event);
clutter_stage_schedule_update (stage);
}
static ClutterEvent *
clutter_stage_compress_motion (ClutterStage *stage,
ClutterEvent *event,
const ClutterEvent *to_discard)
{
double dx, dy;
double dx_unaccel, dy_unaccel;
double dx_constrained, dy_constrained;
double dst_dx = 0.0, dst_dy = 0.0;
double dst_dx_unaccel = 0.0, dst_dy_unaccel = 0.0;
double dst_dx_constrained = 0.0, dst_dy_constrained = 0.0;
graphene_point_t coords;
if (!clutter_event_get_relative_motion (to_discard,
&dx, &dy,
&dx_unaccel, &dy_unaccel,
&dx_constrained, &dy_constrained))
return NULL;
clutter_event_get_relative_motion (event,
&dst_dx, &dst_dy,
&dst_dx_unaccel, &dst_dy_unaccel,
&dst_dx_constrained, &dst_dy_constrained);
clutter_event_get_position (event, &coords);
return clutter_event_motion_new (CLUTTER_EVENT_FLAG_RELATIVE_MOTION,
clutter_event_get_time_us (event),
clutter_event_get_source_device (event),
clutter_event_get_device_tool (event),
clutter_event_get_state (event),
coords,
GRAPHENE_POINT_INIT (dx + dst_dx, dy + dst_dy),
GRAPHENE_POINT_INIT (dx_unaccel + dst_dx_unaccel,
dy_unaccel + dst_dy_unaccel),
GRAPHENE_POINT_INIT (dx_constrained + dst_dx_constrained,
dy_constrained + dst_dy_constrained),
NULL);
}
CLUTTER_EXPORT void
_clutter_stage_process_queued_events (ClutterStage *stage)
{
ClutterStagePrivate *priv;
GList *events, *l;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
COGL_TRACE_BEGIN_SCOPED (ProcessQueuedEvents, "Clutter::Stage::process_queued_events()");
priv = clutter_stage_get_instance_private (stage);
if (priv->event_queue->length == 0)
return;
/* In case the stage gets destroyed during event processing */
g_object_ref (stage);
/* Steal events before starting processing to avoid reentrancy
* issues */
events = priv->event_queue->head;
priv->event_queue->head = NULL;
priv->event_queue->tail = NULL;
priv->event_queue->length = 0;
for (l = events; l != NULL; l = l->next)
{
ClutterEvent *event;
ClutterEvent *next_event;
ClutterInputDevice *device;
ClutterInputDevice *next_device;
gboolean check_device = FALSE;
event = l->data;
next_event = l->next ? l->next->data : NULL;
COGL_TRACE_BEGIN_SCOPED (ProcessEvent,
"Clutter::Stage::process_queued_events#event()");
COGL_TRACE_DESCRIBE (ProcessEvent, clutter_event_get_name (event));
device = clutter_event_get_device (event);
if (next_event != NULL)
next_device = clutter_event_get_device (next_event);
else
next_device = NULL;
if (device != NULL && next_device != NULL)
check_device = TRUE;
/* Skip consecutive motion events coming from the same device. */
if (next_event != NULL)
{
float x, y;
clutter_event_get_coords (event, &x, &y);
if (clutter_event_type (event) == CLUTTER_MOTION &&
(clutter_event_type (next_event) == CLUTTER_MOTION ||
clutter_event_type (next_event) == CLUTTER_LEAVE) &&
(!check_device || (device == next_device)))
{
CLUTTER_NOTE (EVENT,
"Omitting motion event at %d, %d",
(int) x,
(int) y);
if (clutter_event_type (next_event) == CLUTTER_MOTION)
{
ClutterEvent *new_event;
new_event =
clutter_stage_compress_motion (stage, next_event, event);
if (new_event)
{
/* Replace the next event with the rewritten one */
l->next->data = new_event;
clutter_event_free (next_event);
}
}
goto next_event;
}
else if (clutter_event_type (event) == CLUTTER_TOUCH_UPDATE &&
clutter_event_type (next_event) == CLUTTER_TOUCH_UPDATE &&
clutter_event_get_event_sequence (event) ==
clutter_event_get_event_sequence (next_event) &&
(!check_device || (device == next_device)))
{
CLUTTER_NOTE (EVENT,
"Omitting touch update event at %d, %d",
(int) x,
(int) y);
goto next_event;
}
}
clutter_stage_process_event (stage, event);
next_event:
clutter_event_free (event);
}
g_list_free (events);
g_object_unref (stage);
}
void
clutter_stage_queue_actor_relayout (ClutterStage *stage,
ClutterActor *actor)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
clutter_stage_schedule_update (stage);
priv->pending_relayouts = g_slist_prepend (priv->pending_relayouts,
g_object_ref (actor));
}
clutter/actor: Remove actors from shallow relayout list when unrealizing With the introduction of the shallow relayout mechanism another small but severe regression sneaked into our layout machinery: We might allocate an actor twice during the same allocation cycle, with one allocation happening using the wrong parent. This issue happens when reparenting an actor from a NO_LAYOUT parent to a non-NO_LAYOUT parent, in particular it triggered a bug in gnome-shell when DND reparents a child from the NO_LAYOUT uiGroup to the overviews Workspace actor after a drag ended. The reason the issue happens is the following chain of events: 1. child of a NO_LAYOUT parent queues a relayout, this child is added to the priv->pending_relayouts list maintained by ClutterStage 2. child is reparented to a different parent which doesn't have the NO_LAYOUT flag set, another relayout is queued, this time a different actor is added to the priv->pending_relayouts list 3. the relayout happens and we go through the pending_relayouts list backwards, that means the correct relayout queued during 2. happens first, then the old one happens and we simply call clutter_actor_allocate_preferred_size() on the actor, that allocation overrides the other, correct one. So fix that issue by adding a method to ClutterStage which removes actors from the pending_relayouts list again and call this method as soon as an actor with a NO_LAYOUT parent is detached from the stage. With that in place, we can also remove the check whether an actor is still on stage while looping through pending_relayouts. In case something else is going wrong and the actor is not on stage, clutter_actor_allocate() will warn anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1356
2020-07-06 15:35:14 +02:00
void
clutter_stage_dequeue_actor_relayout (ClutterStage *stage,
ClutterActor *actor)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
clutter/actor: Remove actors from shallow relayout list when unrealizing With the introduction of the shallow relayout mechanism another small but severe regression sneaked into our layout machinery: We might allocate an actor twice during the same allocation cycle, with one allocation happening using the wrong parent. This issue happens when reparenting an actor from a NO_LAYOUT parent to a non-NO_LAYOUT parent, in particular it triggered a bug in gnome-shell when DND reparents a child from the NO_LAYOUT uiGroup to the overviews Workspace actor after a drag ended. The reason the issue happens is the following chain of events: 1. child of a NO_LAYOUT parent queues a relayout, this child is added to the priv->pending_relayouts list maintained by ClutterStage 2. child is reparented to a different parent which doesn't have the NO_LAYOUT flag set, another relayout is queued, this time a different actor is added to the priv->pending_relayouts list 3. the relayout happens and we go through the pending_relayouts list backwards, that means the correct relayout queued during 2. happens first, then the old one happens and we simply call clutter_actor_allocate_preferred_size() on the actor, that allocation overrides the other, correct one. So fix that issue by adding a method to ClutterStage which removes actors from the pending_relayouts list again and call this method as soon as an actor with a NO_LAYOUT parent is detached from the stage. With that in place, we can also remove the check whether an actor is still on stage while looping through pending_relayouts. In case something else is going wrong and the actor is not on stage, clutter_actor_allocate() will warn anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1356
2020-07-06 15:35:14 +02:00
GSList *l;
for (l = priv->pending_relayouts; l; l = l->next)
{
ClutterActor *relayout_actor = l->data;
if (relayout_actor == actor)
{
g_object_unref (relayout_actor);
priv->pending_relayouts =
g_slist_delete_link (priv->pending_relayouts, l);
return;
}
}
}
void
clutter_stage_invalidate_devices (ClutterStage *stage)
{
GList *l;
for (l = clutter_stage_peek_stage_views (stage); l; l = l->next)
{
ClutterStageView *view = l->data;
clutter_stage_view_invalidate_input_devices (view);
}
}
void
clutter_stage_maybe_relayout (ClutterActor *actor)
{
ClutterStage *stage = CLUTTER_STAGE (actor);
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
g_autoptr (GSList) stolen_list = NULL;
GSList *l;
int count = 0;
/* No work to do? Avoid the extraneous debug log messages too. */
if (priv->pending_relayouts == NULL)
return;
COGL_TRACE_BEGIN_SCOPED (ClutterStageRelayout, "Clutter::Stage::maybe_relayout()");
CLUTTER_NOTE (ACTOR, ">>> Recomputing layout");
stolen_list = g_steal_pointer (&priv->pending_relayouts);
for (l = stolen_list; l; l = l->next)
{
g_autoptr (ClutterActor) queued_actor = l->data;
float x = 0.f;
float y = 0.f;
if (CLUTTER_ACTOR_IN_RELAYOUT (queued_actor)) /* avoid reentrancy */
continue;
if (queued_actor == actor)
CLUTTER_NOTE (ACTOR, " Deep relayout of stage %s",
_clutter_actor_get_debug_name (queued_actor));
else
CLUTTER_NOTE (ACTOR, " Shallow relayout of actor %s",
_clutter_actor_get_debug_name (queued_actor));
CLUTTER_SET_PRIVATE_FLAGS (queued_actor, CLUTTER_IN_RELAYOUT);
clutter_actor_get_fixed_position (queued_actor, &x, &y);
clutter_actor_allocate_preferred_size (queued_actor, x, y);
CLUTTER_UNSET_PRIVATE_FLAGS (queued_actor, CLUTTER_IN_RELAYOUT);
count++;
}
CLUTTER_NOTE (ACTOR, "<<< Completed recomputing layout of %d subtrees", count);
if (count)
clutter_stage_invalidate_devices (stage);
}
GSList *
clutter_stage_find_updated_devices (ClutterStage *stage,
ClutterStageView *view)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
GSList *updating = NULL;
GHashTableIter iter;
gpointer value;
g_hash_table_iter_init (&iter, priv->pointer_devices);
while (g_hash_table_iter_next (&iter, NULL, &value))
{
PointerDeviceEntry *entry = value;
ClutterStageView *pointer_view;
pointer_view = clutter_stage_get_view_at (stage,
entry->coords.x,
entry->coords.y);
if (!pointer_view)
continue;
if (pointer_view != view)
continue;
updating = g_slist_prepend (updating, entry->device);
}
return updating;
}
void
clutter_stage_finish_layout (ClutterStage *stage)
clutter/actor: Add API to get the stage-views an actor is painted on There are certain rendering techniques and optimizations, for example the unredirection of non-fullscreen windows, where information about the output/stage-view an actor is on is needed to determine whether the optimization can be enabled. So add a new method to ClutterActor that allows listing the stage-views the actor is being painted on: clutter_actor_peek_stage_views() With the way Clutter works, the only point where we can reliably get this information is during or right before the paint phase, when the layout phase of the stage has been completed and no more changes to the actors transformation matrices happen. So to get the stage views the actor is on, introduce a new step that's done on every master clock tick between layout and paint cycle: Traversing through the actor tree and updating the stage-views the mapped actors are going to be painted on. We're doing this in a separate step instead of inside clutter_actor_paint() itself for a few reasons: It keeps the code separate from the painting code, making profiling easier and issues easier to track down (hopefully), it allows for a new "stage-views-changed" signal that doesn't interfere with painting, and finally, it will make it very easy to update the resource scales in the same step in the future. Currently, this list is only invalidated on allocation changes of actors, but not on changes to the transformation matrices. That's because there's no proper API to invalidate the transformation matrices ClutterActor implementations can apply through the apply_transform() vfunc. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1196
2020-04-10 00:34:49 +02:00
{
ClutterActor *actor = CLUTTER_ACTOR (stage);
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
clutter: Add private API to support resource scale affecting layout For ClutterText, the resource scale the text is drawn with affects the size of the allocation: ClutterText will choose a font scale based on the resource scale, and that font scale can lead to a slight difference in size compared to the unscaled font. We currently handle that by queuing a relayout inside the "resource-scale-changed" signal handler. This solution is a bit problematic though since it will take one more allocation cycle until the allocation is actually updated after a scale-change, so the actor is painted using the wrong allocation for one frame. Also the current solution can lead to relayout loops in a few cases, for example if a ClutterText is located near the edge on a 1x scaled monitor and is moved to intersect a 2x scaled monitor: Now the resource scale will change to 2 and a new allocation box is calculated; if this allocation box is slightly smaller than the old one because of the new font scale, the allocation won't intersect the 2x scaled monitor again and the resource scale switches back to 1. Now the allocation gets larger again and intersects the 2x scaled monitor again. This commit introduces a way to properly support those actors: In case an actors resource scale might affect its allocation, it should call the private function clutter_actor_queue_immediate_relayout(). This will make sure the actor gets a relayout before the upcoming paint happens afte every resource scale change. Also potential relayout loops can be handled by the actors themselves using a "phase" argument that's passed to implementations of the calculate_resource_scale() vfunc. The new API is private because resource scales are not meant to be used in a way where the scale affects the allocation. With ClutterText and the current behavior of Pango, that can't be avoid though, so we need it anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
2020-04-10 14:54:11 +02:00
int phase;
COGL_TRACE_BEGIN_SCOPED (ClutterStageUpdateActorStageViews,
"Clutter::Stage::finish_layout()");
clutter: Add private API to support resource scale affecting layout For ClutterText, the resource scale the text is drawn with affects the size of the allocation: ClutterText will choose a font scale based on the resource scale, and that font scale can lead to a slight difference in size compared to the unscaled font. We currently handle that by queuing a relayout inside the "resource-scale-changed" signal handler. This solution is a bit problematic though since it will take one more allocation cycle until the allocation is actually updated after a scale-change, so the actor is painted using the wrong allocation for one frame. Also the current solution can lead to relayout loops in a few cases, for example if a ClutterText is located near the edge on a 1x scaled monitor and is moved to intersect a 2x scaled monitor: Now the resource scale will change to 2 and a new allocation box is calculated; if this allocation box is slightly smaller than the old one because of the new font scale, the allocation won't intersect the 2x scaled monitor again and the resource scale switches back to 1. Now the allocation gets larger again and intersects the 2x scaled monitor again. This commit introduces a way to properly support those actors: In case an actors resource scale might affect its allocation, it should call the private function clutter_actor_queue_immediate_relayout(). This will make sure the actor gets a relayout before the upcoming paint happens afte every resource scale change. Also potential relayout loops can be handled by the actors themselves using a "phase" argument that's passed to implementations of the calculate_resource_scale() vfunc. The new API is private because resource scales are not meant to be used in a way where the scale affects the allocation. With ClutterText and the current behavior of Pango, that can't be avoid though, so we need it anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
2020-04-10 14:54:11 +02:00
/* If an actor needs an immediate relayout because its resource scale
* changed, we give it another chance to allocate correctly before
* the paint.
*
* We're doing the whole thing twice and pass the phase to
* clutter_actor_finish_layout() to allow actors to detect loops:
clutter: Add private API to support resource scale affecting layout For ClutterText, the resource scale the text is drawn with affects the size of the allocation: ClutterText will choose a font scale based on the resource scale, and that font scale can lead to a slight difference in size compared to the unscaled font. We currently handle that by queuing a relayout inside the "resource-scale-changed" signal handler. This solution is a bit problematic though since it will take one more allocation cycle until the allocation is actually updated after a scale-change, so the actor is painted using the wrong allocation for one frame. Also the current solution can lead to relayout loops in a few cases, for example if a ClutterText is located near the edge on a 1x scaled monitor and is moved to intersect a 2x scaled monitor: Now the resource scale will change to 2 and a new allocation box is calculated; if this allocation box is slightly smaller than the old one because of the new font scale, the allocation won't intersect the 2x scaled monitor again and the resource scale switches back to 1. Now the allocation gets larger again and intersects the 2x scaled monitor again. This commit introduces a way to properly support those actors: In case an actors resource scale might affect its allocation, it should call the private function clutter_actor_queue_immediate_relayout(). This will make sure the actor gets a relayout before the upcoming paint happens afte every resource scale change. Also potential relayout loops can be handled by the actors themselves using a "phase" argument that's passed to implementations of the calculate_resource_scale() vfunc. The new API is private because resource scales are not meant to be used in a way where the scale affects the allocation. With ClutterText and the current behavior of Pango, that can't be avoid though, so we need it anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
2020-04-10 14:54:11 +02:00
* If the resource scale changes again after the relayout, the new
* allocation of an actor probably moved the actor onto another stage
* view, so if an actor sees phase == 1, it can choose a "final" scale.
*/
for (phase = 0; phase < 2; phase++)
{
clutter_actor_finish_layout (actor, phase);
clutter/actor: Add API to get the stage-views an actor is painted on There are certain rendering techniques and optimizations, for example the unredirection of non-fullscreen windows, where information about the output/stage-view an actor is on is needed to determine whether the optimization can be enabled. So add a new method to ClutterActor that allows listing the stage-views the actor is being painted on: clutter_actor_peek_stage_views() With the way Clutter works, the only point where we can reliably get this information is during or right before the paint phase, when the layout phase of the stage has been completed and no more changes to the actors transformation matrices happen. So to get the stage views the actor is on, introduce a new step that's done on every master clock tick between layout and paint cycle: Traversing through the actor tree and updating the stage-views the mapped actors are going to be painted on. We're doing this in a separate step instead of inside clutter_actor_paint() itself for a few reasons: It keeps the code separate from the painting code, making profiling easier and issues easier to track down (hopefully), it allows for a new "stage-views-changed" signal that doesn't interfere with painting, and finally, it will make it very easy to update the resource scales in the same step in the future. Currently, this list is only invalidated on allocation changes of actors, but not on changes to the transformation matrices. That's because there's no proper API to invalidate the transformation matrices ClutterActor implementations can apply through the apply_transform() vfunc. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1196
2020-04-10 00:34:49 +02:00
clutter: Add private API to support resource scale affecting layout For ClutterText, the resource scale the text is drawn with affects the size of the allocation: ClutterText will choose a font scale based on the resource scale, and that font scale can lead to a slight difference in size compared to the unscaled font. We currently handle that by queuing a relayout inside the "resource-scale-changed" signal handler. This solution is a bit problematic though since it will take one more allocation cycle until the allocation is actually updated after a scale-change, so the actor is painted using the wrong allocation for one frame. Also the current solution can lead to relayout loops in a few cases, for example if a ClutterText is located near the edge on a 1x scaled monitor and is moved to intersect a 2x scaled monitor: Now the resource scale will change to 2 and a new allocation box is calculated; if this allocation box is slightly smaller than the old one because of the new font scale, the allocation won't intersect the 2x scaled monitor again and the resource scale switches back to 1. Now the allocation gets larger again and intersects the 2x scaled monitor again. This commit introduces a way to properly support those actors: In case an actors resource scale might affect its allocation, it should call the private function clutter_actor_queue_immediate_relayout(). This will make sure the actor gets a relayout before the upcoming paint happens afte every resource scale change. Also potential relayout loops can be handled by the actors themselves using a "phase" argument that's passed to implementations of the calculate_resource_scale() vfunc. The new API is private because resource scales are not meant to be used in a way where the scale affects the allocation. With ClutterText and the current behavior of Pango, that can't be avoid though, so we need it anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
2020-04-10 14:54:11 +02:00
if (!priv->actor_needs_immediate_relayout)
break;
priv->actor_needs_immediate_relayout = FALSE;
clutter_stage_maybe_relayout (actor);
clutter: Add private API to support resource scale affecting layout For ClutterText, the resource scale the text is drawn with affects the size of the allocation: ClutterText will choose a font scale based on the resource scale, and that font scale can lead to a slight difference in size compared to the unscaled font. We currently handle that by queuing a relayout inside the "resource-scale-changed" signal handler. This solution is a bit problematic though since it will take one more allocation cycle until the allocation is actually updated after a scale-change, so the actor is painted using the wrong allocation for one frame. Also the current solution can lead to relayout loops in a few cases, for example if a ClutterText is located near the edge on a 1x scaled monitor and is moved to intersect a 2x scaled monitor: Now the resource scale will change to 2 and a new allocation box is calculated; if this allocation box is slightly smaller than the old one because of the new font scale, the allocation won't intersect the 2x scaled monitor again and the resource scale switches back to 1. Now the allocation gets larger again and intersects the 2x scaled monitor again. This commit introduces a way to properly support those actors: In case an actors resource scale might affect its allocation, it should call the private function clutter_actor_queue_immediate_relayout(). This will make sure the actor gets a relayout before the upcoming paint happens afte every resource scale change. Also potential relayout loops can be handled by the actors themselves using a "phase" argument that's passed to implementations of the calculate_resource_scale() vfunc. The new API is private because resource scales are not meant to be used in a way where the scale affects the allocation. With ClutterText and the current behavior of Pango, that can't be avoid though, so we need it anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
2020-04-10 14:54:11 +02:00
}
g_warn_if_fail (!priv->actor_needs_immediate_relayout);
clutter/actor: Add API to get the stage-views an actor is painted on There are certain rendering techniques and optimizations, for example the unredirection of non-fullscreen windows, where information about the output/stage-view an actor is on is needed to determine whether the optimization can be enabled. So add a new method to ClutterActor that allows listing the stage-views the actor is being painted on: clutter_actor_peek_stage_views() With the way Clutter works, the only point where we can reliably get this information is during or right before the paint phase, when the layout phase of the stage has been completed and no more changes to the actors transformation matrices happen. So to get the stage views the actor is on, introduce a new step that's done on every master clock tick between layout and paint cycle: Traversing through the actor tree and updating the stage-views the mapped actors are going to be painted on. We're doing this in a separate step instead of inside clutter_actor_paint() itself for a few reasons: It keeps the code separate from the painting code, making profiling easier and issues easier to track down (hopefully), it allows for a new "stage-views-changed" signal that doesn't interfere with painting, and finally, it will make it very easy to update the resource scales in the same step in the future. Currently, this list is only invalidated on allocation changes of actors, but not on changes to the transformation matrices. That's because there's no proper API to invalidate the transformation matrices ClutterActor implementations can apply through the apply_transform() vfunc. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1196
2020-04-10 00:34:49 +02:00
}
void
clutter_stage_update_devices (ClutterStage *stage,
GSList *devices)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
GSList *l;
COGL_TRACE_BEGIN_SCOPED (ClutterStageUpdateDevices, "Clutter::Stage::update_devices()");
for (l = devices; l; l = l->next)
{
ClutterInputDevice *device = l->data;
PointerDeviceEntry *entry = NULL;
entry = g_hash_table_lookup (priv->pointer_devices, device);
g_assert (entry != NULL);
clutter_stage_pick_and_update_device (stage,
device,
NULL, NULL,
CLUTTER_DEVICE_UPDATE_IGNORE_CACHE |
CLUTTER_DEVICE_UPDATE_EMIT_CROSSING,
entry->coords,
CLUTTER_CURRENT_TIME);
}
}
static void
clutter_stage_real_queue_relayout (ClutterActor *self)
{
ClutterStage *stage = CLUTTER_STAGE (self);
ClutterActorClass *parent_class;
clutter_stage_queue_actor_relayout (stage, self);
/* chain up */
parent_class = CLUTTER_ACTOR_CLASS (clutter_stage_parent_class);
parent_class->queue_relayout (self);
}
static gboolean
is_full_stage_redraw_queued (ClutterStage *stage)
{
GList *l;
for (l = clutter_stage_peek_stage_views (stage); l; l = l->next)
{
ClutterStageView *view = l->data;
if (!clutter_stage_view_has_full_redraw_clip (view))
return FALSE;
}
return TRUE;
}
static void
setup_ray_for_coordinates (ClutterStage *stage,
float x,
float y,
graphene_point3d_t *point,
graphene_ray_t *ray)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
graphene_point3d_t camera_position;
graphene_point3d_t p;
graphene_vec3_t direction;
graphene_vec3_t cv;
graphene_vec3_t v;
camera_position = GRAPHENE_POINT3D_INIT_ZERO;
graphene_vec3_init (&cv,
camera_position.x,
camera_position.y,
camera_position.z);
p = GRAPHENE_POINT3D_INIT (x, y, 0.f);
graphene_matrix_transform_point3d (&priv->view, &p, &p);
graphene_vec3_init (&v, p.x, p.y, p.z);
graphene_vec3_subtract (&v, &cv, &direction);
graphene_vec3_normalize (&direction, &direction);
graphene_ray_init (ray, &camera_position, &direction);
graphene_point3d_init_from_point (point, &p);
}
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
static ClutterActor *
_clutter_stage_do_pick_on_view (ClutterStage *stage,
float x,
float y,
ClutterPickMode mode,
ClutterStageView *view,
MtkRegion **clear_area)
{
g_autoptr (ClutterPickStack) pick_stack = NULL;
ClutterPickContext *pick_context;
graphene_point3d_t p;
graphene_ray_t ray;
ClutterActor *actor;
COGL_TRACE_BEGIN_SCOPED (ClutterStagePickView, "Clutter::Stage::do_pick_on_view()");
setup_ray_for_coordinates (stage, x, y, &p, &ray);
pick_context = clutter_pick_context_new_for_view (view, mode, &p, &ray);
clutter_actor_pick (CLUTTER_ACTOR (stage), pick_context);
pick_stack = clutter_pick_context_steal_stack (pick_context);
clutter_pick_context_destroy (pick_context);
actor = clutter_pick_stack_search_actor (pick_stack, &p, &ray, clear_area);
return actor ? actor : CLUTTER_ACTOR (stage);
}
/**
* clutter_stage_get_view_at: (skip)
*/
ClutterStageView *
clutter_stage_get_view_at (ClutterStage *stage,
float x,
float y)
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
GList *l;
for (l = _clutter_stage_window_get_views (priv->impl); l; l = l->next)
{
ClutterStageView *view = l->data;
MtkRectangle view_layout;
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
clutter_stage_view_get_layout (view, &view_layout);
if (x >= view_layout.x &&
x < view_layout.x + view_layout.width &&
y >= view_layout.y &&
y < view_layout.y + view_layout.height)
return view;
}
return NULL;
}
static ClutterActor *
_clutter_stage_do_pick (ClutterStage *stage,
float x,
float y,
ClutterPickMode mode,
MtkRegion **clear_area)
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
{
ClutterActor *actor = CLUTTER_ACTOR (stage);
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
float stage_width, stage_height;
ClutterStageView *view = NULL;
priv = clutter_stage_get_instance_private (stage);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return actor;
if (G_UNLIKELY (clutter_pick_debug_flags & CLUTTER_DEBUG_NOP_PICKING))
return actor;
if (G_UNLIKELY (priv->impl == NULL))
return actor;
clutter_actor_get_size (CLUTTER_ACTOR (stage), &stage_width, &stage_height);
if (x < 0 || x >= stage_width || y < 0 || y >= stage_height)
return actor;
view = clutter_stage_get_view_at (stage, x, y);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
if (view)
return _clutter_stage_do_pick_on_view (stage, x, y, mode, view, clear_area);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
return actor;
}
static void
clutter_stage_real_apply_transform (ClutterActor *stage,
graphene_matrix_t *matrix)
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (stage));
/* FIXME: we probably shouldn't be explicitly resetting the matrix
* here... */
graphene_matrix_init_from_matrix (matrix, &priv->view);
}
Try to mop up the default stage mess The default stage was a neat concept when we started Clutter out, somewhere in the Jurassic era; a singleton instance that gets created at initialization time, and remains the same for the entire duration of the process. Worked well enough when Clutter was a small library meant to be used to write fullscreen media browsers, but since the introduction of multiple stages, and Clutter being used to create all sorts of applications, the default stage is just a vestigial remainder of that past, like an appendix; something that complicates the layout of the code and introduces weird behaviour, so that you notice its existence only when something goes wrong. Some platforms we do support, though, only have one framebuffer, so it makes sense for them to have only one stage. At this point, the only sane thing to do is to go through the same code paths on all platforms, and that code path is the stage instance creation and initialization — i.e. clutter_stage_new() (or g_object_new() with CLUTTER_TYPE_STAGE). For platforms that support multiple stages, nothing has changed: the stage created by clutter_stage_get_default() will be set as the default one; if nobody calls it, the default stage is never created, and it just lives on as a meaningless check. For platforms that only support one stage, clutter_stage_new() and clutter_stage_get_default() will behave exactly the same the first time they are called: both will create a stage, and set it as the default. Calling clutter_stage_new() a second time is treated as a programmer error, and will result in Clutter aborting. This is a behavioural change because the existing behaviour or creating a new ClutterStage instance with the same ClutterStageWindow private implementation is, simply put, utterly braindamaged and I should have *never* had written it, and I apologize for it. In my defence, I didn't know any better at the time. This is the first step towards the complete deprecation of clutter_stage_get_default() and clutter_stage_is_default(), which will come later.
2011-11-09 14:04:05 +00:00
static void
clutter_stage_constructed (GObject *gobject)
{
ClutterStage *self = CLUTTER_STAGE (gobject);
ClutterStageManager *stage_manager;
stage_manager = clutter_stage_manager_get_default ();
/* this will take care to sinking the floating reference */
Try to mop up the default stage mess The default stage was a neat concept when we started Clutter out, somewhere in the Jurassic era; a singleton instance that gets created at initialization time, and remains the same for the entire duration of the process. Worked well enough when Clutter was a small library meant to be used to write fullscreen media browsers, but since the introduction of multiple stages, and Clutter being used to create all sorts of applications, the default stage is just a vestigial remainder of that past, like an appendix; something that complicates the layout of the code and introduces weird behaviour, so that you notice its existence only when something goes wrong. Some platforms we do support, though, only have one framebuffer, so it makes sense for them to have only one stage. At this point, the only sane thing to do is to go through the same code paths on all platforms, and that code path is the stage instance creation and initialization — i.e. clutter_stage_new() (or g_object_new() with CLUTTER_TYPE_STAGE). For platforms that support multiple stages, nothing has changed: the stage created by clutter_stage_get_default() will be set as the default one; if nobody calls it, the default stage is never created, and it just lives on as a meaningless check. For platforms that only support one stage, clutter_stage_new() and clutter_stage_get_default() will behave exactly the same the first time they are called: both will create a stage, and set it as the default. Calling clutter_stage_new() a second time is treated as a programmer error, and will result in Clutter aborting. This is a behavioural change because the existing behaviour or creating a new ClutterStage instance with the same ClutterStageWindow private implementation is, simply put, utterly braindamaged and I should have *never* had written it, and I apologize for it. In my defence, I didn't know any better at the time. This is the first step towards the complete deprecation of clutter_stage_get_default() and clutter_stage_is_default(), which will come later.
2011-11-09 14:04:05 +00:00
_clutter_stage_manager_add_stage (stage_manager, self);
G_OBJECT_CLASS (clutter_stage_parent_class)->constructed (gobject);
}
2006-05-29 08:59:36 +00:00
static void
clutter_stage_set_property (GObject *object,
2006-05-29 08:59:36 +00:00
guint prop_id,
const GValue *value,
2006-05-29 08:59:36 +00:00
GParamSpec *pspec)
{
ClutterStage *stage = CLUTTER_STAGE (object);
2006-05-29 08:59:36 +00:00
switch (prop_id)
2006-05-29 08:59:36 +00:00
{
case PROP_TITLE:
clutter_stage_set_title (stage, g_value_get_string (value));
break;
case PROP_KEY_FOCUS:
clutter_stage_set_key_focus (stage, g_value_get_object (value));
break;
2006-05-29 08:59:36 +00:00
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
clutter_stage_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
2006-05-29 08:59:36 +00:00
{
ClutterStagePrivate *priv =
clutter_stage_get_instance_private (CLUTTER_STAGE (gobject));
2006-05-29 08:59:36 +00:00
switch (prop_id)
2006-05-29 08:59:36 +00:00
{
case PROP_PERSPECTIVE:
g_value_set_boxed (value, &priv->perspective);
break;
case PROP_TITLE:
g_value_set_string (value, priv->title);
break;
case PROP_KEY_FOCUS:
g_value_set_object (value, priv->key_focused_actor);
break;
case PROP_IS_GRABBED:
g_value_set_boolean (value, !!priv->topmost_grab);
break;
2006-05-29 08:59:36 +00:00
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
2006-05-29 08:59:36 +00:00
break;
}
2006-05-29 08:59:36 +00:00
}
static void
clutter_stage_dispose (GObject *object)
{
ClutterStage *stage = CLUTTER_STAGE (object);
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
ClutterStageManager *stage_manager;
Enforce invariants on mapped, realized, visibility states Bug 1138 - No trackable "mapped" state * Add a VISIBLE flag tracking application programmer's expected showing-state for the actor, allowing us to always ensure we keep what the app wants while tracking internal implementation state separately. * Make MAPPED reflect whether the actor will be painted; add notification on a ClutterActor::mapped property. Keep MAPPED state updated as the actor is shown, ancestors are shown, actor is reparented, etc. * Require a stage and realized parents to realize; this means at realization time the correct window system and GL resources are known. But unparented actors can no longer be realized. * Allow children to be unrealized even if parent is realized. Otherwise in effect either all actors or no actors are realized, i.e. it becomes a stage-global flag. * Allow clutter_actor_realize() to "fail" if not inside a toplevel * Rework clutter_actor_unrealize() so internally we have a flavor that does not mess with visibility flag * Add _clutter_actor_rerealize() to encapsulate a somewhat tricky operation we were doing in a couple of places * Do not realize/unrealize children in ClutterGroup, ClutterActor already does it * Do not realize impl by hand in clutter_stage_show(), since showing impl already does that * Do not unrealize in various dispose() methods, since ClutterActor dispose implementation already does it and chaining up is mandatory * ClutterTexture uses COGL while unrealizable (before it's added to a stage). Previously this breakage was affecting ClutterActor because we had to allow realize outside a stage. Move the breakage to ClutterTexture, by making ClutterTexture just use COGL while not realized. * Unrealize before we set parent to NULL in clutter_actor_unparent(). This means unrealize() implementations can get to the stage. Because actors need the stage in order to detach from stage. * Update clutter-actor-invariants.txt to reflect latest changes * Remove explicit hide/unrealize from ClutterActor::dispose since unparent already forces those Instead just assert that unparent() occurred and did the right thing. * Check whether parent implements unrealize before chaining up Needed because ClutterGroup no longer has to implement unrealize. * Perform unrealize in the default handler for the signal. This allows non-containers that have children to work properly, and allows containers to override how it's done. * Add map/unmap virtual methods and set MAPPED flag on self and children in there. This allows subclasses to hook map/unmap. These are not signals, because notify::mapped is better for anything it's legitimate for a non-subclass to do. Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
2009-04-02 09:16:43 -04:00
clutter_actor_hide (CLUTTER_ACTOR (object));
_clutter_clear_events_queue ();
if (priv->impl != NULL)
{
CLUTTER_NOTE (BACKEND, "Disposing of the stage implementation");
if (clutter_actor_is_realized (CLUTTER_ACTOR (object)))
_clutter_stage_window_unrealize (priv->impl);
g_object_unref (priv->impl);
priv->impl = NULL;
}
clutter_actor_destroy_all_children (CLUTTER_ACTOR (object));
g_slist_free_full (priv->pending_relayouts,
(GDestroyNotify) g_object_unref);
priv->pending_relayouts = NULL;
/* this will release the reference on the stage */
stage_manager = clutter_stage_manager_get_default ();
_clutter_stage_manager_remove_stage (stage_manager, stage);
g_hash_table_remove_all (priv->pointer_devices);
g_hash_table_remove_all (priv->touch_sequences);
G_OBJECT_CLASS (clutter_stage_parent_class)->dispose (object);
}
static void
clutter_stage_finalize (GObject *object)
{
ClutterStage *stage = CLUTTER_STAGE (object);
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
g_queue_foreach (priv->event_queue, (GFunc) clutter_event_free, NULL);
g_queue_free (priv->event_queue);
g_assert (priv->cur_event_actors->len == 0);
g_ptr_array_free (priv->cur_event_actors, TRUE);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
g_assert (priv->cur_event_emission_chain->len == 0);
g_array_unref (priv->cur_event_emission_chain);
g_hash_table_destroy (priv->pointer_devices);
g_hash_table_destroy (priv->touch_sequences);
g_free (priv->title);
G_OBJECT_CLASS (clutter_stage_parent_class)->finalize (object);
}
static void
clutter_stage_real_paint_view (ClutterStage *stage,
ClutterStageView *view,
const MtkRegion *redraw_clip,
ClutterFrame *frame)
{
clutter_stage_do_paint_view (stage, view, frame, redraw_clip);
}
static void
clutter_stage_paint (ClutterActor *actor,
ClutterPaintContext *paint_context)
{
ClutterStageView *view;
CLUTTER_ACTOR_CLASS (clutter_stage_parent_class)->paint (actor, paint_context);
view = clutter_paint_context_get_stage_view (paint_context);
if (view &&
G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_MAX_RENDER_TIME))
{
MtkRectangle view_layout;
ClutterFrameClock *frame_clock;
g_autoptr (GString) string = NULL;
PangoLayout *layout;
PangoRectangle logical;
ClutterColor color;
g_autoptr (ClutterPaintNode) node = NULL;
ClutterActorBox box;
clutter_stage_view_get_layout (view, &view_layout);
frame_clock = clutter_stage_view_get_frame_clock (view);
string = clutter_frame_clock_get_max_render_time_debug_info (frame_clock);
layout = clutter_actor_create_pango_layout (actor, string->str);
pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
pango_layout_get_pixel_extents (layout, NULL, &logical);
clutter_color_init (&color, 255, 255, 255, 255);
node = clutter_text_node_new (layout, &color);
box.x1 = view_layout.x;
box.y1 = view_layout.y + 30;
box.x2 = box.x1 + logical.width;
box.y2 = box.y1 + logical.height;
clutter_paint_node_add_rectangle (node, &box);
clutter_paint_node_paint (node, paint_context);
g_object_unref (layout);
}
}
2006-05-29 08:59:36 +00:00
static void
clutter_stage_class_init (ClutterStageClass *klass)
{
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
2006-05-29 08:59:36 +00:00
Try to mop up the default stage mess The default stage was a neat concept when we started Clutter out, somewhere in the Jurassic era; a singleton instance that gets created at initialization time, and remains the same for the entire duration of the process. Worked well enough when Clutter was a small library meant to be used to write fullscreen media browsers, but since the introduction of multiple stages, and Clutter being used to create all sorts of applications, the default stage is just a vestigial remainder of that past, like an appendix; something that complicates the layout of the code and introduces weird behaviour, so that you notice its existence only when something goes wrong. Some platforms we do support, though, only have one framebuffer, so it makes sense for them to have only one stage. At this point, the only sane thing to do is to go through the same code paths on all platforms, and that code path is the stage instance creation and initialization — i.e. clutter_stage_new() (or g_object_new() with CLUTTER_TYPE_STAGE). For platforms that support multiple stages, nothing has changed: the stage created by clutter_stage_get_default() will be set as the default one; if nobody calls it, the default stage is never created, and it just lives on as a meaningless check. For platforms that only support one stage, clutter_stage_new() and clutter_stage_get_default() will behave exactly the same the first time they are called: both will create a stage, and set it as the default. Calling clutter_stage_new() a second time is treated as a programmer error, and will result in Clutter aborting. This is a behavioural change because the existing behaviour or creating a new ClutterStage instance with the same ClutterStageWindow private implementation is, simply put, utterly braindamaged and I should have *never* had written it, and I apologize for it. In my defence, I didn't know any better at the time. This is the first step towards the complete deprecation of clutter_stage_get_default() and clutter_stage_is_default(), which will come later.
2011-11-09 14:04:05 +00:00
gobject_class->constructed = clutter_stage_constructed;
2006-05-29 08:59:36 +00:00
gobject_class->set_property = clutter_stage_set_property;
gobject_class->get_property = clutter_stage_get_property;
gobject_class->dispose = clutter_stage_dispose;
gobject_class->finalize = clutter_stage_finalize;
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
2008-06-10 Emmanuele Bassi <ebassi@openedhand.com> Bug #815 - Split up request, allocation, and paint box * clutter/clutter-actor.[ch]: Rework the size allocation, request and paint area. Now ::request_coords() is called ::allocate(), and ::query_coords() has been split into ::get_preferred_width() and ::get_preferred_height(). See the documentation and the layout test on how to implement a container and layout manager with the new API. (#915, based on a patch by Havoc Pennington, Lucas Rocha and Johan Bilien) * clutter/clutter-clone-texture.c: Port CloneTexture to the new size negotiation API; it just means forwarding the requests to the parent texture. * clutter/clutter-deprecated.h: Add deprecated and replaced API. * clutter/clutter-entry.c: Port Entry to the new size negotiation API. * clutter/clutter-group.c: Port Group to the new size negotiation API; the semantics of the Group actor do not change. * clutter/clutter-label.c: Port Label to the new size negotiation API, and vastly simplify the code. * clutter/clutter-main.[ch]: Add API for executing a relayout when needed. * clutter/clutter-private.h: Add new Stage private API. * clutter/clutter-rectangle.c: Update the get_abs_opacity() call to get_paint_opacity(). * clutter/clutter-stage.c: (clutter_stage_get_preferred_width), (clutter_stage_get_preferred_height), (clutter_stage_allocate), (clutter_stage_class_init): Port Stage to the new size negotiation API. * clutter/clutter-texture.c: Port Texture to the new size negotiation API. * clutter/clutter-types.h: Add ClutterRequestMode enumeration. * clutter/x11/clutter-stage-x11.c: Port the X11 stage implementation to the new size negotiation API. * tests/Makefile.am: Add the layout manager test case. * tests/test-opacity.c: Update. * tests/test-project.c: Update. * tests/test-layout.c: Test case for a layout manager implemented using the new size negotiation API; the layout manager handles both transformed and untransformed children.
2008-06-10 17:07:52 +00:00
actor_class->allocate = clutter_stage_allocate;
actor_class->get_preferred_width = clutter_stage_get_preferred_width;
actor_class->get_preferred_height = clutter_stage_get_preferred_height;
actor_class->get_paint_volume = clutter_stage_get_paint_volume;
actor_class->realize = clutter_stage_realize;
actor_class->unrealize = clutter_stage_unrealize;
actor_class->show = clutter_stage_show;
actor_class->hide = clutter_stage_hide;
actor_class->hide_all = clutter_stage_hide_all;
actor_class->queue_relayout = clutter_stage_real_queue_relayout;
actor_class->apply_transform = clutter_stage_real_apply_transform;
actor_class->paint = clutter_stage_paint;
klass->paint_view = clutter_stage_real_paint_view;
/**
* ClutterStage:perspective:
*
* The parameters used for the perspective projection from 3D
* coordinates to 2D
*/
obj_props[PROP_PERSPECTIVE] =
g_param_spec_boxed ("perspective", NULL, NULL,
CLUTTER_TYPE_PERSPECTIVE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* ClutterStage:title:
*
* The stage's title - usually displayed in stage windows title decorations.
*/
obj_props[PROP_TITLE] =
g_param_spec_string ("title", NULL, NULL,
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* ClutterStage:key-focus:
*
* The [class@Clutter.Actor] that will receive key events from the underlying
* windowing system.
*
* If %NULL, the #ClutterStage will receive the events.
*/
obj_props[PROP_KEY_FOCUS] =
g_param_spec_object ("key-focus", NULL, NULL,
CLUTTER_TYPE_ACTOR,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* ClutterStage:is-grabbed:
*
* %TRUE if there is currently an active grab on the stage.
*/
obj_props[PROP_IS_GRABBED] =
g_param_spec_boolean ("is-grabbed", NULL, NULL,
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
/**
* ClutterStage::activate:
* @stage: the stage which was activated
*
* The signal is emitted when the stage receives key focus
* from the underlying window system.
*/
stage_signals[ACTIVATE] =
g_signal_new (I_("activate"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterStageClass, activate),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* ClutterStage::deactivate:
* @stage: the stage which was deactivated
*
* The signal is emitted when the stage loses key focus
* from the underlying window system.
*/
stage_signals[DEACTIVATE] =
g_signal_new (I_("deactivate"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterStageClass, deactivate),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* ClutterStage::before-update:
* @stage: the #ClutterStage
* @view: a #ClutterStageView
* @frame: a #ClutterFrame
*/
stage_signals[BEFORE_UPDATE] =
g_signal_new (I_("before-update"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
_clutter_marshal_VOID__OBJECT_BOXED,
G_TYPE_NONE, 2,
CLUTTER_TYPE_STAGE_VIEW,
CLUTTER_TYPE_FRAME | G_SIGNAL_TYPE_STATIC_SCOPE);
g_signal_set_va_marshaller (stage_signals[BEFORE_UPDATE],
G_TYPE_FROM_CLASS (gobject_class),
_clutter_marshal_VOID__OBJECT_BOXEDv);
/**
* ClutterStage::prepare-frame:
* @stage: the stage that received the event
* @view: a #ClutterStageView
* @frame: a #ClutterFrame
*
* The signal is emitted after the stage is updated,
* before the stage is painted, even if it will not be painted.
*/
stage_signals[PREPARE_FRAME] =
g_signal_new (I_("prepare-frame"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
_clutter_marshal_VOID__OBJECT_BOXED,
G_TYPE_NONE, 2,
CLUTTER_TYPE_STAGE_VIEW,
CLUTTER_TYPE_FRAME | G_SIGNAL_TYPE_STATIC_SCOPE);
g_signal_set_va_marshaller (stage_signals[PREPARE_FRAME],
G_TYPE_FROM_CLASS (gobject_class),
_clutter_marshal_VOID__OBJECT_BOXEDv);
/**
* ClutterStage::before-paint:
* @stage: the stage that received the event
* @view: a #ClutterStageView
* @frame: a #ClutterFrame
*
* The signal is emitted before the stage is painted.
*/
stage_signals[BEFORE_PAINT] =
g_signal_new (I_("before-paint"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterStageClass, before_paint),
NULL, NULL,
_clutter_marshal_VOID__OBJECT_BOXED,
G_TYPE_NONE, 2,
CLUTTER_TYPE_STAGE_VIEW,
CLUTTER_TYPE_FRAME | G_SIGNAL_TYPE_STATIC_SCOPE);
g_signal_set_va_marshaller (stage_signals[BEFORE_PAINT],
G_TYPE_FROM_CLASS (gobject_class),
_clutter_marshal_VOID__OBJECT_BOXEDv);
/**
* ClutterStage::after-paint:
* @stage: the stage that received the event
* @view: a #ClutterStageView
* @frame: a #ClutterFrame
*
* The signal is emitted after the stage is painted,
* but before the results are displayed on the screen.0
*/
stage_signals[AFTER_PAINT] =
g_signal_new (I_("after-paint"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0, /* no corresponding vfunc */
NULL, NULL,
_clutter_marshal_VOID__OBJECT_BOXED,
G_TYPE_NONE, 2,
CLUTTER_TYPE_STAGE_VIEW,
CLUTTER_TYPE_FRAME | G_SIGNAL_TYPE_STATIC_SCOPE);
g_signal_set_va_marshaller (stage_signals[AFTER_PAINT],
G_TYPE_FROM_CLASS (gobject_class),
_clutter_marshal_VOID__OBJECT_BOXEDv);
/**
* ClutterStage::after-update:
* @stage: the #ClutterStage
* @view: a #ClutterStageView
* @frame: a #ClutterFrame
*/
stage_signals[AFTER_UPDATE] =
g_signal_new (I_("after-update"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
_clutter_marshal_VOID__OBJECT_BOXED,
G_TYPE_NONE, 2,
CLUTTER_TYPE_STAGE_VIEW,
CLUTTER_TYPE_FRAME | G_SIGNAL_TYPE_STATIC_SCOPE);
g_signal_set_va_marshaller (stage_signals[AFTER_UPDATE],
G_TYPE_FROM_CLASS (gobject_class),
_clutter_marshal_VOID__OBJECT_BOXEDv);
/**
* ClutterStage::paint-view:
* @stage: the stage that received the event
* @view: a #ClutterStageView
* @redraw_clip: a #MtkRegion with the redraw clip
* @frame: a #ClutterFrame
*
* The signal is emitted before a [class@Clutter.StageView] is being
* painted.
*
* The view is painted in the default handler. Hence, if you want to perform
* some action after the view is painted, like reading the contents of the
* framebuffer, use [func@GObject.signal_connect_after] or pass %G_CONNECT_AFTER.
*/
stage_signals[PAINT_VIEW] =
g_signal_new (I_("paint-view"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterStageClass, paint_view),
NULL, NULL,
_clutter_marshal_VOID__OBJECT_BOXED_BOXED,
G_TYPE_NONE, 3,
CLUTTER_TYPE_STAGE_VIEW,
MTK_TYPE_REGION | G_SIGNAL_TYPE_STATIC_SCOPE,
CLUTTER_TYPE_FRAME | G_SIGNAL_TYPE_STATIC_SCOPE);
g_signal_set_va_marshaller (stage_signals[PAINT_VIEW],
G_TYPE_FROM_CLASS (gobject_class),
_clutter_marshal_VOID__OBJECT_BOXED_BOXEDv);
/**
* ClutterStage::presented: (skip)
* @stage: the stage that received the event
* @view: the #ClutterStageView presented
* @frame_info: a #ClutterFrameInfo
2018-10-19 09:15:54 +02:00
*
* Signals that the #ClutterStage was presented on the screen to the user.
*/
stage_signals[PRESENTED] =
g_signal_new (I_("presented"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
_clutter_marshal_VOID__OBJECT_POINTER,
G_TYPE_NONE, 2,
CLUTTER_TYPE_STAGE_VIEW,
G_TYPE_POINTER);
g_signal_set_va_marshaller (stage_signals[PRESENTED],
G_TYPE_FROM_CLASS (gobject_class),
_clutter_marshal_VOID__OBJECT_POINTERv);
/**
* ClutterStage::gl-video-memory-purged: (skip)
* @stage: the stage that received the event
*
* Signals that the underlying GL driver has had its texture memory purged
* so anything presently held in texture memory is now invalidated, and
* likely corrupt. It needs redrawing.
*/
stage_signals[GL_VIDEO_MEMORY_PURGED] =
g_signal_new (I_("gl-video-memory-purged"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
klass->activate = clutter_stage_real_activate;
klass->deactivate = clutter_stage_real_deactivate;
2006-05-29 08:59:36 +00:00
}
static void
on_seat_unfocus_inhibited_changed (ClutterStage *stage,
ClutterSeat *seat)
{
clutter_stage_repick_device (stage, clutter_seat_get_pointer (seat));
}
2006-05-29 08:59:36 +00:00
static void
clutter_stage_init (ClutterStage *self)
{
MtkRectangle geom = { 0, };
2006-05-29 08:59:36 +00:00
ClutterStagePrivate *priv;
Try to mop up the default stage mess The default stage was a neat concept when we started Clutter out, somewhere in the Jurassic era; a singleton instance that gets created at initialization time, and remains the same for the entire duration of the process. Worked well enough when Clutter was a small library meant to be used to write fullscreen media browsers, but since the introduction of multiple stages, and Clutter being used to create all sorts of applications, the default stage is just a vestigial remainder of that past, like an appendix; something that complicates the layout of the code and introduces weird behaviour, so that you notice its existence only when something goes wrong. Some platforms we do support, though, only have one framebuffer, so it makes sense for them to have only one stage. At this point, the only sane thing to do is to go through the same code paths on all platforms, and that code path is the stage instance creation and initialization — i.e. clutter_stage_new() (or g_object_new() with CLUTTER_TYPE_STAGE). For platforms that support multiple stages, nothing has changed: the stage created by clutter_stage_get_default() will be set as the default one; if nobody calls it, the default stage is never created, and it just lives on as a meaningless check. For platforms that only support one stage, clutter_stage_new() and clutter_stage_get_default() will behave exactly the same the first time they are called: both will create a stage, and set it as the default. Calling clutter_stage_new() a second time is treated as a programmer error, and will result in Clutter aborting. This is a behavioural change because the existing behaviour or creating a new ClutterStage instance with the same ClutterStageWindow private implementation is, simply put, utterly braindamaged and I should have *never* had written it, and I apologize for it. In my defence, I didn't know any better at the time. This is the first step towards the complete deprecation of clutter_stage_get_default() and clutter_stage_is_default(), which will come later.
2011-11-09 14:04:05 +00:00
ClutterStageWindow *impl;
ClutterBackend *backend;
ClutterSeat *seat;
Try to mop up the default stage mess The default stage was a neat concept when we started Clutter out, somewhere in the Jurassic era; a singleton instance that gets created at initialization time, and remains the same for the entire duration of the process. Worked well enough when Clutter was a small library meant to be used to write fullscreen media browsers, but since the introduction of multiple stages, and Clutter being used to create all sorts of applications, the default stage is just a vestigial remainder of that past, like an appendix; something that complicates the layout of the code and introduces weird behaviour, so that you notice its existence only when something goes wrong. Some platforms we do support, though, only have one framebuffer, so it makes sense for them to have only one stage. At this point, the only sane thing to do is to go through the same code paths on all platforms, and that code path is the stage instance creation and initialization — i.e. clutter_stage_new() (or g_object_new() with CLUTTER_TYPE_STAGE). For platforms that support multiple stages, nothing has changed: the stage created by clutter_stage_get_default() will be set as the default one; if nobody calls it, the default stage is never created, and it just lives on as a meaningless check. For platforms that only support one stage, clutter_stage_new() and clutter_stage_get_default() will behave exactly the same the first time they are called: both will create a stage, and set it as the default. Calling clutter_stage_new() a second time is treated as a programmer error, and will result in Clutter aborting. This is a behavioural change because the existing behaviour or creating a new ClutterStage instance with the same ClutterStageWindow private implementation is, simply put, utterly braindamaged and I should have *never* had written it, and I apologize for it. In my defence, I didn't know any better at the time. This is the first step towards the complete deprecation of clutter_stage_get_default() and clutter_stage_is_default(), which will come later.
2011-11-09 14:04:05 +00:00
GError *error;
2006-07-06 Emmanuele Bassi <ebassi@openedhand.com> Big rework of the actor management semantics: now ClutterActor objects behave like GtkObjects - that is they have an initial "floating" reference that gets "sunk" when they are added to a ClutterGroup. This makes a group responsible of de-allocating each actor inside it, so you just have to destroy the group to get every child actor destroyed. Also, now you can do: clutter_group_add (group, clutter_video_texture_new ()); without having to care about reference counting and explicit unreffing. * clutter/clutter-private.h: Add private flags setter and getter macros. * clutter/clutter-actor.h: * clutter/clutter-actor.c: Clean up; inherit from GInitiallyUnowned; add a "visible" property; add the "destroy", "show" and "hide" signals to ClutterActorClass. (clutter_actor_show), (clutter_actor_hide): Refactor a bit; emit the "show" and "hide" signals. (clutter_actor_set_property), (clutter_actor_get_property), (clutter_actor_class_init): Implement the "visible" property; add signals. (clutter_actor_finalize): Do not leak the actor's name, if it is set. (clutter_actor_dispose): Emit the "destroy" signal here. (clutter_actor_init): Sink the initial floating flag if needed. (clutter_actor_destroy): Add a function to explicitely destroy a ClutterActor. (clutter_actor_set_parent), (clutter_actor_get_parent), (clutter_actor_unparent): Make set_parent require a valid parent; add unparent; check on get_parent; ref_sink the actor when setting its parent and unref it when unsetting it. Probably we'll need a function that does reparenting as unparent+set_parent in a single shot. * clutter/clutter-group.h: * clutter/clutter-group.c (clutter_group_dispose), (clutter_group_finalize), (clutter_group_add), (clutter_group_remove): Make the group destroy its children when disposing it; clean up, and use the newly-available clutter_actor_unparent(). * clutter/clutter-stage.h: * clutter/clutter-stage.c (clutter_stage_init): ClutterStage is a top-level actor; clean up. * clutter/clutter-video-texture.h: * clutter/clutter-video-texture.c: Clean up. * examples/super-oh.c: * examples/test.c: * examples/video-player.c: * examples/test-text.c: * examples/video-cube.c: Remove the g_object_unref() call, as the ClutterStage object is destroyed on clutter_main_quit().
2006-07-06 17:52:57 +00:00
/* a stage is a top-level object */
CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IS_TOPLEVEL);
priv = clutter_stage_get_instance_private (self);
2006-05-29 08:59:36 +00:00
CLUTTER_NOTE (BACKEND, "Creating stage from the default backend");
backend = clutter_get_default_backend ();
Try to mop up the default stage mess The default stage was a neat concept when we started Clutter out, somewhere in the Jurassic era; a singleton instance that gets created at initialization time, and remains the same for the entire duration of the process. Worked well enough when Clutter was a small library meant to be used to write fullscreen media browsers, but since the introduction of multiple stages, and Clutter being used to create all sorts of applications, the default stage is just a vestigial remainder of that past, like an appendix; something that complicates the layout of the code and introduces weird behaviour, so that you notice its existence only when something goes wrong. Some platforms we do support, though, only have one framebuffer, so it makes sense for them to have only one stage. At this point, the only sane thing to do is to go through the same code paths on all platforms, and that code path is the stage instance creation and initialization — i.e. clutter_stage_new() (or g_object_new() with CLUTTER_TYPE_STAGE). For platforms that support multiple stages, nothing has changed: the stage created by clutter_stage_get_default() will be set as the default one; if nobody calls it, the default stage is never created, and it just lives on as a meaningless check. For platforms that only support one stage, clutter_stage_new() and clutter_stage_get_default() will behave exactly the same the first time they are called: both will create a stage, and set it as the default. Calling clutter_stage_new() a second time is treated as a programmer error, and will result in Clutter aborting. This is a behavioural change because the existing behaviour or creating a new ClutterStage instance with the same ClutterStageWindow private implementation is, simply put, utterly braindamaged and I should have *never* had written it, and I apologize for it. In my defence, I didn't know any better at the time. This is the first step towards the complete deprecation of clutter_stage_get_default() and clutter_stage_is_default(), which will come later.
2011-11-09 14:04:05 +00:00
error = NULL;
impl = _clutter_backend_create_stage (backend, self, &error);
if (G_LIKELY (impl != NULL))
{
_clutter_stage_set_window (self, impl);
_clutter_stage_window_get_geometry (priv->impl, &geom);
}
else
Try to mop up the default stage mess The default stage was a neat concept when we started Clutter out, somewhere in the Jurassic era; a singleton instance that gets created at initialization time, and remains the same for the entire duration of the process. Worked well enough when Clutter was a small library meant to be used to write fullscreen media browsers, but since the introduction of multiple stages, and Clutter being used to create all sorts of applications, the default stage is just a vestigial remainder of that past, like an appendix; something that complicates the layout of the code and introduces weird behaviour, so that you notice its existence only when something goes wrong. Some platforms we do support, though, only have one framebuffer, so it makes sense for them to have only one stage. At this point, the only sane thing to do is to go through the same code paths on all platforms, and that code path is the stage instance creation and initialization — i.e. clutter_stage_new() (or g_object_new() with CLUTTER_TYPE_STAGE). For platforms that support multiple stages, nothing has changed: the stage created by clutter_stage_get_default() will be set as the default one; if nobody calls it, the default stage is never created, and it just lives on as a meaningless check. For platforms that only support one stage, clutter_stage_new() and clutter_stage_get_default() will behave exactly the same the first time they are called: both will create a stage, and set it as the default. Calling clutter_stage_new() a second time is treated as a programmer error, and will result in Clutter aborting. This is a behavioural change because the existing behaviour or creating a new ClutterStage instance with the same ClutterStageWindow private implementation is, simply put, utterly braindamaged and I should have *never* had written it, and I apologize for it. In my defence, I didn't know any better at the time. This is the first step towards the complete deprecation of clutter_stage_get_default() and clutter_stage_is_default(), which will come later.
2011-11-09 14:04:05 +00:00
{
if (error != NULL)
{
g_critical ("Unable to create a new stage implementation: %s",
error->message);
g_error_free (error);
}
else
g_critical ("Unable to create a new stage implementation.");
}
priv->event_queue = g_queue_new ();
priv->cur_event_actors = g_ptr_array_sized_new (32);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
priv->cur_event_emission_chain =
g_array_sized_new (FALSE, TRUE, sizeof (EventReceiver), 32);
g_array_set_clear_func (priv->cur_event_emission_chain,
(GDestroyNotify) free_event_receiver);
priv->pointer_devices =
g_hash_table_new_full (NULL, NULL,
NULL, (GDestroyNotify) free_pointer_device_entry);
priv->touch_sequences =
g_hash_table_new_full (NULL, NULL,
NULL, (GDestroyNotify) free_pointer_device_entry);
clutter_actor_set_background_color (CLUTTER_ACTOR (self),
&default_stage_color);
clutter_stage_queue_actor_relayout (self, CLUTTER_ACTOR (self));
clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
clutter_stage_set_title (self, g_get_prgname ());
clutter_stage_set_key_focus (self, NULL);
clutter_stage_set_viewport (self, geom.width, geom.height);
seat = clutter_backend_get_default_seat (backend);
g_signal_connect_object (seat, "is-unfocus-inhibited-changed",
G_CALLBACK (on_seat_unfocus_inhibited_changed),
self,
G_CONNECT_SWAPPED);
2006-06-05 Emmanuele Bassi <ebassi@openedhand.com> * clutter-color.h: * clutter-color.c: Reimplement ClutterColor as a boxed type; add convenience API for color handling, like: add, subtract, shade, HSL color-space conversion, packing and unpacking. * clutter-private.h: Update ClutterMainContext, and export the main context pointer here. * clutter-rectangle.h: * clutter-rectangle.c: Update the color-related code; make clutter_rectangle_new() and empty constructor and provide clutter_rectangle_new_with_color(); provide color setter and getter API. * clutter-label.h: * clutter-label.c: Rename the "font" property to "font-name"; update the color-related code to the new ClutterColor object; rename clutter_label_new() to clutter_label_new_with_text(), and add setters and getters for the properties. * clutter-marshal.list: Add VOID:OBJECT and VOID:BOXED marshallers generators. * clutter-stage.h: * clutter-stage.c: Rework the API: provide a default constructor for a singleton object, named clutter_stage_get_default(), which supercedes the clutter_stage() function in clutter-main; provide new events: button-press-event, button-release-event, key-press-event and key-release-event; update the color-related code; (clutter_stage_snapshot): Allow negative width and height when taking a snapshot (meaning: use full width/height). (clutter_stage_get_element_at_pos): Rename clutter_stage_pick(). * clutter-element.c (clutter_element_paint): Clean up the stage and color related code. * clutter-event.h: * clutter-event.c: Add generic ClutterAnyEvent type; add clutter_event_new(), clutter_event_copy() and clutter_event_free(); make ClutterEvent a boxed type. * clutter-main.h: * clutter-main.c: Remove clutter_stage(); add clutter_main_quit(), for cleanly quitting from clutter_main(); add multiple mainloops support; allocate the ClutterCntx instead of adding it to the stack; re-work the ClutterEvent dispatching. * clutter-group.c (clutter_group_add), (clutter_group_remove): Keep a reference on the element when added to a ClutterGroup. * examples/rects.py * examples/test.c: * examples/test-text.c: * examples/video-cube.c: * examples/super-oh.c: * examples/test-video.c: Update.
2006-06-05 13:38:31 +00:00
}
static void
clutter_stage_set_perspective (ClutterStage *stage,
ClutterPerspective *perspective)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
if (priv->perspective.fovy == perspective->fovy &&
priv->perspective.aspect == perspective->aspect &&
priv->perspective.z_near == perspective->z_near &&
priv->perspective.z_far == perspective->z_far)
return;
priv->perspective = *perspective;
graphene_matrix_init_perspective (&priv->projection,
priv->perspective.fovy,
priv->perspective.aspect,
priv->perspective.z_near,
priv->perspective.z_far);
graphene_matrix_inverse (&priv->projection,
&priv->inverse_projection);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
_clutter_stage_dirty_projection (stage);
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
/**
* clutter_stage_get_perspective:
* @stage: A #ClutterStage
* @perspective: (out caller-allocates) (allow-none): return location for a
* #ClutterPerspective
*
* Retrieves the stage perspective.
*/
void
clutter_stage_get_perspective (ClutterStage *stage,
ClutterPerspective *perspective)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (perspective != NULL);
priv = clutter_stage_get_instance_private (stage);
*perspective = priv->perspective;
}
/*
* clutter_stage_get_projection_matrix:
* @stage: A #ClutterStage
* @projection: return location for a #graphene_matrix_t representing the
* perspective projection applied to actors on the given
* @stage.
*
* Retrieves the @stage's projection matrix. This is derived from the
* current perspective.
*/
void
_clutter_stage_get_projection_matrix (ClutterStage *stage,
graphene_matrix_t *projection)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (projection != NULL);
priv = clutter_stage_get_instance_private (stage);
*projection = priv->projection;
}
/* This simply provides a simple mechanism for us to ensure that
* the projection matrix gets re-asserted before painting.
*
* This is used when switching between multiple stages */
void
_clutter_stage_dirty_projection (ClutterStage *stage)
{
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
ClutterStagePrivate *priv;
GList *l;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = clutter_stage_get_instance_private (stage);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
for (l = _clutter_stage_window_get_views (priv->impl); l; l = l->next)
{
ClutterStageView *view = l->data;
clutter_stage_view_invalidate_projection (view);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
}
}
/*
* clutter_stage_set_viewport:
* @stage: A #ClutterStage
* @width: The width to render the stage at, in window coordinates
* @height: The height to render the stage at, in window coordinates
*
* Sets the stage viewport. The viewport defines a final scale and
* translation of your rendered stage and actors. This lets you render
* your stage into a subregion of the stage window or you could use it to
* pan a subregion of the stage if your stage window is smaller then
* the stage. (XXX: currently this isn't possible)
*
* Unlike a scale and translation done using the modelview matrix this
* is done after everything has had perspective projection applied, so
* for example if you were to pan across a subregion of the stage using
* the viewport then you would not see a change in perspective for the
* actors on the stage.
*
* Normally the stage viewport will automatically track the size of the
* stage window with no offset so the stage will fill your window. This
* behaviour can be changed with the "viewport-mimics-window" property
* which will automatically be set to FALSE if you use this API. If
* you want to revert to the original behaviour then you should set
* this property back to %TRUE using
* clutter_stage_set_viewport_mimics_window().
* (XXX: If we were to make this API public then we might want to do
* add that property.)
*
* Note: currently this interface only support integer precision
* offsets and sizes for viewports but the interface takes floats because
* OpenGL 4.0 has introduced floating point viewports which we might
* want to expose via this API eventually.
*/
static void
clutter_stage_set_viewport (ClutterStage *stage,
float width,
float height)
{
ClutterStagePrivate *priv;
float x, y;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = clutter_stage_get_instance_private (stage);
x = 0.f;
y = 0.f;
width = roundf (width);
height = roundf (height);
if (x == priv->viewport[0] &&
y == priv->viewport[1] &&
width == priv->viewport[2] &&
height == priv->viewport[3])
return;
priv->viewport[0] = x;
priv->viewport[1] = y;
priv->viewport[2] = width;
priv->viewport[3] = height;
clutter_stage_update_view_perspective (stage);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
_clutter_stage_dirty_viewport (stage);
queue_full_redraw (stage);
}
/* This simply provides a simple mechanism for us to ensure that
* the viewport gets re-asserted before next painting.
*
* This is used when switching between multiple stages */
void
_clutter_stage_dirty_viewport (ClutterStage *stage)
{
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
ClutterStagePrivate *priv;
GList *l;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = clutter_stage_get_instance_private (stage);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
for (l = _clutter_stage_window_get_views (priv->impl); l; l = l->next)
{
ClutterStageView *view = l->data;
clutter_stage_view_invalidate_viewport (view);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
}
}
/*
* clutter_stage_get_viewport:
* @stage: A #ClutterStage
* @x: A location for the X position where the stage is rendered,
* in window coordinates.
* @y: A location for the Y position where the stage is rendered,
* in window coordinates.
* @width: A location for the width the stage is rendered at,
* in window coordinates.
* @height: A location for the height the stage is rendered at,
* in window coordinates.
*
* Returns the viewport offset and size set using
* clutter_stage_set_viewport() or if the "viewport-mimics-window" property
* is TRUE then @x and @y will be set to 0 and @width and @height will equal
* the width if the stage window.
*/
void
_clutter_stage_get_viewport (ClutterStage *stage,
float *x,
float *y,
float *width,
float *height)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = clutter_stage_get_instance_private (stage);
*x = priv->viewport[0];
*y = priv->viewport[1];
*width = priv->viewport[2];
*height = priv->viewport[3];
}
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
/**
* clutter_stage_read_pixels:
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
* @stage: A #ClutterStage
* @x: x coordinate of the first pixel that is read from stage
* @y: y coordinate of the first pixel that is read from stage
* @width: Width dimension of pixels to be read, or -1 for the
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
* entire stage width
* @height: Height dimension of pixels to be read, or -1 for the
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
* entire stage height
*
* Makes a screenshot of the stage in RGBA 8bit data, returns a
* linear buffer with @width * 4 as rowstride.
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
*
* The alpha data contained in the returned buffer is driver-dependent,
* and not guaranteed to hold any sensible value.
*
* Return value: (transfer full) (array): a pointer to newly allocated memory with the buffer
* or %NULL if the read failed. Use g_free() on the returned data
* to release the resources it has allocated.
*/
guchar *
clutter_stage_read_pixels (ClutterStage *stage,
gint x,
gint y,
gint width,
gint height)
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
{
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
ClutterStagePrivate *priv;
ClutterActorBox box;
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
GList *l;
ClutterStageView *view;
g_autoptr (MtkRegion) clip = NULL;
MtkRectangle clip_rect;
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
CoglFramebuffer *framebuffer;
float view_scale;
float pixel_width;
float pixel_height;
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
uint8_t *pixels;
2006-05-29 08:59:36 +00:00
COGL_TRACE_BEGIN_SCOPED (ClutterStageReadPixels, "Clutter::Stage::read_pixels()");
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
priv = clutter_stage_get_instance_private (stage);
clutter_actor_get_allocation_box (CLUTTER_ACTOR (stage), &box);
if (width < 0)
width = ceilf (box.x2 - box.x1);
if (height < 0)
height = ceilf (box.y2 - box.y1);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
l = _clutter_stage_window_get_views (priv->impl);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
if (!l)
return NULL;
/* XXX: We only read the first view. Needs different API for multi view screen
* capture. */
view = l->data;
clutter_stage_view_get_layout (view, &clip_rect);
clip = mtk_region_create_rectangle (&clip_rect);
mtk_region_intersect_rectangle (clip,
&MTK_RECTANGLE_INIT (x, y, width, height));
clip_rect = mtk_region_get_extents (clip);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
if (clip_rect.width == 0 || clip_rect.height == 0)
return NULL;
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
framebuffer = clutter_stage_view_get_framebuffer (view);
clutter_stage_do_paint_view (stage, view, NULL, clip);
view_scale = clutter_stage_view_get_scale (view);
pixel_width = roundf (clip_rect.width * view_scale);
pixel_height = roundf (clip_rect.height * view_scale);
pixels = g_malloc0 (pixel_width * pixel_height * 4);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
cogl_framebuffer_read_pixels (framebuffer,
clip_rect.x * view_scale,
clip_rect.y * view_scale,
pixel_width, pixel_height,
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
COGL_PIXEL_FORMAT_RGBA_8888,
pixels);
return pixels;
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
}
2006-05-29 08:59:36 +00:00
/**
* clutter_stage_get_actor_at_pos:
* @stage: a #ClutterStage
* @pick_mode: how the scene graph should be painted
* @x: X coordinate to check
* @y: Y coordinate to check
*
* Checks the scene at the coordinates @x and @y and returns a pointer
* to the [class@Clutter.Actor] at those coordinates. The result is the actor which
* would be at the specified location on the next redraw, and is not
* necessarily that which was there on the previous redraw. This allows the
* function to perform chronologically correctly after any queued changes to
* the scene, and even if nothing has been drawn.
*
* By using @pick_mode it is possible to control which actors will be
* painted and thus available.
*
* Return value: (transfer none): the actor at the specified coordinates,
* if any
*/
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
ClutterActor *
clutter_stage_get_actor_at_pos (ClutterStage *stage,
ClutterPickMode pick_mode,
float x,
float y)
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 18:21:59 +00:00
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
return _clutter_stage_do_pick (stage, x, y, pick_mode, NULL);
2006-05-29 08:59:36 +00:00
}
/**
* clutter_stage_set_title:
* @stage: A #ClutterStage
* @title: A utf8 string for the stage windows title.
*
* Sets the stage title.
**/
void
clutter_stage_set_title (ClutterStage *stage,
const gchar *title)
{
ClutterStagePrivate *priv;
ClutterStageWindow *impl;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = clutter_stage_get_instance_private (stage);
g_free (priv->title);
priv->title = g_strdup (title);
impl = CLUTTER_STAGE_WINDOW (priv->impl);
if (CLUTTER_STAGE_WINDOW_GET_IFACE(impl)->set_title != NULL)
CLUTTER_STAGE_WINDOW_GET_IFACE (impl)->set_title (impl, priv->title);
g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_TITLE]);
}
/**
* clutter_stage_get_title:
* @stage: A #ClutterStage
*
* Gets the stage title.
*
* Return value: pointer to the title string for the stage. The
* returned string is owned by the actor and should not
* be modified or freed.
**/
const gchar *
clutter_stage_get_title (ClutterStage *stage)
{
ClutterStagePrivate *priv;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
priv = clutter_stage_get_instance_private (stage);
return priv->title;
}
/**
* clutter_stage_set_key_focus:
* @stage: the #ClutterStage
* @actor: (allow-none): the actor to set key focus to, or %NULL
*
* Sets the key focus on @actor. An actor with key focus will receive
* all the key events. If @actor is %NULL, the stage will receive
* focus.
*/
void
clutter_stage_set_key_focus (ClutterStage *stage,
ClutterActor *actor)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
priv = clutter_stage_get_instance_private (stage);
/* normalize the key focus. NULL == stage */
if (actor == CLUTTER_ACTOR (stage))
actor = NULL;
/* avoid emitting signals and notifications if we're setting the same
* actor as the key focus
*/
if (priv->key_focused_actor == actor)
return;
if (priv->key_focused_actor != NULL)
{
ClutterActor *old_focused_actor;
old_focused_actor = priv->key_focused_actor;
/* set key_focused_actor to NULL before emitting the signal or someone
* might hide the previously focused actor in the signal handler
*/
priv->key_focused_actor = NULL;
_clutter_actor_set_has_key_focus (old_focused_actor, FALSE);
}
else
_clutter_actor_set_has_key_focus (CLUTTER_ACTOR (stage), FALSE);
/* Note, if someone changes key focus in focus-out signal handler we'd be
* overriding the latter call below moving the focus where it was originally
* intended. The order of events would be:
* 1st focus-out, 2nd focus-out (on stage), 2nd focus-in, 1st focus-in
*/
priv->key_focused_actor = actor;
/* If the key focused actor is allowed to receive key events according
* to the given grab (or there is none) set key focus on it, otherwise
* key focus is delayed until there are grabbing conditions that allow
* it to get key focus.
*/
if (!priv->topmost_grab ||
priv->topmost_grab->actor == CLUTTER_ACTOR (stage) ||
priv->topmost_grab->actor == actor ||
(actor && clutter_actor_contains (priv->topmost_grab->actor, actor)))
{
if (actor != NULL)
_clutter_actor_set_has_key_focus (actor, TRUE);
else
_clutter_actor_set_has_key_focus (CLUTTER_ACTOR (stage), TRUE);
}
g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_KEY_FOCUS]);
}
/**
* clutter_stage_get_key_focus:
* @stage: the #ClutterStage
*
* Retrieves the actor that is currently under key focus.
*
* Return value: (transfer none): the actor with key focus, or the stage
*/
ClutterActor *
clutter_stage_get_key_focus (ClutterStage *stage)
{
ClutterStagePrivate *priv;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
priv = clutter_stage_get_instance_private (stage);
if (priv->key_focused_actor)
return priv->key_focused_actor;
return CLUTTER_ACTOR (stage);
}
/*** Perspective boxed type ******/
static gpointer
clutter_perspective_copy (gpointer data)
{
if (G_LIKELY (data))
return g_memdup2 (data, sizeof (ClutterPerspective));
return NULL;
}
static void
clutter_perspective_free (gpointer data)
{
if (G_LIKELY (data))
g_free (data);
}
G_DEFINE_BOXED_TYPE (ClutterPerspective, clutter_perspective,
clutter_perspective_copy,
clutter_perspective_free);
/**
* clutter_stage_ensure_viewport:
* @stage: a #ClutterStage
*
* Ensures that the GL viewport is updated with the current
* stage window size.
*
* This function will queue a redraw of @stage.
*
* This function should not be called by applications; it is used
* when embedding a #ClutterStage into a toolkit with another
* windowing system, like GTK+.
*/
void
clutter_stage_ensure_viewport (ClutterStage *stage)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
_clutter_stage_dirty_viewport (stage);
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
# define _DEG_TO_RAD(d) ((d) * ((float) G_PI / 180.0f))
clutter-stage: Allow a wider range of visible z values Since eef9078f the translation of the camera away from the z=zero plane was hardcoded at 50 which is approximately half way between the default z_near and z_far values. This ended up with quite a small distance in user-space coordinates to the far plane with the default stage size and this was causing test-texture-quality to clip the actor early. This patch makes it try to calculate a reasonable value for the position of the z=0 plane as well as a value for z_far so we maximize the space in between the z=0 plane and the near plane and we have a predictable amount of space behind the stage before hitting the far clipping plane, while considering the trade off of loosing depth precision by pushing the far plane too far back relative to the near plane. With the default fov of 60° it's not possible to use the stage size to define the gap in-front of the stage plane; only ~87% of the stage size is possible as an upper limit. We make 85% of the stage_height available assuming you have a fov of 60°. We consistently provide 10 times the stage height of space behind the stage regardless of the fov. It seems worth noting here that we went around in circles a few times over how to calculate the gaps since there are a number of trade offs to consider and they also affect the complexity of the solution. In the end we went for simplicity but commented the issues well enough hopefully so we can develop a more elaborate solution if we ever have a use-case. http://bugzilla.clutter-project.org/show_bug.cgi?id=2625
2011-06-06 17:40:57 +01:00
/* This calculates a distance into the view frustum to position the
* stage so there is a decent amount of space to position geometry
* between the stage and the near clipping plane.
*
* Some awkward issues with this problem are:
* - It's not possible to have a gap as large as the stage size with
* a fov > 53° which is basically always the case since the default
* fov is 60°.
* - This can be deduced if you consider that this requires a
* triangle as wide as it is deep to fit in the frustum in front
* of the z_near plane. That triangle will always have an angle
* of 53.13° at the point sitting on the z_near plane, but if the
* frustum has a wider fov angle the left/right clipping planes
* can never converge with the two corners of our triangle no
* matter what size the triangle has.
* - With a fov > 53° there is a trade off between maximizing the gap
* size relative to the stage size but not losing depth precision.
clutter-stage: Allow a wider range of visible z values Since eef9078f the translation of the camera away from the z=zero plane was hardcoded at 50 which is approximately half way between the default z_near and z_far values. This ended up with quite a small distance in user-space coordinates to the far plane with the default stage size and this was causing test-texture-quality to clip the actor early. This patch makes it try to calculate a reasonable value for the position of the z=0 plane as well as a value for z_far so we maximize the space in between the z=0 plane and the near plane and we have a predictable amount of space behind the stage before hitting the far clipping plane, while considering the trade off of loosing depth precision by pushing the far plane too far back relative to the near plane. With the default fov of 60° it's not possible to use the stage size to define the gap in-front of the stage plane; only ~87% of the stage size is possible as an upper limit. We make 85% of the stage_height available assuming you have a fov of 60°. We consistently provide 10 times the stage height of space behind the stage regardless of the fov. It seems worth noting here that we went around in circles a few times over how to calculate the gaps since there are a number of trade offs to consider and they also affect the complexity of the solution. In the end we went for simplicity but commented the issues well enough hopefully so we can develop a more elaborate solution if we ever have a use-case. http://bugzilla.clutter-project.org/show_bug.cgi?id=2625
2011-06-06 17:40:57 +01:00
* - Perhaps ideally we wouldn't just consider the fov on the y-axis
* that is usually used to define a perspective, we would consider
* the fov of the axis with the largest stage size so the gap would
* accommodate that size best.
*
* After going around in circles a few times with how to handle these
* issues, we decided in the end to go for the simplest solution to
* start with instead of an elaborate function that handles arbitrary
* fov angles that we currently have no use-case for.
*
* The solution assumes a fovy of 60° and for that case gives a gap
* that's 85% of the stage height. We can consider more elaborate
* functions if necessary later.
*
* One guide we had to steer the gap size we support is the
* interactive test, test-texture-quality which expects to animate an
* actor to +400 on the z axis with a stage size of 640x480. A gap
* that's 85% of the stage height gives a gap of 408 in that case.
*/
static float
calculate_z_translation (float z_near)
{
/* This solution uses fairly basic trigonometry, but is seems worth
* clarifying the particular geometry we are looking at in-case
* anyone wants to develop this further later. Not sure how well an
* ascii diagram is going to work :-)
*
* |--- stage_height ---|
* | stage line |
* ------------
* . (2) . | |
* C . . gap| |
* =0.5° . a . | |
* b(1). D . | |
* B.. near plane | |
* A= ------------- |
* 120° c | z_2d
* z_near |
* left | |
* clip 60°fovy | |
* plane ----------------------
* |
* |
* origin line
*
* The area of interest is the triangle labeled (1) at the top left
* marked with the ... line (a) from where the origin line crosses
* the near plane to the top left where the stage line cross the
* left clip plane.
*
* The sides of the triangle are a, b and c and the corresponding
* angles opposite those sides are A, B and C.
*
* The angle of C is what trades off the gap size we have relative
* to the stage size vs the depth precision we have.
*
* As mentioned above we arove at the angle for C is by working
* backwards from how much space we want for test-texture-quality.
* With a stage_height of 480 we want a gap > 400, ideally we also
* wanted a somewhat round number as a percentage of the height for
* documentation purposes. ~87% or a gap of ~416 is the limit
* because that's where we approach a C angle of 0° and effectively
* loose all depth precision.
*
* So for our test app with a stage_height of 480 if we aim for a
* gap of 408 (85% of 480) we can get the angle D as
* atan (stage_height/2/408) = 30.5°.
*
* That gives us the angle for B as 90° - 30.5° = 59.5°
*
* We can already determine that A has an angle of (fovy/2 + 90°) =
* 120°
*
* Therefore C = 180 - A - B = 0.5°
*
* The length of c = z_near * tan (30°)
*
* Now we can use the rule a/SinA = c/SinC to calculate the
* length of a. After some rearranging that gives us:
*
* a c
* ---------- = ----------
* sin (120°) sin (0.5°)
*
* c * sin (120°)
* a = --------------
* sin (0.5°)
*
* And with that we can determine z_2d = cos (D) * a =
* cos (30.5°) * a + z_near:
*
* c * sin (120°) * cos (30.5°)
* z_2d = --------------------------- + z_near
* sin (0.5°)
*/
/* We expect the compiler should boil this down to z_near * CONSTANT
* already, but just in case we use precomputed constants
*/
#if 0
# define A tanf (_DEG_TO_RAD (30.f))
# define B sinf (_DEG_TO_RAD (120.f))
# define C cosf (_DEG_TO_RAD (30.5f))
# define D sinf (_DEG_TO_RAD (.5f))
#else
# define A 0.57735025882720947265625f
# define B 0.866025388240814208984375f
# define C 0.86162912845611572265625f
# define D 0.00872653536498546600341796875f
#endif
return z_near
* A * B * C
/ D
+ z_near;
clutter-stage: Allow a wider range of visible z values Since eef9078f the translation of the camera away from the z=zero plane was hardcoded at 50 which is approximately half way between the default z_near and z_far values. This ended up with quite a small distance in user-space coordinates to the far plane with the default stage size and this was causing test-texture-quality to clip the actor early. This patch makes it try to calculate a reasonable value for the position of the z=0 plane as well as a value for z_far so we maximize the space in between the z=0 plane and the near plane and we have a predictable amount of space behind the stage before hitting the far clipping plane, while considering the trade off of loosing depth precision by pushing the far plane too far back relative to the near plane. With the default fov of 60° it's not possible to use the stage size to define the gap in-front of the stage plane; only ~87% of the stage size is possible as an upper limit. We make 85% of the stage_height available assuming you have a fov of 60°. We consistently provide 10 times the stage height of space behind the stage regardless of the fov. It seems worth noting here that we went around in circles a few times over how to calculate the gaps since there are a number of trade offs to consider and they also affect the complexity of the solution. In the end we went for simplicity but commented the issues well enough hopefully so we can develop a more elaborate solution if we ever have a use-case. http://bugzilla.clutter-project.org/show_bug.cgi?id=2625
2011-06-06 17:40:57 +01:00
}
static void
view_2d_in_perspective (graphene_matrix_t *matrix,
float fov_y,
float aspect,
float z_near,
float z_2d,
float width_2d,
float height_2d)
{
float top = z_near * tan (fov_y * G_PI / 360.0);
float left = -top * aspect;
float right = top * aspect;
float bottom = -top;
float left_2d_plane = left / z_near * z_2d;
float right_2d_plane = right / z_near * z_2d;
float bottom_2d_plane = bottom / z_near * z_2d;
float top_2d_plane = top / z_near * z_2d;
float width_2d_start = right_2d_plane - left_2d_plane;
float height_2d_start = top_2d_plane - bottom_2d_plane;
/* Factors to scale from framebuffer geometry to frustum
* cross-section geometry. */
float width_scale = width_2d_start / width_2d;
float height_scale = height_2d_start / height_2d;
graphene_matrix_init_scale (matrix, width_scale, -height_scale, width_scale);
graphene_matrix_translate (matrix,
&GRAPHENE_POINT3D_INIT (left_2d_plane,
top_2d_plane,
-z_2d));
}
static void
clutter_stage_update_view_perspective (ClutterStage *stage)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
ClutterPerspective perspective;
float z_2d;
perspective = priv->perspective;
perspective.fovy = 60.0; /* 60 Degrees */
perspective.z_near = 1.0;
perspective.aspect = priv->viewport[2] / priv->viewport[3];
z_2d = calculate_z_translation (perspective.z_near);
/* NB: z_2d is only enough room for 85% of the stage_height between
* the stage and the z_near plane. For behind the stage plane we
* want a more consistent gap of 10 times the stage_height before
* hitting the far plane so we calculate that relative to the final
* height of the stage plane at the z_2d_distance we got... */
perspective.z_far = z_2d +
tanf (_DEG_TO_RAD (perspective.fovy / 2.0f)) * z_2d * 20.0f;
clutter_stage_set_perspective (stage, &perspective);
view_2d_in_perspective (&priv->view,
perspective.fovy,
perspective.aspect,
perspective.z_near,
z_2d,
priv->viewport[2],
priv->viewport[3]);
clutter_actor_invalidate_transform (CLUTTER_ACTOR (stage));
}
void
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
_clutter_stage_maybe_setup_viewport (ClutterStage *stage,
ClutterStageView *view)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
if (clutter_stage_view_is_dirty_viewport (view))
{
MtkRectangle view_layout;
float fb_scale;
float viewport_offset_x;
float viewport_offset_y;
float viewport_x;
float viewport_y;
float viewport_width;
float viewport_height;
CLUTTER_NOTE (PAINT,
"Setting up the viewport { w:%f, h:%f }",
priv->viewport[2],
priv->viewport[3]);
fb_scale = clutter_stage_view_get_scale (view);
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
clutter_stage_view_get_layout (view, &view_layout);
viewport_offset_x = view_layout.x * fb_scale;
viewport_offset_y = view_layout.y * fb_scale;
viewport_x = roundf (priv->viewport[0] * fb_scale - viewport_offset_x);
viewport_y = roundf (priv->viewport[1] * fb_scale - viewport_offset_y);
viewport_width = roundf (priv->viewport[2] * fb_scale);
viewport_height = roundf (priv->viewport[3] * fb_scale);
clutter_stage_view_set_viewport (view,
viewport_x, viewport_y,
viewport_width, viewport_height);
}
Introduce regional stage rendering Add support for drawing a stage using multiple framebuffers each making up one part of the stage. This works by the stage backend (ClutterStageWindow) providing a list of views which will be for splitting up the stage in different regions. A view layout, for now, is a set of rectangles. The stage window (i.e. stage "backend" will use this information when drawing a frame, using one framebuffer for each view. The scene graph is adapted to explictly take a view when painting the stage. It will use this view, its assigned framebuffer and layout to offset and clip the drawing accordingly. This effectively removes any notion of "stage framebuffer", since each stage now may consist of multiple framebuffers. Therefore, API involving this has been deprecated and made no-ops; namely clutter_stage_ensure_context(). Callers are now assumed to either always use a framebuffer reference explicitly, or push/pop the framebuffer of a given view where the code has not yet changed to use the explicit-buffer-using cogl API. Currently only the nested X11 backend supports this mode fully, and the per view framebuffers are all offscreen. Upon frame completion, it'll blit each view's framebuffer onto the onscreen framebuffer before swapping. Other backends (X11 CM and native/KMS) are adapted to manage a full-stage view. The X11 CM backend will continue to use this method, while the native/KMS backend will be adopted to use multiple view drawing. https://bugzilla.gnome.org/show_bug.cgi?id=768976
2016-05-27 11:09:24 +08:00
if (clutter_stage_view_is_dirty_projection (view))
clutter_stage_view_set_projection (view, &priv->projection);
}
#undef _DEG_TO_RAD
/**
* clutter_stage_is_redraw_queued_on_view: (skip)
*/
gboolean
clutter_stage_is_redraw_queued_on_view (ClutterStage *stage,
ClutterStageView *view)
{
clutter_stage_finish_layout (stage);
return clutter_stage_view_has_redraw_clip (view);
}
void
_clutter_stage_set_window (ClutterStage *stage,
ClutterStageWindow *stage_window)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (CLUTTER_IS_STAGE_WINDOW (stage_window));
priv = clutter_stage_get_instance_private (stage);
if (priv->impl != NULL)
g_object_unref (priv->impl);
priv->impl = stage_window;
}
ClutterStageWindow *
_clutter_stage_get_window (ClutterStage *stage)
{
ClutterStagePrivate *priv;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
priv = clutter_stage_get_instance_private (stage);
return CLUTTER_STAGE_WINDOW (priv->impl);
}
2018-10-19 09:15:54 +02:00
/**
* clutter_stage_schedule_update:
* @stage: a #ClutterStage actor
2018-10-19 09:15:54 +02:00
*
* Schedules a redraw of the #ClutterStage at the next optimal timestamp.
*/
void
clutter_stage_schedule_update (ClutterStage *stage)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
ClutterStageWindow *stage_window;
gboolean first_event;
GList *l;
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return;
first_event = priv->event_queue->length == 0;
if (priv->update_scheduled && !first_event)
return;
stage_window = _clutter_stage_get_window (stage);
if (stage_window == NULL)
return;
for (l = clutter_stage_peek_stage_views (stage); l; l = l->next)
{
ClutterStageView *view = l->data;
clutter_stage_view_schedule_update (view);
}
priv->update_scheduled = TRUE;
}
actor: defer queue-redraw signaling Instead of immediately, recursively emitting the "queue-redraw" signal when clutter_actor_queue_redraw is called we now defer this process until all stage updates are complete. This allows us to aggregate repeated _queue_redraw requests for the same actor avoiding redundant paint volume transformations. By deferring we also increase the likelihood that the actor will have a valid paint volume since it will have an up to date allocation; this in turn means we will more often be able to automatically queue clipped redraws which can have a big impact on performance. Here's an outline of the actor queue redraw mechanism: The process starts in clutter_actor_queue_redraw or _clutter_actor_queue_redraw_with_clip. These functions queue an entry in a list associated with the stage which is a list of actors that queued a redraw while updating the timelines, performing layouting and processing other mainloop sources before the next paint starts. We aim to minimize the processing done at this point because there is a good chance other events will happen while updating the scenegraph that would invalidate any expensive work we might otherwise try to do here. For example we don't try and resolve the screen space bounding box of an actor at this stage so as to minimize how much of the screen redraw because it's possible something else will happen which will force a full redraw anyway. When all updates are complete and we come to paint the stage (see _clutter_stage_do_update) then we iterate this list and actually emit the "queue-redraw" signals for each of the listed actors which will bubble up to the stage for each actor and at that point we will transform the actors paint volume into screen coordinates to determine the clip region for what needs to be redrawn in the next paint. Note: actors are allowed to queue a redraw in reseponse to a queue-redraw signal so we repeat the processing of the list until it remains empty. An example of when this happens is for Clone actors or clutter_texture_new_from_actor actors which need to queue a redraw if their source queues a redraw.
2010-09-10 01:33:02 +01:00
void
clutter_stage_add_to_redraw_clip (ClutterStage *stage,
ClutterPaintVolume *redraw_clip)
{
ClutterStageWindow *stage_window;
ClutterActorBox bounding_box;
ClutterActorBox intersection_box;
MtkRectangle geom, stage_clip;
if (CLUTTER_ACTOR_IN_DESTRUCTION (CLUTTER_ACTOR (stage)))
return;
stage_window = _clutter_stage_get_window (stage);
if (stage_window == NULL)
return;
if (is_full_stage_redraw_queued (stage))
return;
if (redraw_clip == NULL)
{
clutter_stage_add_redraw_clip (stage, NULL);
return;
}
if (redraw_clip->is_empty)
return;
/* Now transform and project the clip volume to view coordinates and get
* the axis aligned bounding box that's aligned to the pixel grid.
*/
_clutter_paint_volume_get_stage_paint_box (redraw_clip,
stage,
&bounding_box);
_clutter_stage_window_get_geometry (stage_window, &geom);
intersection_box.x1 = MAX (bounding_box.x1, 0);
intersection_box.y1 = MAX (bounding_box.y1, 0);
intersection_box.x2 = MIN (bounding_box.x2, geom.width);
intersection_box.y2 = MIN (bounding_box.y2, geom.height);
/* There is no need to track degenerate/empty redraw clips */
if (intersection_box.x2 <= intersection_box.x1 ||
intersection_box.y2 <= intersection_box.y1)
return;
stage_clip.x = intersection_box.x1;
stage_clip.y = intersection_box.y1;
stage_clip.width = intersection_box.x2 - stage_clip.x;
stage_clip.height = intersection_box.y2 - stage_clip.y;
clutter_stage_add_redraw_clip (stage, &stage_clip);
}
int64_t
clutter_stage_get_frame_counter (ClutterStage *stage)
{
ClutterStageWindow *stage_window;
stage_window = _clutter_stage_get_window (stage);
return _clutter_stage_window_get_frame_counter (stage_window);
}
void
clutter_stage_presented (ClutterStage *stage,
ClutterStageView *view,
ClutterFrameInfo *frame_info)
{
g_signal_emit (stage, stage_signals[PRESENTED], 0, view, frame_info);
}
/**
* clutter_stage_get_capture_final_size:
* @stage: a #ClutterStage actor
* @rect: a rectangle
* @out_width: (out) (optional): the final width
* @out_height: (out) (optional): the final height
* @out_scale: (out) (optional): the final scale factor
*
* Get the size of the framebuffer one must pass to
* [method@Stage.paint_to_buffer] or [method@Stage.paint_to_framebuffer]
* would be used with the same @rect.
*
* Returns: %TRUE if the size has been retrieved, %FALSE otherwise.
*/
gboolean
clutter_stage_get_capture_final_size (ClutterStage *stage,
MtkRectangle *rect,
int *out_width,
int *out_height,
float *out_scale)
{
float max_scale = 1.0;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
if (rect)
{
graphene_rect_t capture_rect;
g_autoptr (GList) views = NULL;
GList *l;
capture_rect = mtk_rectangle_to_graphene_rect (rect);
views = clutter_stage_get_views_for_rect (stage, &capture_rect);
if (!views)
return FALSE;
for (l = views; l; l = l->next)
{
ClutterStageView *view = l->data;
max_scale = MAX (clutter_stage_view_get_scale (view), max_scale);
}
if (out_width)
*out_width = (gint) roundf (rect->width * max_scale);
if (out_height)
*out_height = (gint) roundf (rect->height * max_scale);
}
else
{
ClutterActorBox alloc;
float stage_width, stage_height;
clutter_actor_get_allocation_box (CLUTTER_ACTOR (stage), &alloc);
clutter_actor_box_get_size (&alloc, &stage_width, &stage_height);
max_scale = clutter_actor_get_real_resource_scale (CLUTTER_ACTOR (stage));
if (out_width)
*out_width = (gint) roundf (stage_width * max_scale);
if (out_height)
*out_height = (gint) roundf (stage_height * max_scale);
}
if (out_scale)
*out_scale = max_scale;
return TRUE;
}
void
clutter_stage_paint_to_framebuffer (ClutterStage *stage,
CoglFramebuffer *framebuffer,
const MtkRectangle *rect,
float scale,
ClutterPaintFlag paint_flags)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
ClutterPaintContext *paint_context;
g_autoptr (MtkRegion) redraw_clip = NULL;
COGL_TRACE_BEGIN_SCOPED (PaintToFramebuffer,
"Clutter::Stage::paint_to_framebuffer()");
if (paint_flags & CLUTTER_PAINT_FLAG_CLEAR)
{
CoglColor clear_color;
cogl_color_init_from_4f (&clear_color, 0.0, 0.0, 0.0, 0.0);
cogl_framebuffer_clear (framebuffer, COGL_BUFFER_BIT_COLOR, &clear_color);
}
redraw_clip = mtk_region_create_rectangle (rect);
paint_context =
clutter_paint_context_new_for_framebuffer (framebuffer,
redraw_clip,
paint_flags);
cogl_framebuffer_push_matrix (framebuffer);
cogl_framebuffer_set_projection_matrix (framebuffer, &priv->projection);
cogl_framebuffer_set_viewport (framebuffer,
-(rect->x * scale),
-(rect->y * scale),
priv->viewport[2] * scale,
priv->viewport[3] * scale);
clutter_actor_paint (CLUTTER_ACTOR (stage), paint_context);
cogl_framebuffer_pop_matrix (framebuffer);
clutter_paint_context_destroy (paint_context);
}
/**
* clutter_stage_paint_to_buffer:
* @stage: a #ClutterStage actor
* @rect: a rectangle
* @scale: the scale
* @data: (array) (element-type guint8): a pointer to the data
* @stride: stride of the image surface
* @format: the pixel format
* @paint_flags: the #ClutterPaintFlag
* @error: the error
*
* Take a snapshot of the stage to a provided buffer.
*
* Returns: %TRUE is the buffer has been paint successfully, %FALSE otherwise.
*/
gboolean
clutter_stage_paint_to_buffer (ClutterStage *stage,
const MtkRectangle *rect,
float scale,
uint8_t *data,
int stride,
CoglPixelFormat format,
ClutterPaintFlag paint_flags,
GError **error)
{
ClutterBackend *clutter_backend = clutter_get_default_backend ();
CoglContext *cogl_context =
clutter_backend_get_cogl_context (clutter_backend);
int texture_width, texture_height;
CoglTexture *texture;
CoglOffscreen *offscreen;
CoglFramebuffer *framebuffer;
CoglBitmap *bitmap;
texture_width = (int) roundf (rect->width * scale);
texture_height = (int) roundf (rect->height * scale);
texture = cogl_texture_2d_new_with_size (cogl_context,
texture_width,
texture_height);
if (!texture)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to create %dx%d texture",
texture_width, texture_height);
return FALSE;
}
offscreen = cogl_offscreen_new_with_texture (texture);
framebuffer = COGL_FRAMEBUFFER (offscreen);
g_object_unref (texture);
if (!cogl_framebuffer_allocate (framebuffer, error))
return FALSE;
clutter_stage_paint_to_framebuffer (stage, framebuffer,
rect, scale, paint_flags);
bitmap = cogl_bitmap_new_for_data (cogl_context,
texture_width, texture_height,
format,
stride,
data);
cogl_framebuffer_read_pixels_into_bitmap (framebuffer,
0, 0,
COGL_READ_PIXELS_COLOR_BUFFER,
bitmap);
g_object_unref (bitmap);
g_object_unref (framebuffer);
return TRUE;
}
/**
* clutter_stage_paint_to_content:
* @stage: a #ClutterStage actor
* @rect: a rectangle
* @scale: the scale
* @paint_flags: the #ClutterPaintFlag
* @error: the error
*
* Take a snapshot of the stage to a #ClutterContent.
*
* Returns: (transfer full): the #ClutterContent or %NULL on error.
*/
ClutterContent *
clutter_stage_paint_to_content (ClutterStage *stage,
const MtkRectangle *rect,
float scale,
ClutterPaintFlag paint_flags,
GError **error)
{
ClutterBackend *clutter_backend = clutter_get_default_backend ();
CoglContext *cogl_context =
clutter_backend_get_cogl_context (clutter_backend);
int texture_width, texture_height;
CoglTexture *texture;
CoglOffscreen *offscreen;
g_autoptr (CoglFramebuffer) framebuffer = NULL;
texture_width = (int) roundf (rect->width * scale);
texture_height = (int) roundf (rect->height * scale);
texture = cogl_texture_2d_new_with_size (cogl_context,
texture_width,
texture_height);
if (!texture)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to create %dx%d texture",
texture_width, texture_height);
return NULL;
}
offscreen = cogl_offscreen_new_with_texture (texture);
framebuffer = COGL_FRAMEBUFFER (offscreen);
g_object_unref (texture);
if (!cogl_framebuffer_allocate (framebuffer, error))
return NULL;
clutter_stage_paint_to_framebuffer (stage, framebuffer,
rect, scale, paint_flags);
return clutter_texture_content_new_from_texture (cogl_offscreen_get_texture (offscreen),
NULL);
}
void
clutter_stage_capture_view_into (ClutterStage *stage,
ClutterStageView *view,
MtkRectangle *rect,
uint8_t *data,
int stride)
{
CoglFramebuffer *framebuffer;
ClutterBackend *backend;
CoglContext *context;
CoglBitmap *bitmap;
MtkRectangle view_layout;
float view_scale;
float texture_width;
float texture_height;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
framebuffer = clutter_stage_view_get_framebuffer (view);
clutter_stage_view_get_layout (view, &view_layout);
if (!rect)
rect = &view_layout;
view_scale = clutter_stage_view_get_scale (view);
texture_width = roundf (rect->width * view_scale);
texture_height = roundf (rect->height * view_scale);
backend = clutter_get_default_backend ();
context = clutter_backend_get_cogl_context (backend);
bitmap = cogl_bitmap_new_for_data (context,
texture_width, texture_height,
COGL_PIXEL_FORMAT_CAIRO_ARGB32_COMPAT,
stride,
data);
cogl_framebuffer_read_pixels_into_bitmap (framebuffer,
roundf ((rect->x - view_layout.x) * view_scale),
roundf ((rect->y - view_layout.y) * view_scale),
COGL_READ_PIXELS_COLOR_BUFFER,
bitmap);
g_object_unref (bitmap);
}
/**
* clutter_stage_peek_stage_views: (skip)
*/
GList *
clutter_stage_peek_stage_views (ClutterStage *stage)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
return _clutter_stage_window_get_views (priv->impl);
}
void
clutter_stage_clear_stage_views (ClutterStage *stage)
{
clutter_actor_clear_stage_views_recursive (CLUTTER_ACTOR (stage), FALSE);
}
GList *
clutter_stage_get_views_for_rect (ClutterStage *stage,
const graphene_rect_t *rect)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
GList *views_for_rect = NULL;
GList *l;
for (l = _clutter_stage_window_get_views (priv->impl); l; l = l->next)
{
ClutterStageView *view = l->data;
MtkRectangle view_layout;
graphene_rect_t view_rect;
clutter_stage_view_get_layout (view, &view_layout);
view_rect = mtk_rectangle_to_graphene_rect (&view_layout);
if (graphene_rect_intersection (&view_rect, rect, NULL))
views_for_rect = g_list_prepend (views_for_rect, view);
}
return views_for_rect;
}
clutter: Add private API to support resource scale affecting layout For ClutterText, the resource scale the text is drawn with affects the size of the allocation: ClutterText will choose a font scale based on the resource scale, and that font scale can lead to a slight difference in size compared to the unscaled font. We currently handle that by queuing a relayout inside the "resource-scale-changed" signal handler. This solution is a bit problematic though since it will take one more allocation cycle until the allocation is actually updated after a scale-change, so the actor is painted using the wrong allocation for one frame. Also the current solution can lead to relayout loops in a few cases, for example if a ClutterText is located near the edge on a 1x scaled monitor and is moved to intersect a 2x scaled monitor: Now the resource scale will change to 2 and a new allocation box is calculated; if this allocation box is slightly smaller than the old one because of the new font scale, the allocation won't intersect the 2x scaled monitor again and the resource scale switches back to 1. Now the allocation gets larger again and intersects the 2x scaled monitor again. This commit introduces a way to properly support those actors: In case an actors resource scale might affect its allocation, it should call the private function clutter_actor_queue_immediate_relayout(). This will make sure the actor gets a relayout before the upcoming paint happens afte every resource scale change. Also potential relayout loops can be handled by the actors themselves using a "phase" argument that's passed to implementations of the calculate_resource_scale() vfunc. The new API is private because resource scales are not meant to be used in a way where the scale affects the allocation. With ClutterText and the current behavior of Pango, that can't be avoid though, so we need it anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
2020-04-10 14:54:11 +02:00
void
clutter_stage_set_actor_needs_immediate_relayout (ClutterStage *stage)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
clutter: Add private API to support resource scale affecting layout For ClutterText, the resource scale the text is drawn with affects the size of the allocation: ClutterText will choose a font scale based on the resource scale, and that font scale can lead to a slight difference in size compared to the unscaled font. We currently handle that by queuing a relayout inside the "resource-scale-changed" signal handler. This solution is a bit problematic though since it will take one more allocation cycle until the allocation is actually updated after a scale-change, so the actor is painted using the wrong allocation for one frame. Also the current solution can lead to relayout loops in a few cases, for example if a ClutterText is located near the edge on a 1x scaled monitor and is moved to intersect a 2x scaled monitor: Now the resource scale will change to 2 and a new allocation box is calculated; if this allocation box is slightly smaller than the old one because of the new font scale, the allocation won't intersect the 2x scaled monitor again and the resource scale switches back to 1. Now the allocation gets larger again and intersects the 2x scaled monitor again. This commit introduces a way to properly support those actors: In case an actors resource scale might affect its allocation, it should call the private function clutter_actor_queue_immediate_relayout(). This will make sure the actor gets a relayout before the upcoming paint happens afte every resource scale change. Also potential relayout loops can be handled by the actors themselves using a "phase" argument that's passed to implementations of the calculate_resource_scale() vfunc. The new API is private because resource scales are not meant to be used in a way where the scale affects the allocation. With ClutterText and the current behavior of Pango, that can't be avoid though, so we need it anyway. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
2020-04-10 14:54:11 +02:00
priv->actor_needs_immediate_relayout = TRUE;
}
void
clutter_stage_maybe_invalidate_focus (ClutterStage *self,
ClutterActor *actor)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
GHashTableIter iter;
gpointer value;
if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
return;
g_hash_table_iter_init (&iter, priv->pointer_devices);
while (g_hash_table_iter_next (&iter, NULL, &value))
{
PointerDeviceEntry *entry = value;
if (entry->current_actor != actor)
continue;
clutter_stage_pick_and_update_device (self,
entry->device,
NULL, NULL,
CLUTTER_DEVICE_UPDATE_IGNORE_CACHE |
CLUTTER_DEVICE_UPDATE_EMIT_CROSSING,
entry->coords,
CLUTTER_CURRENT_TIME);
}
g_hash_table_iter_init (&iter, priv->touch_sequences);
while (g_hash_table_iter_next (&iter, NULL, &value))
{
PointerDeviceEntry *entry = value;
if (entry->current_actor != actor)
continue;
clutter_stage_pick_and_update_device (self,
entry->device,
entry->sequence,
NULL,
CLUTTER_DEVICE_UPDATE_IGNORE_CACHE |
CLUTTER_DEVICE_UPDATE_EMIT_CROSSING,
entry->coords,
CLUTTER_CURRENT_TIME);
}
}
void
clutter_stage_invalidate_focus (ClutterStage *self,
ClutterActor *actor)
{
if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
return;
g_assert (!clutter_actor_is_mapped (actor) || !clutter_actor_get_reactive (actor));
clutter_stage_maybe_invalidate_focus (self, actor);
if (actor != CLUTTER_ACTOR (self))
g_assert (!clutter_actor_has_pointer (actor));
}
static void
free_pointer_device_entry (PointerDeviceEntry *entry)
{
if (entry->current_actor)
_clutter_actor_set_has_pointer (entry->current_actor, FALSE);
g_clear_pointer (&entry->clear_area, mtk_region_unref);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
g_assert (!entry->press_count);
g_assert (entry->event_emission_chain->len == 0);
g_array_unref (entry->event_emission_chain);
g_free (entry);
}
static void
clutter_stage_update_device_entry (ClutterStage *self,
ClutterInputDevice *device,
ClutterEventSequence *sequence,
graphene_point_t coords,
ClutterActor *actor,
MtkRegion *clear_area)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
PointerDeviceEntry *entry = NULL;
g_assert (device != NULL);
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
if (!entry)
{
entry = g_new0 (PointerDeviceEntry, 1);
if (sequence != NULL)
g_hash_table_insert (priv->touch_sequences, sequence, entry);
else
g_hash_table_insert (priv->pointer_devices, device, entry);
entry->stage = self;
entry->device = device;
entry->sequence = sequence;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
entry->press_count = 0;
entry->implicit_grab_actor = NULL;
entry->event_emission_chain =
g_array_sized_new (FALSE, TRUE, sizeof (EventReceiver), 32);
g_array_set_clear_func (entry->event_emission_chain,
(GDestroyNotify) free_event_receiver);
}
entry->coords = coords;
if (entry->current_actor != actor)
{
if (entry->current_actor)
_clutter_actor_set_has_pointer (entry->current_actor, FALSE);
entry->current_actor = actor;
if (actor)
_clutter_actor_set_has_pointer (actor, TRUE);
}
g_clear_pointer (&entry->clear_area, mtk_region_unref);
if (clear_area)
entry->clear_area = mtk_region_ref (clear_area);
}
void
clutter_stage_remove_device_entry (ClutterStage *self,
ClutterInputDevice *device,
ClutterEventSequence *sequence)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
gboolean removed;
g_assert (device != NULL);
if (sequence != NULL)
removed = g_hash_table_remove (priv->touch_sequences, sequence);
else
removed = g_hash_table_remove (priv->pointer_devices, device);
g_assert (removed);
}
/**
* clutter_stage_get_device_actor:
* @stage: a #ClutterStage
* @device: a #ClutterInputDevice
* @sequence: (allow-none): an optional #ClutterEventSequence
*
* Retrieves the [class@Clutter.Actor] underneath the pointer or touch point
* of @device and @sequence.
*
* Returns: (transfer none) (nullable): a pointer to the #ClutterActor or %NULL
*/
ClutterActor *
clutter_stage_get_device_actor (ClutterStage *stage,
ClutterInputDevice *device,
ClutterEventSequence *sequence)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
PointerDeviceEntry *entry = NULL;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
g_return_val_if_fail (device != NULL, NULL);
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
if (entry)
return entry->current_actor;
return NULL;
}
/**
* clutter_stage_get_device_coords: (skip):
*/
gboolean
clutter_stage_get_device_coords (ClutterStage *stage,
ClutterInputDevice *device,
ClutterEventSequence *sequence,
graphene_point_t *coords)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
PointerDeviceEntry *entry = NULL;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
g_return_val_if_fail (device != NULL, FALSE);
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
if (!entry)
return FALSE;
if (coords)
*coords = entry->coords;
return TRUE;
}
static void
clutter_stage_set_device_coords (ClutterStage *stage,
ClutterInputDevice *device,
ClutterEventSequence *sequence,
graphene_point_t coords)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
PointerDeviceEntry *entry = NULL;
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
if (entry)
entry->coords = coords;
}
static ClutterActor *
find_common_root_actor (ClutterStage *stage,
ClutterActor *a,
ClutterActor *b)
{
if (a && b)
{
while (a)
{
if (a == b || clutter_actor_contains (a, b))
return a;
a = clutter_actor_get_parent (a);
}
}
return CLUTTER_ACTOR (stage);
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
static inline void
add_actor_to_event_emission_chain (GArray *chain,
ClutterActor *actor,
ClutterEventPhase phase)
{
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
EventReceiver *receiver;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
g_array_set_size (chain, chain->len + 1);
receiver = &g_array_index (chain, EventReceiver, chain->len - 1);
receiver->actor = g_object_ref (actor);
receiver->phase = phase;
}
static inline void
add_action_to_event_emission_chain (GArray *chain,
ClutterAction *action)
{
EventReceiver *receiver;
g_array_set_size (chain, chain->len + 1);
receiver = &g_array_index (chain, EventReceiver, chain->len - 1);
receiver->action = g_object_ref (action);
}
static void
create_event_emission_chain (ClutterStage *stage,
GArray *chain,
ClutterActor *topmost,
ClutterActor *deepmost)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
int i;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
g_assert (priv->cur_event_actors->len == 0);
clutter_actor_collect_event_actors (topmost, deepmost, priv->cur_event_actors);
for (i = priv->cur_event_actors->len - 1; i >= 0; i--)
{
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
ClutterActor *actor = g_ptr_array_index (priv->cur_event_actors, i);
const GList *l;
for (l = clutter_actor_peek_actions (actor); l; l = l->next)
{
ClutterAction *action = l->data;
if (clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (action)) &&
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
clutter_action_get_phase (action) == CLUTTER_PHASE_CAPTURE)
add_action_to_event_emission_chain (chain, action);
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
add_actor_to_event_emission_chain (chain, actor, CLUTTER_PHASE_CAPTURE);
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
for (i = 0; i < priv->cur_event_actors->len; i++)
{
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
ClutterActor *actor = g_ptr_array_index (priv->cur_event_actors, i);
const GList *l;
for (l = clutter_actor_peek_actions (actor); l; l = l->next)
{
ClutterAction *action = l->data;
if (clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (action)) &&
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
clutter_action_get_phase (action) == CLUTTER_PHASE_BUBBLE)
add_action_to_event_emission_chain (chain, action);
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
add_actor_to_event_emission_chain (chain, actor, CLUTTER_PHASE_BUBBLE);
}
priv->cur_event_actors->len = 0;
}
typedef enum
{
EVENT_NOT_HANDLED,
EVENT_HANDLED_BY_ACTOR,
EVENT_HANDLED_BY_ACTION
} EventHandledState;
static EventHandledState
emit_event (const ClutterEvent *event,
GArray *event_emission_chain)
{
unsigned int i;
for (i = 0; i < event_emission_chain->len; i++)
{
EventReceiver *receiver =
&g_array_index (event_emission_chain, EventReceiver, i);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
if (receiver->actor)
{
if (clutter_actor_event (receiver->actor, event, receiver->phase == CLUTTER_PHASE_CAPTURE))
return EVENT_HANDLED_BY_ACTOR;
}
else if (receiver->action)
{
if (clutter_action_handle_event (receiver->action, event))
return EVENT_HANDLED_BY_ACTION;
}
}
return EVENT_NOT_HANDLED;
}
static void
clutter_stage_emit_crossing_event (ClutterStage *self,
const ClutterEvent *event,
ClutterActor *deepmost,
ClutterActor *topmost)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
ClutterInputDevice *device = clutter_event_get_device (event);
ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
PointerDeviceEntry *entry;
if (topmost == NULL)
topmost = CLUTTER_ACTOR (self);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
g_assert (entry != NULL);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
if (entry->press_count &&
!(clutter_event_get_flags (event) & CLUTTER_EVENT_FLAG_GRAB_NOTIFY))
{
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
emit_event (event, entry->event_emission_chain);
}
else
{
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
gboolean in_event_emission;
GArray *event_emission_chain;
/* Crossings can happen while we're in the middle of event emission
* (for example when an actor goes unmapped or gets grabbed), so we
* can't reuse priv->cur_event_emission_chain here, it might already be in use.
*/
in_event_emission = priv->cur_event_emission_chain->len != 0;
if (in_event_emission)
{
event_emission_chain =
g_array_sized_new (FALSE, TRUE, sizeof (EventReceiver), 32);
g_array_set_clear_func (event_emission_chain,
(GDestroyNotify) free_event_receiver);
}
else
{
event_emission_chain = g_array_ref (priv->cur_event_emission_chain);
}
create_event_emission_chain (self, event_emission_chain, topmost, deepmost);
emit_event (event, event_emission_chain);
g_array_remove_range (event_emission_chain, 0, event_emission_chain->len);
g_array_unref (event_emission_chain);
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
}
static void
sync_crossings_on_implicit_grab_end (ClutterStage *self,
PointerDeviceEntry *entry)
{
ClutterActor *deepmost, *topmost;
ClutterActor *parent;
ClutterEvent *crossing;
deepmost = entry->current_actor;
if (clutter_actor_contains (entry->current_actor, entry->implicit_grab_actor))
return;
topmost = entry->current_actor;
while ((parent = clutter_actor_get_parent (topmost)))
{
if (clutter_actor_contains (parent, entry->implicit_grab_actor))
break;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
topmost = parent;
}
crossing = clutter_event_crossing_new (CLUTTER_ENTER,
CLUTTER_EVENT_FLAG_GRAB_NOTIFY,
CLUTTER_CURRENT_TIME,
entry->device,
entry->sequence,
entry->coords,
entry->current_actor,
NULL);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
if (!_clutter_event_process_filters (crossing, deepmost))
{
clutter_stage_emit_crossing_event (self,
crossing,
deepmost,
topmost);
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
clutter_event_free (crossing);
}
void
clutter_stage_update_device (ClutterStage *stage,
ClutterInputDevice *device,
ClutterEventSequence *sequence,
ClutterInputDevice *source_device,
graphene_point_t point,
uint32_t time_ms,
ClutterActor *new_actor,
MtkRegion *clear_area,
gboolean emit_crossing)
{
ClutterInputDeviceType device_type;
ClutterActor *old_actor, *root;
gboolean device_actor_changed;
ClutterEvent *event;
device_type = clutter_input_device_get_device_type (device);
g_assert (device_type != CLUTTER_KEYBOARD_DEVICE &&
device_type != CLUTTER_PAD_DEVICE);
old_actor = clutter_stage_get_device_actor (stage, device, sequence);
device_actor_changed = new_actor != old_actor;
if (!source_device)
source_device = device;
clutter_stage_update_device_entry (stage,
device, sequence,
point,
new_actor,
clear_area);
if (device_actor_changed)
{
CLUTTER_NOTE (EVENT,
"Updating actor under cursor (device %s, at %.2f, %.2f): %s",
clutter_input_device_get_device_name (device),
point.x,
point.y,
_clutter_actor_get_debug_name (new_actor));
if (emit_crossing)
{
ClutterActor *grab_actor;
root = find_common_root_actor (stage, new_actor, old_actor);
grab_actor = clutter_stage_get_grab_actor (stage);
/* If the common root is outside the currently effective grab,
* it involves actors outside the grabbed actor hierarchy, the
* events should be propagated from/inside the grab actor.
*/
if (grab_actor &&
root != grab_actor &&
!clutter_actor_contains (grab_actor, root))
root = grab_actor;
}
/* we need to make sure that this event is processed
* before any other event we might have queued up until
* now, so we go on, and synthesize the event emission
* ourselves
*/
if (old_actor && emit_crossing)
{
event = clutter_event_crossing_new (CLUTTER_LEAVE,
CLUTTER_EVENT_NONE,
ms2us (time_ms),
source_device,
sequence,
point,
old_actor,
new_actor);
if (!_clutter_event_process_filters (event, old_actor))
{
clutter_stage_emit_crossing_event (stage,
event,
old_actor,
root);
}
clutter_event_free (event);
}
if (new_actor && emit_crossing)
{
event = clutter_event_crossing_new (CLUTTER_ENTER,
CLUTTER_EVENT_NONE,
ms2us (time_ms),
source_device,
sequence,
point,
new_actor,
old_actor);
if (!_clutter_event_process_filters (event, new_actor))
{
clutter_stage_emit_crossing_event (stage,
event,
new_actor,
root);
}
clutter_event_free (event);
}
}
}
void
clutter_stage_repick_device (ClutterStage *stage,
ClutterInputDevice *device)
{
graphene_point_t point = GRAPHENE_POINT_INIT_ZERO;
if (!clutter_stage_get_device_coords (stage, device, NULL, &point))
return;
clutter_stage_pick_and_update_device (stage,
device,
NULL, NULL,
CLUTTER_DEVICE_UPDATE_IGNORE_CACHE |
CLUTTER_DEVICE_UPDATE_EMIT_CROSSING,
point,
CLUTTER_CURRENT_TIME);
}
static gboolean
clutter_stage_check_in_clear_area (ClutterStage *stage,
ClutterInputDevice *device,
ClutterEventSequence *sequence,
graphene_point_t point)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
PointerDeviceEntry *entry = NULL;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
g_return_val_if_fail (device != NULL, FALSE);
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
if (!entry)
return FALSE;
if (!entry->clear_area)
return FALSE;
return mtk_region_contains_point (entry->clear_area,
point.x, point.y);
}
ClutterActor *
clutter_stage_pick_and_update_device (ClutterStage *stage,
ClutterInputDevice *device,
ClutterEventSequence *sequence,
ClutterInputDevice *source_device,
ClutterDeviceUpdateFlags flags,
graphene_point_t point,
uint32_t time_ms)
{
ClutterActor *new_actor = NULL;
MtkRegion *clear_area = NULL;
ClutterSeat *seat;
seat = clutter_input_device_get_seat (device);
if (sequence ||
device != clutter_seat_get_pointer (seat) ||
clutter_seat_is_unfocus_inhibited (seat))
{
if ((flags & CLUTTER_DEVICE_UPDATE_IGNORE_CACHE) == 0)
{
if (clutter_stage_check_in_clear_area (stage, device,
sequence, point))
{
clutter_stage_set_device_coords (stage, device,
sequence, point);
return clutter_stage_get_device_actor (stage, device, sequence);
}
}
new_actor = _clutter_stage_do_pick (stage,
point.x,
point.y,
CLUTTER_PICK_REACTIVE,
&clear_area);
/* Picking should never fail, but if it does, we bail out here */
g_return_val_if_fail (new_actor != NULL, NULL);
}
clutter_stage_update_device (stage,
device, sequence,
source_device,
point,
time_ms,
new_actor,
clear_area,
!!(flags & CLUTTER_DEVICE_UPDATE_EMIT_CROSSING));
g_clear_pointer (&clear_area, mtk_region_unref);
return new_actor;
}
static void
cleanup_implicit_grab (PointerDeviceEntry *entry)
{
clutter_actor_set_implicitly_grabbed (entry->implicit_grab_actor, FALSE);
entry->implicit_grab_actor = NULL;
g_array_remove_range (entry->event_emission_chain, 0,
entry->event_emission_chain->len);
entry->press_count = 0;
}
static void
clutter_stage_notify_grab_on_pointer_entry (ClutterStage *stage,
PointerDeviceEntry *entry,
ClutterActor *grab_actor,
ClutterActor *old_grab_actor)
{
gboolean pointer_in_grab, pointer_in_old_grab;
gboolean implicit_grab_cancelled = FALSE;
clutter/stage: Don't set implicit_grab_cancelled to TRUE if there are none The assertion for !implicit_grab_cancelled in the `grab_actor == old_grab_actor` case of clutter_stage_notify_grab_on_pointer_entry() is meant to do a simple sanity-check to ensure the grab machinery is working as intended: During a seat grab, all input gets delivered to the tree inside the grab, and all implicit grabs outside of that tree are cancelled. When a new seat grab on the same actor as the existing one happens, we run through the cancellation machinery for implicit grabs anyway, so we might as well check that the assumption mentioned above holds true: By asserting that no implicit grabs were cancelled, we know that no implicit grabs exist outside of the existing seat grab tree. This assertion is slightly over-eager though due to the way we set implicit_grab_cancelled: We initialize it to TRUE in the entry->press_count > 0 case and then only set it to FALSE once we find an implicit grab that may remain active. If there are no implicit grabs though (while entry->press_count is still >0), we never set implicit_grab_cancelled to FALSE, triggering the assertion in question even though no implicit grabs got cancelled. There's two possible solutions for this: Either dropping the assertion, or refactoring it so it observes the situation where the implicit grabs were already undone. This commit implements the latter. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2700 Fixes: debbd88f8c8 ("clutter/stage: Cancel parts of implicit grabs when ClutterGrabs happen") Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3216>
2023-08-27 13:44:06 +02:00
unsigned int implicit_grab_n_removed = 0, implicit_grab_n_remaining = 0;
ClutterEventType event_type = CLUTTER_NOTHING;
ClutterActor *topmost, *deepmost;
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
if (!entry->current_actor)
return;
pointer_in_grab =
!grab_actor ||
grab_actor == entry->current_actor ||
clutter_actor_contains (grab_actor, entry->current_actor);
pointer_in_old_grab =
!old_grab_actor ||
old_grab_actor == entry->current_actor ||
clutter_actor_contains (old_grab_actor, entry->current_actor);
if (grab_actor && entry->press_count > 0)
{
ClutterInputDevice *device = entry->device;
ClutterEventSequence *sequence = entry->sequence;
unsigned int i;
for (i = 0; i < entry->event_emission_chain->len; i++)
{
EventReceiver *receiver =
&g_array_index (entry->event_emission_chain, EventReceiver, i);
if (receiver->actor)
{
if (!clutter_actor_contains (grab_actor, receiver->actor))
{
g_clear_object (&receiver->actor);
clutter/stage: Don't set implicit_grab_cancelled to TRUE if there are none The assertion for !implicit_grab_cancelled in the `grab_actor == old_grab_actor` case of clutter_stage_notify_grab_on_pointer_entry() is meant to do a simple sanity-check to ensure the grab machinery is working as intended: During a seat grab, all input gets delivered to the tree inside the grab, and all implicit grabs outside of that tree are cancelled. When a new seat grab on the same actor as the existing one happens, we run through the cancellation machinery for implicit grabs anyway, so we might as well check that the assumption mentioned above holds true: By asserting that no implicit grabs were cancelled, we know that no implicit grabs exist outside of the existing seat grab tree. This assertion is slightly over-eager though due to the way we set implicit_grab_cancelled: We initialize it to TRUE in the entry->press_count > 0 case and then only set it to FALSE once we find an implicit grab that may remain active. If there are no implicit grabs though (while entry->press_count is still >0), we never set implicit_grab_cancelled to FALSE, triggering the assertion in question even though no implicit grabs got cancelled. There's two possible solutions for this: Either dropping the assertion, or refactoring it so it observes the situation where the implicit grabs were already undone. This commit implements the latter. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2700 Fixes: debbd88f8c8 ("clutter/stage: Cancel parts of implicit grabs when ClutterGrabs happen") Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3216>
2023-08-27 13:44:06 +02:00
implicit_grab_n_removed++;
}
else
{
clutter/stage: Don't set implicit_grab_cancelled to TRUE if there are none The assertion for !implicit_grab_cancelled in the `grab_actor == old_grab_actor` case of clutter_stage_notify_grab_on_pointer_entry() is meant to do a simple sanity-check to ensure the grab machinery is working as intended: During a seat grab, all input gets delivered to the tree inside the grab, and all implicit grabs outside of that tree are cancelled. When a new seat grab on the same actor as the existing one happens, we run through the cancellation machinery for implicit grabs anyway, so we might as well check that the assumption mentioned above holds true: By asserting that no implicit grabs were cancelled, we know that no implicit grabs exist outside of the existing seat grab tree. This assertion is slightly over-eager though due to the way we set implicit_grab_cancelled: We initialize it to TRUE in the entry->press_count > 0 case and then only set it to FALSE once we find an implicit grab that may remain active. If there are no implicit grabs though (while entry->press_count is still >0), we never set implicit_grab_cancelled to FALSE, triggering the assertion in question even though no implicit grabs got cancelled. There's two possible solutions for this: Either dropping the assertion, or refactoring it so it observes the situation where the implicit grabs were already undone. This commit implements the latter. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2700 Fixes: debbd88f8c8 ("clutter/stage: Cancel parts of implicit grabs when ClutterGrabs happen") Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3216>
2023-08-27 13:44:06 +02:00
implicit_grab_n_remaining++;
}
}
else if (receiver->action)
{
ClutterActor *action_actor =
clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (receiver->action));
if (!action_actor || !clutter_actor_contains (grab_actor, action_actor))
{
clutter_action_sequence_cancelled (receiver->action,
device,
sequence);
g_clear_object (&receiver->action);
clutter/stage: Don't set implicit_grab_cancelled to TRUE if there are none The assertion for !implicit_grab_cancelled in the `grab_actor == old_grab_actor` case of clutter_stage_notify_grab_on_pointer_entry() is meant to do a simple sanity-check to ensure the grab machinery is working as intended: During a seat grab, all input gets delivered to the tree inside the grab, and all implicit grabs outside of that tree are cancelled. When a new seat grab on the same actor as the existing one happens, we run through the cancellation machinery for implicit grabs anyway, so we might as well check that the assumption mentioned above holds true: By asserting that no implicit grabs were cancelled, we know that no implicit grabs exist outside of the existing seat grab tree. This assertion is slightly over-eager though due to the way we set implicit_grab_cancelled: We initialize it to TRUE in the entry->press_count > 0 case and then only set it to FALSE once we find an implicit grab that may remain active. If there are no implicit grabs though (while entry->press_count is still >0), we never set implicit_grab_cancelled to FALSE, triggering the assertion in question even though no implicit grabs got cancelled. There's two possible solutions for this: Either dropping the assertion, or refactoring it so it observes the situation where the implicit grabs were already undone. This commit implements the latter. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2700 Fixes: debbd88f8c8 ("clutter/stage: Cancel parts of implicit grabs when ClutterGrabs happen") Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3216>
2023-08-27 13:44:06 +02:00
implicit_grab_n_removed++;
}
else
{
clutter/stage: Don't set implicit_grab_cancelled to TRUE if there are none The assertion for !implicit_grab_cancelled in the `grab_actor == old_grab_actor` case of clutter_stage_notify_grab_on_pointer_entry() is meant to do a simple sanity-check to ensure the grab machinery is working as intended: During a seat grab, all input gets delivered to the tree inside the grab, and all implicit grabs outside of that tree are cancelled. When a new seat grab on the same actor as the existing one happens, we run through the cancellation machinery for implicit grabs anyway, so we might as well check that the assumption mentioned above holds true: By asserting that no implicit grabs were cancelled, we know that no implicit grabs exist outside of the existing seat grab tree. This assertion is slightly over-eager though due to the way we set implicit_grab_cancelled: We initialize it to TRUE in the entry->press_count > 0 case and then only set it to FALSE once we find an implicit grab that may remain active. If there are no implicit grabs though (while entry->press_count is still >0), we never set implicit_grab_cancelled to FALSE, triggering the assertion in question even though no implicit grabs got cancelled. There's two possible solutions for this: Either dropping the assertion, or refactoring it so it observes the situation where the implicit grabs were already undone. This commit implements the latter. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2700 Fixes: debbd88f8c8 ("clutter/stage: Cancel parts of implicit grabs when ClutterGrabs happen") Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3216>
2023-08-27 13:44:06 +02:00
implicit_grab_n_remaining++;
}
}
}
clutter/stage: Don't set implicit_grab_cancelled to TRUE if there are none The assertion for !implicit_grab_cancelled in the `grab_actor == old_grab_actor` case of clutter_stage_notify_grab_on_pointer_entry() is meant to do a simple sanity-check to ensure the grab machinery is working as intended: During a seat grab, all input gets delivered to the tree inside the grab, and all implicit grabs outside of that tree are cancelled. When a new seat grab on the same actor as the existing one happens, we run through the cancellation machinery for implicit grabs anyway, so we might as well check that the assumption mentioned above holds true: By asserting that no implicit grabs were cancelled, we know that no implicit grabs exist outside of the existing seat grab tree. This assertion is slightly over-eager though due to the way we set implicit_grab_cancelled: We initialize it to TRUE in the entry->press_count > 0 case and then only set it to FALSE once we find an implicit grab that may remain active. If there are no implicit grabs though (while entry->press_count is still >0), we never set implicit_grab_cancelled to FALSE, triggering the assertion in question even though no implicit grabs got cancelled. There's two possible solutions for this: Either dropping the assertion, or refactoring it so it observes the situation where the implicit grabs were already undone. This commit implements the latter. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2700 Fixes: debbd88f8c8 ("clutter/stage: Cancel parts of implicit grabs when ClutterGrabs happen") Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3216>
2023-08-27 13:44:06 +02:00
/* Seat grabs win over implicit grabs, so we default to cancel the ongoing
* implicit grab. If the seat grab contains one or more actors from
* the implicit grab though, the implicit grab remains in effect.
*/
implicit_grab_cancelled = implicit_grab_n_remaining == 0;
CLUTTER_NOTE (GRABS,
"[grab=%p device=%p sequence=%p implicit_grab_cancelled=%d] "
"Cancelled %u actors and actions (%u remaining) on implicit "
"grab due to new seat grab",
priv->topmost_grab, device, sequence, implicit_grab_cancelled,
clutter/stage: Don't set implicit_grab_cancelled to TRUE if there are none The assertion for !implicit_grab_cancelled in the `grab_actor == old_grab_actor` case of clutter_stage_notify_grab_on_pointer_entry() is meant to do a simple sanity-check to ensure the grab machinery is working as intended: During a seat grab, all input gets delivered to the tree inside the grab, and all implicit grabs outside of that tree are cancelled. When a new seat grab on the same actor as the existing one happens, we run through the cancellation machinery for implicit grabs anyway, so we might as well check that the assumption mentioned above holds true: By asserting that no implicit grabs were cancelled, we know that no implicit grabs exist outside of the existing seat grab tree. This assertion is slightly over-eager though due to the way we set implicit_grab_cancelled: We initialize it to TRUE in the entry->press_count > 0 case and then only set it to FALSE once we find an implicit grab that may remain active. If there are no implicit grabs though (while entry->press_count is still >0), we never set implicit_grab_cancelled to FALSE, triggering the assertion in question even though no implicit grabs got cancelled. There's two possible solutions for this: Either dropping the assertion, or refactoring it so it observes the situation where the implicit grabs were already undone. This commit implements the latter. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2700 Fixes: debbd88f8c8 ("clutter/stage: Cancel parts of implicit grabs when ClutterGrabs happen") Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3216>
2023-08-27 13:44:06 +02:00
implicit_grab_n_removed, implicit_grab_n_remaining);
}
/* Equate NULL actors to the stage here, to ease calculations further down. */
if (!grab_actor)
grab_actor = CLUTTER_ACTOR (stage);
if (!old_grab_actor)
old_grab_actor = CLUTTER_ACTOR (stage);
if (grab_actor == old_grab_actor)
{
clutter/stage: Don't set implicit_grab_cancelled to TRUE if there are none The assertion for !implicit_grab_cancelled in the `grab_actor == old_grab_actor` case of clutter_stage_notify_grab_on_pointer_entry() is meant to do a simple sanity-check to ensure the grab machinery is working as intended: During a seat grab, all input gets delivered to the tree inside the grab, and all implicit grabs outside of that tree are cancelled. When a new seat grab on the same actor as the existing one happens, we run through the cancellation machinery for implicit grabs anyway, so we might as well check that the assumption mentioned above holds true: By asserting that no implicit grabs were cancelled, we know that no implicit grabs exist outside of the existing seat grab tree. This assertion is slightly over-eager though due to the way we set implicit_grab_cancelled: We initialize it to TRUE in the entry->press_count > 0 case and then only set it to FALSE once we find an implicit grab that may remain active. If there are no implicit grabs though (while entry->press_count is still >0), we never set implicit_grab_cancelled to FALSE, triggering the assertion in question even though no implicit grabs got cancelled. There's two possible solutions for this: Either dropping the assertion, or refactoring it so it observes the situation where the implicit grabs were already undone. This commit implements the latter. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2700 Fixes: debbd88f8c8 ("clutter/stage: Cancel parts of implicit grabs when ClutterGrabs happen") Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3216>
2023-08-27 13:44:06 +02:00
g_assert ((implicit_grab_n_removed == 0 && implicit_grab_n_remaining == 0) ||
!implicit_grab_cancelled);
return;
}
if (pointer_in_grab && pointer_in_old_grab)
{
/* Both grabs happen to contain the pointer actor, we have to figure out
* which is topmost, and emit ENTER/LEAVE events accordingly on the actors
* between old/new grabs.
*/
if (clutter_actor_contains (grab_actor, old_grab_actor))
{
/* grab_actor is above old_grab_actor, emit ENTER events in the
* line between those two actors.
*/
event_type = CLUTTER_ENTER;
deepmost = clutter_actor_get_parent (old_grab_actor);
topmost = grab_actor;
}
else if (clutter_actor_contains (old_grab_actor, grab_actor))
{
/* old_grab_actor is above grab_actor, emit LEAVE events in the
* line between those two actors.
*/
event_type = CLUTTER_LEAVE;
deepmost = clutter_actor_get_parent (grab_actor);
topmost = old_grab_actor;
}
}
else if (pointer_in_grab)
{
/* Pointer is somewhere inside the grab_actor hierarchy. Emit ENTER events
* from the current grab actor to the pointer actor.
*/
event_type = CLUTTER_ENTER;
deepmost = entry->current_actor;
topmost = grab_actor;
}
else if (pointer_in_old_grab)
{
/* Pointer is somewhere inside the old_grab_actor hierarchy. Emit LEAVE
* events from the common root of old/cur grab actors to the pointer
* actor.
*/
event_type = CLUTTER_LEAVE;
deepmost = entry->current_actor;
topmost = find_common_root_actor (stage, grab_actor, old_grab_actor);
}
if (event_type == CLUTTER_ENTER && implicit_grab_cancelled)
cleanup_implicit_grab (entry);
if (event_type != CLUTTER_NOTHING)
{
ClutterEvent *event;
if (entry->implicit_grab_actor)
deepmost = find_common_root_actor (stage, entry->implicit_grab_actor, deepmost);
event = clutter_event_crossing_new (event_type,
CLUTTER_EVENT_FLAG_GRAB_NOTIFY,
CLUTTER_CURRENT_TIME,
entry->device,
entry->sequence,
entry->coords,
entry->current_actor,
event_type == CLUTTER_LEAVE ?
grab_actor : old_grab_actor);
if (!_clutter_event_process_filters (event, entry->current_actor))
{
clutter_stage_emit_crossing_event (stage,
event,
deepmost,
topmost);
}
clutter_event_free (event);
}
if ((event_type == CLUTTER_NOTHING || event_type == CLUTTER_LEAVE) &&
implicit_grab_cancelled)
cleanup_implicit_grab (entry);
}
static void
clutter_stage_notify_grab_on_key_focus (ClutterStage *stage,
ClutterActor *grab_actor,
ClutterActor *old_grab_actor)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
ClutterActor *key_focus;
gboolean focus_in_grab, focus_in_old_grab;
key_focus = priv->key_focused_actor ?
priv->key_focused_actor : CLUTTER_ACTOR (stage);
focus_in_grab =
!grab_actor ||
grab_actor == key_focus ||
clutter_actor_contains (grab_actor, key_focus);
focus_in_old_grab =
!old_grab_actor ||
old_grab_actor == key_focus ||
clutter_actor_contains (old_grab_actor, key_focus);
if (focus_in_grab && !focus_in_old_grab)
_clutter_actor_set_has_key_focus (CLUTTER_ACTOR (key_focus), TRUE);
else if (!focus_in_grab && focus_in_old_grab)
_clutter_actor_set_has_key_focus (CLUTTER_ACTOR (key_focus), FALSE);
}
static void
clutter_stage_notify_grab (ClutterStage *stage,
ClutterGrab *cur,
ClutterGrab *old)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
ClutterActor *cur_actor = NULL, *old_actor = NULL;
PointerDeviceEntry *entry;
GHashTableIter iter;
if (cur)
cur_actor = cur->actor;
if (old)
old_actor = old->actor;
/* Nothing to notify */
if (cur_actor == old_actor)
return;
g_hash_table_iter_init (&iter, priv->pointer_devices);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &entry))
{
/* Update pointers */
clutter_stage_notify_grab_on_pointer_entry (stage,
entry,
cur_actor,
old_actor);
}
g_hash_table_iter_init (&iter, priv->touch_sequences);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &entry))
{
/* Update touch sequences */
clutter_stage_notify_grab_on_pointer_entry (stage,
entry,
cur_actor,
old_actor);
}
clutter_stage_notify_grab_on_key_focus (stage, cur_actor, old_actor);
}
static ClutterGrab *
clutter_stage_grab_full (ClutterStage *stage,
ClutterActor *actor,
gboolean owns_actor)
{
ClutterStagePrivate *priv;
ClutterGrab *grab;
gboolean was_grabbed;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
g_return_val_if_fail (stage ==
(ClutterStage *) _clutter_actor_get_stage_internal (actor),
NULL);
priv = clutter_stage_get_instance_private (stage);
if (!priv->topmost_grab)
{
ClutterContext *context;
ClutterSeat *seat;
/* First grab in the chain, trigger a backend grab too */
context = _clutter_context_get_default ();
seat = clutter_backend_get_default_seat (context->backend);
priv->grab_state =
clutter_seat_grab (seat, clutter_get_current_event_time ());
}
grab = clutter_grab_new (stage, actor, owns_actor);
grab->prev = NULL;
grab->next = priv->topmost_grab;
was_grabbed = !!priv->topmost_grab;
if (priv->topmost_grab)
priv->topmost_grab->prev = grab;
priv->topmost_grab = grab;
if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_GRABS))
{
unsigned int n_grabs = 0;
ClutterGrab *g;
for (g = priv->topmost_grab; g != NULL; g = g->next)
n_grabs++;
CLUTTER_NOTE (GRABS,
"[grab=%p] Attached seat grab (n_grabs: %u) on actor: %s",
grab, n_grabs, _clutter_actor_get_debug_name (actor));
}
clutter_actor_attach_grab (actor, grab);
clutter_stage_notify_grab (stage, grab, grab->next);
if (was_grabbed != !!priv->topmost_grab)
g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_IS_GRABBED]);
if (grab->next)
clutter_grab_notify (grab->next);
return grab;
}
/**
* clutter_stage_grab:
* @stage: The #ClutterStage
* @actor: The actor grabbing input
*
* Grabs input onto a certain actor. Events will be propagated as
* usual inside its hierarchy.
*
* Returns: (transfer full): an opaque #ClutterGrab handle, drop
* with [method@Grab.dismiss]
**/
ClutterGrab *
clutter_stage_grab (ClutterStage *stage,
ClutterActor *actor)
{
return clutter_stage_grab_full (stage, actor, FALSE);
}
ClutterGrab *
clutter_stage_grab_input_only (ClutterStage *stage,
ClutterEventHandler handler,
gpointer user_data,
GDestroyNotify user_data_destroy)
{
ClutterInputOnlyActor *input_only_actor;
ClutterActor *actor;
input_only_actor = clutter_input_only_actor_new (handler, user_data,
user_data_destroy);
actor = CLUTTER_ACTOR (input_only_actor);
clutter_actor_set_name (actor, "input only grab actor");
clutter_actor_insert_child_at_index (CLUTTER_ACTOR (stage), actor, 0);
return clutter_stage_grab_full (stage, actor, TRUE);
}
void
clutter_stage_unlink_grab (ClutterStage *stage,
ClutterGrab *grab)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
ClutterGrab *prev, *next;
gboolean was_grabbed;
/* This grab is already detached */
if (!grab->prev && !grab->next && priv->topmost_grab != grab)
return;
prev = grab->prev;
next = grab->next;
if (prev)
prev->next = next;
if (next)
next->prev = prev;
was_grabbed = !!priv->topmost_grab;
if (priv->topmost_grab == grab)
{
/* This is the active grab */
g_assert (prev == NULL);
priv->topmost_grab = next;
clutter_stage_notify_grab (stage, next, grab);
}
clutter_actor_detach_grab (grab->actor, grab);
if (!priv->topmost_grab)
{
ClutterContext *context;
ClutterSeat *seat;
/* This was the last remaining grab, trigger a backend ungrab */
context = _clutter_context_get_default ();
seat = clutter_backend_get_default_seat (context->backend);
clutter_seat_ungrab (seat, clutter_get_current_event_time ());
priv->grab_state = CLUTTER_GRAB_STATE_NONE;
}
if (was_grabbed != !!priv->topmost_grab)
g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_IS_GRABBED]);
if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_GRABS))
{
unsigned int n_grabs = 0;
ClutterGrab *g;
for (g = priv->topmost_grab; g != NULL; g = g->next)
n_grabs++;
CLUTTER_NOTE (GRABS,
"[grab=%p] Detached seat grab (n_grabs: %u)",
grab, n_grabs);
}
grab->next = NULL;
grab->prev = NULL;
if (grab->owns_actor)
g_clear_pointer (&grab->actor, clutter_actor_destroy);
if (priv->topmost_grab)
clutter_grab_notify (priv->topmost_grab);
}
/**
* clutter_grab_dismiss:
* @grab: Grab to undo
*
* Removes a grab. If this grab is effective, crossing events
* will be generated to indicate the change in event redirection.
**/
void
clutter_grab_dismiss (ClutterGrab *grab)
{
g_return_if_fail (grab != NULL);
clutter_stage_unlink_grab (grab->stage, grab);
}
/**
* clutter_grab_get_seat_state:
* @grab: a Grab handle
*
* Returns the windowing-level state of the
* grab, the devices that are guaranteed to be
* grabbed.
*
* Returns: The state of the grab.
**/
ClutterGrabState
clutter_grab_get_seat_state (ClutterGrab *grab)
{
ClutterStagePrivate *priv;
g_return_val_if_fail (grab != NULL, CLUTTER_GRAB_STATE_NONE);
priv = clutter_stage_get_instance_private (grab->stage);
return priv->grab_state;
}
/**
* clutter_stage_get_grab_actor:
* @stage: a #ClutterStage
*
* Gets the actor that currently holds a grab.
*
* Returns: (transfer none) (nullable): The grabbing actor
**/
ClutterActor *
clutter_stage_get_grab_actor (ClutterStage *stage)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (stage);
if (!priv->topmost_grab)
return NULL;
/* Return active grab */
return priv->topmost_grab->actor;
}
/**
* clutter_stage_get_event_actor:
* @stage: a #ClutterStage
* @event: an event received on the stage
*
* Retrieves the current focus actor for an event. This is
* the key focus for key events and other events directed
* to the key focus, or the actor directly under the
* coordinates of a device or touch sequence.
*
* The actor is looked up at the time of calling this function,
* and may differ from the actor that the stage originally
* delivered the event to.
*
* Returns: (transfer none) (nullable): a pointer to the #ClutterActor or %NULL
**/
ClutterActor *
clutter_stage_get_event_actor (ClutterStage *stage,
const ClutterEvent *event)
{
ClutterInputDevice *device;
ClutterEventSequence *sequence;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
g_return_val_if_fail (event != NULL, NULL);
switch (clutter_event_type (event))
{
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
case CLUTTER_PAD_BUTTON_PRESS:
case CLUTTER_PAD_BUTTON_RELEASE:
case CLUTTER_PAD_RING:
case CLUTTER_PAD_STRIP:
case CLUTTER_IM_COMMIT:
case CLUTTER_IM_DELETE:
case CLUTTER_IM_PREEDIT:
return clutter_stage_get_key_focus (stage);
case CLUTTER_MOTION:
case CLUTTER_ENTER:
case CLUTTER_LEAVE:
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
case CLUTTER_SCROLL:
case CLUTTER_TOUCH_BEGIN:
case CLUTTER_TOUCH_UPDATE:
case CLUTTER_TOUCH_END:
case CLUTTER_TOUCH_CANCEL:
case CLUTTER_TOUCHPAD_PINCH:
case CLUTTER_TOUCHPAD_SWIPE:
case CLUTTER_TOUCHPAD_HOLD:
case CLUTTER_PROXIMITY_IN:
case CLUTTER_PROXIMITY_OUT:
device = clutter_event_get_device (event);
sequence = clutter_event_get_event_sequence (event);
return clutter_stage_get_device_actor (stage, device, sequence);
case CLUTTER_DEVICE_ADDED:
case CLUTTER_DEVICE_REMOVED:
case CLUTTER_NOTHING:
case CLUTTER_EVENT_LAST:
g_warn_if_reached ();
}
return NULL;
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
static void
free_event_receiver (EventReceiver *receiver)
{
g_clear_object (&receiver->actor);
g_clear_object (&receiver->action);
}
static void
remove_all_actors_from_chain (PointerDeviceEntry *entry)
{
unsigned int i;
for (i = 0; i < entry->event_emission_chain->len; i++)
{
EventReceiver *receiver =
&g_array_index (entry->event_emission_chain, EventReceiver, i);
if (receiver->actor)
g_clear_object (&receiver->actor);
}
}
static void
remove_all_actions_from_chain (PointerDeviceEntry *entry)
{
unsigned int i;
for (i = 0; i < entry->event_emission_chain->len; i++)
{
EventReceiver *receiver =
&g_array_index (entry->event_emission_chain, EventReceiver, i);
if (receiver->action)
{
clutter_action_sequence_cancelled (receiver->action,
entry->device,
entry->sequence);
g_clear_object (&receiver->action);
}
}
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
static gboolean
setup_implicit_grab (PointerDeviceEntry *entry)
{
/* With a mouse, it's possible to press two buttons at the same time,
* We ignore the second BUTTON_PRESS event here, and we'll release the
* implicit grab on the BUTTON_RELEASE of the second press.
*/
if (entry->sequence == NULL && entry->press_count)
{
entry->press_count++;
return FALSE;
}
CLUTTER_NOTE (GRABS,
"[device=%p sequence=%p] Acquiring implicit grab",
entry->device, entry->sequence);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
g_assert (entry->press_count == 0);
g_assert (entry->event_emission_chain->len == 0);
entry->press_count = 1;
return TRUE;
}
static gboolean
release_implicit_grab (PointerDeviceEntry *entry)
{
if (!entry->press_count)
return FALSE;
/* See comment in setup_implicit_grab() */
if (entry->sequence == NULL && entry->press_count > 1)
{
entry->press_count--;
return FALSE;
}
CLUTTER_NOTE (GRABS,
"[device=%p sequence=%p] Releasing implicit grab",
entry->device, entry->sequence);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
g_assert (entry->press_count == 1);
entry->press_count = 0;
return TRUE;
}
void
clutter_stage_maybe_lost_implicit_grab (ClutterStage *self,
ClutterInputDevice *device,
ClutterEventSequence *sequence)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
PointerDeviceEntry *entry = NULL;
unsigned int i;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
g_assert (entry != NULL);
if (!entry->press_count)
return;
CLUTTER_NOTE (GRABS,
"[device=%p sequence=%p] Lost implicit grab",
device, sequence);
for (i = 0; i < entry->event_emission_chain->len; i++)
{
EventReceiver *receiver =
&g_array_index (entry->event_emission_chain, EventReceiver, i);
if (receiver->action)
clutter_action_sequence_cancelled (receiver->action, device, sequence);
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
sync_crossings_on_implicit_grab_end (self, entry);
cleanup_implicit_grab (entry);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
}
void
clutter_stage_emit_event (ClutterStage *self,
const ClutterEvent *event)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
ClutterInputDevice *device = clutter_event_get_device (event);
ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
PointerDeviceEntry *entry;
ClutterActor *target_actor = NULL, *seat_grab_actor = NULL;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
gboolean is_sequence_begin, is_sequence_end;
ClutterEventType event_type;
COGL_TRACE_BEGIN_SCOPED (EmitEvent, "Clutter::Stage::emit_event()");
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
event_type = clutter_event_type (event);
switch (event_type)
{
case CLUTTER_NOTHING:
case CLUTTER_DEVICE_REMOVED:
case CLUTTER_DEVICE_ADDED:
case CLUTTER_EVENT_LAST:
return;
case CLUTTER_KEY_PRESS:
case CLUTTER_KEY_RELEASE:
case CLUTTER_PAD_BUTTON_PRESS:
case CLUTTER_PAD_BUTTON_RELEASE:
case CLUTTER_PAD_STRIP:
case CLUTTER_PAD_RING:
case CLUTTER_IM_COMMIT:
case CLUTTER_IM_DELETE:
case CLUTTER_IM_PREEDIT:
{
target_actor = priv->key_focused_actor ?
priv->key_focused_actor : CLUTTER_ACTOR (self);
break;
}
/* x11 stage enter/leave events */
case CLUTTER_ENTER:
case CLUTTER_LEAVE:
{
target_actor = entry->current_actor;
break;
}
case CLUTTER_MOTION:
case CLUTTER_BUTTON_PRESS:
case CLUTTER_BUTTON_RELEASE:
case CLUTTER_SCROLL:
case CLUTTER_TOUCHPAD_PINCH:
case CLUTTER_TOUCHPAD_SWIPE:
case CLUTTER_TOUCHPAD_HOLD:
case CLUTTER_TOUCH_UPDATE:
case CLUTTER_TOUCH_BEGIN:
case CLUTTER_TOUCH_CANCEL:
case CLUTTER_TOUCH_END:
case CLUTTER_PROXIMITY_IN:
case CLUTTER_PROXIMITY_OUT:
{
float x, y;
clutter_event_get_coords (event, &x, &y);
CLUTTER_NOTE (EVENT,
"Reactive event received at %.2f, %.2f - actor: %p",
x, y, entry->current_actor);
target_actor = entry->current_actor;
break;
}
}
if (!target_actor)
return;
seat_grab_actor = priv->topmost_grab ? priv->topmost_grab->actor : CLUTTER_ACTOR (self);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
is_sequence_begin =
event_type == CLUTTER_BUTTON_PRESS || event_type == CLUTTER_TOUCH_BEGIN;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
is_sequence_end =
event_type == CLUTTER_BUTTON_RELEASE || event_type == CLUTTER_TOUCH_END ||
event_type == CLUTTER_TOUCH_CANCEL;
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
if (is_sequence_begin && setup_implicit_grab (entry))
{
g_assert (entry->implicit_grab_actor == NULL);
entry->implicit_grab_actor = target_actor;
clutter_actor_set_implicitly_grabbed (entry->implicit_grab_actor, TRUE);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
create_event_emission_chain (self, entry->event_emission_chain, seat_grab_actor, target_actor);
}
if (entry && entry->press_count)
{
EventHandledState state;
state = emit_event (event, entry->event_emission_chain);
if (state == EVENT_HANDLED_BY_ACTOR)
remove_all_actions_from_chain (entry);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
}
else
{
create_event_emission_chain (self, priv->cur_event_emission_chain, seat_grab_actor, target_actor);
emit_event (event, priv->cur_event_emission_chain);
g_array_remove_range (priv->cur_event_emission_chain, 0, priv->cur_event_emission_chain->len);
}
if (is_sequence_end && release_implicit_grab (entry))
{
/* Sync crossings after the implicit grab for mice */
if (event_type == CLUTTER_BUTTON_RELEASE)
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
sync_crossings_on_implicit_grab_end (self, entry);
cleanup_implicit_grab (entry);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
}
}
static void
cancel_implicit_grab_on_actor (PointerDeviceEntry *entry,
ClutterActor *actor)
{
unsigned int i;
ClutterActor *parent = clutter_actor_get_parent (actor);
CLUTTER_NOTE (GRABS,
"[device=%p sequence=%p] Cancelling implicit grab on actor (%s) "
"due to unmap",
entry->device, entry->sequence,
_clutter_actor_get_debug_name (actor));
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
for (i = 0; i < entry->event_emission_chain->len; i++)
{
EventReceiver *receiver =
&g_array_index (entry->event_emission_chain, EventReceiver, i);
if (receiver->actor)
{
if (receiver->actor == actor)
g_clear_object (&receiver->actor);
}
else if (receiver->action)
{
ClutterActor *action_actor =
clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (receiver->action));
if (!action_actor || action_actor == actor)
{
clutter_action_sequence_cancelled (receiver->action,
entry->device,
entry->sequence);
g_clear_object (&receiver->action);
}
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
}
}
clutter_actor_set_implicitly_grabbed (entry->implicit_grab_actor, FALSE);
entry->implicit_grab_actor = NULL;
if (parent)
{
g_assert (clutter_actor_is_mapped (parent));
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
entry->implicit_grab_actor = parent;
clutter_actor_set_implicitly_grabbed (entry->implicit_grab_actor, TRUE);
}
}
void
clutter_stage_implicit_grab_actor_unmapped (ClutterStage *self,
ClutterActor *actor)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
clutter: Implicitly grab on button and touch event sequences We'll soon introduce a new gesture tracking framework which heavily depends on ClutterActions seeing all events of a sequence. For this to work, a larger change to event delivery is needed: Implicit grabbing of all events for button and touch press->motion->release sequences to ensure ClutterActions continue receiving events for the whole sequence. This commit takes care of that: At the start of an event sequence we collect all the event-handling actors and actions to a GArray that lives in the PointerDeviceEntry, and then deliver all events belonging to that sequence to the same actors/actions until the sequence ends. To avoid events getting pulled from under our feet when mutters event filter returns CLUTTER_EVENT_STOP, this also introduces private API (maybe_lost_implicit_grab()) on ClutterStage so that we can't end up with stale sequences. Note that this also slightly changes behavior when it comes to event delivery to actions: Because we now store actions separated from their actors, any action returning CLUTTER_EVENT_STOP now stops event propagation immediately. That was different before, where we'd emit events to all actions of the actor and only then stop propagation. Note that this isn't handling ClutterGrabs correctly right now, this will be a little tricky, so we'll take care of that in a future commit. To handle actors getting destroyed or unmapped during a grab, listen to notify::grab on the deepmost actor in the implicit grab tree. This gives us a notification when any actor inside the tree goes unmapped. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
2022-08-03 17:57:13 +02:00
GHashTableIter iter;
PointerDeviceEntry *entry;
g_hash_table_iter_init (&iter, priv->pointer_devices);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &entry))
{
if (entry->implicit_grab_actor == actor)
cancel_implicit_grab_on_actor (entry, actor);
}
g_hash_table_iter_init (&iter, priv->touch_sequences);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &entry))
{
if (entry->implicit_grab_actor == actor)
cancel_implicit_grab_on_actor (entry, actor);
}
}
void
clutter_stage_notify_action_implicit_grab (ClutterStage *self,
ClutterInputDevice *device,
ClutterEventSequence *sequence)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
PointerDeviceEntry *entry;
if (sequence != NULL)
entry = g_hash_table_lookup (priv->touch_sequences, sequence);
else
entry = g_hash_table_lookup (priv->pointer_devices, device);
g_assert (entry->press_count > 0);
remove_all_actors_from_chain (entry);
}
/**
* clutter_stage_pointing_input_foreach:
* @self: The stage
* @func: (scope call): Iterator function
* @user_data: user data
*
* Iterates over active input.
*
* Returns: %TRUE if the foreach function did not stop.
**/
gboolean
clutter_stage_pointing_input_foreach (ClutterStage *self,
ClutterStageInputForeachFunc func,
gpointer user_data)
{
ClutterStagePrivate *priv = clutter_stage_get_instance_private (self);
GHashTableIter iter;
PointerDeviceEntry *entry;
g_return_val_if_fail (CLUTTER_IS_STAGE (self), FALSE);
g_return_val_if_fail (func != NULL, FALSE);
g_hash_table_iter_init (&iter, priv->pointer_devices);
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &entry))
{
if (!func (self, entry->device, entry->sequence, user_data))
return FALSE;
}
g_hash_table_iter_init (&iter, priv->touch_sequences);
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &entry))
{
if (!func (self, entry->device, entry->sequence, user_data))
return FALSE;
}
return TRUE;
}