forked from AuroraMiddleware/gtk
890080ebf7
Rename all *window.[ch] source files. This is an automatic operation, done by the following commands: for i in $(git ls-files gdk | grep window); do git mv $i $(echo $i | sed s/window/surface/); git sed -f g $(basename $i) $(basename $i | sed s/window/surface/) ; done git checkout NEWS* po-properties po
216 lines
5.7 KiB
C
216 lines
5.7 KiB
C
/* GDK - The GIMP Drawing Kit
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include "gdkinternals.h"
|
|
#include "gdkrectangle.h"
|
|
#include "gdkprivate-x11.h"
|
|
#include "gdkscreen-x11.h"
|
|
#include "gdkdisplay-x11.h"
|
|
#include "gdksurface-x11.h"
|
|
|
|
|
|
typedef struct _GdkSurfaceQueueItem GdkSurfaceQueueItem;
|
|
typedef struct _GdkSurfaceParentPos GdkSurfaceParentPos;
|
|
|
|
struct _GdkSurfaceQueueItem
|
|
{
|
|
GdkSurface *window;
|
|
gulong serial;
|
|
cairo_region_t *antiexpose_area;
|
|
};
|
|
|
|
static Bool
|
|
expose_serial_predicate (Display *xdisplay,
|
|
XEvent *xev,
|
|
XPointer arg)
|
|
{
|
|
gulong *serial = (gulong *)arg;
|
|
|
|
if (xev->xany.type == Expose || xev->xany.type == GraphicsExpose)
|
|
*serial = MIN (*serial, xev->xany.serial);
|
|
|
|
return False;
|
|
}
|
|
|
|
/* Find oldest possible serial for an outstanding expose event
|
|
*/
|
|
static gulong
|
|
find_current_serial (Display *xdisplay)
|
|
{
|
|
XEvent xev;
|
|
gulong serial = NextRequest (xdisplay);
|
|
|
|
XSync (xdisplay, False);
|
|
|
|
XCheckIfEvent (xdisplay, &xev, expose_serial_predicate, (XPointer)&serial);
|
|
|
|
return serial;
|
|
}
|
|
|
|
static void
|
|
queue_delete_link (GQueue *queue,
|
|
GList *link)
|
|
{
|
|
if (queue->tail == link)
|
|
queue->tail = link->prev;
|
|
|
|
queue->head = g_list_remove_link (queue->head, link);
|
|
g_list_free_1 (link);
|
|
queue->length--;
|
|
}
|
|
|
|
static void
|
|
queue_item_free (GdkSurfaceQueueItem *item)
|
|
{
|
|
if (item->window)
|
|
{
|
|
g_object_remove_weak_pointer (G_OBJECT (item->window),
|
|
(gpointer *)&(item->window));
|
|
}
|
|
|
|
cairo_region_destroy (item->antiexpose_area);
|
|
g_free (item);
|
|
}
|
|
|
|
void
|
|
_gdk_x11_display_free_translate_queue (GdkDisplay *display)
|
|
{
|
|
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
|
|
|
|
if (display_x11->translate_queue)
|
|
{
|
|
g_queue_foreach (display_x11->translate_queue, (GFunc)queue_item_free, NULL);
|
|
g_queue_free (display_x11->translate_queue);
|
|
display_x11->translate_queue = NULL;
|
|
}
|
|
}
|
|
|
|
static void
|
|
gdk_surface_queue (GdkSurface *window,
|
|
GdkSurfaceQueueItem *new_item)
|
|
{
|
|
GdkX11Display *display_x11 = GDK_X11_DISPLAY (GDK_SURFACE_DISPLAY (window));
|
|
|
|
if (!display_x11->translate_queue)
|
|
display_x11->translate_queue = g_queue_new ();
|
|
|
|
/* Keep length of queue finite by, if it grows too long,
|
|
* figuring out the latest relevant serial and discarding
|
|
* irrelevant queue items.
|
|
*/
|
|
if (display_x11->translate_queue->length >= 64)
|
|
{
|
|
gulong serial = find_current_serial (GDK_SURFACE_XDISPLAY (window));
|
|
GList *tmp_list = display_x11->translate_queue->head;
|
|
|
|
while (tmp_list)
|
|
{
|
|
GdkSurfaceQueueItem *item = tmp_list->data;
|
|
GList *next = tmp_list->next;
|
|
|
|
/* an overflow-safe (item->serial < serial) */
|
|
if (item->serial - serial > (gulong) G_MAXLONG)
|
|
{
|
|
queue_delete_link (display_x11->translate_queue, tmp_list);
|
|
queue_item_free (item);
|
|
}
|
|
|
|
tmp_list = next;
|
|
}
|
|
}
|
|
|
|
/* Catch the case where someone isn't processing events and there
|
|
* is an event stuck in the event queue with an old serial:
|
|
* If we can't reduce the queue length by the above method,
|
|
* discard anti-expose items. (We can't discard translate
|
|
* items
|
|
*/
|
|
if (display_x11->translate_queue->length >= 64)
|
|
{
|
|
GList *tmp_list = display_x11->translate_queue->head;
|
|
|
|
while (tmp_list)
|
|
{
|
|
GdkSurfaceQueueItem *item = tmp_list->data;
|
|
GList *next = tmp_list->next;
|
|
|
|
queue_delete_link (display_x11->translate_queue, tmp_list);
|
|
queue_item_free (item);
|
|
|
|
tmp_list = next;
|
|
}
|
|
}
|
|
|
|
new_item->window = window;
|
|
new_item->serial = NextRequest (GDK_SURFACE_XDISPLAY (window));
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (window),
|
|
(gpointer *)&(new_item->window));
|
|
|
|
g_queue_push_tail (display_x11->translate_queue, new_item);
|
|
}
|
|
|
|
void
|
|
_gdk_x11_surface_queue_antiexpose (GdkSurface *window,
|
|
cairo_region_t *area)
|
|
{
|
|
GdkSurfaceQueueItem *item = g_new (GdkSurfaceQueueItem, 1);
|
|
item->antiexpose_area = cairo_region_reference (area);
|
|
|
|
gdk_surface_queue (window, item);
|
|
}
|
|
|
|
void
|
|
_gdk_x11_surface_process_expose (GdkSurface *window,
|
|
gulong serial,
|
|
GdkRectangle *area)
|
|
{
|
|
cairo_region_t *invalidate_region = cairo_region_create_rectangle (area);
|
|
GdkX11Display *display_x11 = GDK_X11_DISPLAY (GDK_SURFACE_DISPLAY (window));
|
|
|
|
if (display_x11->translate_queue)
|
|
{
|
|
GList *tmp_list = display_x11->translate_queue->head;
|
|
|
|
while (tmp_list)
|
|
{
|
|
GdkSurfaceQueueItem *item = tmp_list->data;
|
|
GList *next = tmp_list->next;
|
|
|
|
/* an overflow-safe (serial < item->serial) */
|
|
if (serial - item->serial > (gulong) G_MAXLONG)
|
|
{
|
|
if (item->window == window)
|
|
cairo_region_subtract (invalidate_region, item->antiexpose_area);
|
|
}
|
|
else
|
|
{
|
|
queue_delete_link (display_x11->translate_queue, tmp_list);
|
|
queue_item_free (item);
|
|
}
|
|
tmp_list = next;
|
|
}
|
|
}
|
|
|
|
if (!cairo_region_is_empty (invalidate_region))
|
|
_gdk_surface_invalidate_for_expose (window, invalidate_region);
|
|
|
|
cairo_region_destroy (invalidate_region);
|
|
}
|