[Freeciv-Dev] Re: (PR#7376) Unify dirty managment
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7376 >
On Wed, Feb 04, 2004 at 08:16:21AM -0800, Raimar Falke wrote:
>
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=7376 >
>
>
> See $SUBJECT.
>
> Only GTK1 and Xaw changed and tested.
With GTK2 support.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
The Software is not designed or licensed for use in on-line control
equipment in hazardous environments, such as operation of nuclear
facilities, aircraft navigation or control, or direct life support
machines.
-- Java Compiler Compiler Download and License Agreement
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.74
diff -u -u -r1.74 mapview_common.c
--- client/mapview_common.c 2004/02/03 20:16:07 1.74
+++ client/mapview_common.c 2004/02/04 20:45:34
@@ -25,6 +25,7 @@
#include "climap.h"
#include "control.h"
#include "goto.h"
+#include "gui_main_g.h"
#include "mapctrl_g.h"
#include "mapview_g.h"
#include "tilespec.h"
@@ -1722,4 +1723,81 @@
/* Call gui specific function. */
map_size_changed();
+}
+
+/**************************************************************************
+ Flush the given part of the canvas buffer (if there is one) to the
+ screen.
+**************************************************************************/
+static void flush_mapcanvas(int canvas_x, int canvas_y,
+ int pixel_width, int pixel_height)
+{
+ if (pixel_width > 0 && pixel_height > 0) {
+ gui_copy_canvas(mapview_canvas.window, mapview_canvas.store, canvas_x,
+ canvas_y, canvas_x, canvas_y, pixel_width, pixel_height);
+ }
+}
+
+#define MAX_DIRTY_RECTS 20
+static int num_dirty_rects = 0;
+static struct {
+ int x, y, width, height;
+} dirty_rects[MAX_DIRTY_RECTS];
+
+/**************************************************************************
+...
+**************************************************************************/
+static void dirty_added(void)
+{
+ if (num_dirty_rects == 0) {
+ add_idle_callback(flush_dirty);
+ }
+}
+
+/**************************************************************************
+ Mark the rectangular region as 'dirty' so that we know to flush it
+ later.
+**************************************************************************/
+void dirty_rect(int canvas_x, int canvas_y, int pixel_width,
+ int pixel_height)
+{
+ dirty_added();
+
+ if (num_dirty_rects < MAX_DIRTY_RECTS) {
+ dirty_rects[num_dirty_rects].x = canvas_x;
+ dirty_rects[num_dirty_rects].y = canvas_y;
+ dirty_rects[num_dirty_rects].width = pixel_width;
+ dirty_rects[num_dirty_rects].height = pixel_height;
+ num_dirty_rects++;
+ }
+}
+
+/**************************************************************************
+ Mark the entire screen area as "dirty" so that we can flush it later.
+**************************************************************************/
+void dirty_all(void)
+{
+ dirty_added();
+
+ num_dirty_rects = MAX_DIRTY_RECTS;
+}
+
+/**************************************************************************
+ Flush all regions that have been previously marked as dirty. See
+ dirty_rect and dirty_all. This function is generally called after we've
+ processed a batch of drawing operations.
+**************************************************************************/
+void flush_dirty(void)
+{
+ if (num_dirty_rects == MAX_DIRTY_RECTS) {
+ flush_mapcanvas(0, 0, mapview_canvas.width, mapview_canvas.height);
+ } else {
+ int i;
+
+ for (i = 0; i < num_dirty_rects; i++) {
+ flush_mapcanvas(dirty_rects[i].x, dirty_rects[i].y,
+ dirty_rects[i].width, dirty_rects[i].height);
+ }
+ }
+ num_dirty_rects = 0;
}
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.40
diff -u -u -r1.40 mapview_common.h
--- client/mapview_common.h 2004/02/03 20:16:07 1.40
+++ client/mapview_common.h 2004/02/04 20:45:35
@@ -23,10 +23,14 @@
struct canvas_store; /* opaque type, real type is gui-dep */
struct canvas {
+ /* The following fields are controlled by mapview_common.c. */
int map_x0, map_y0;
int width, height; /* Size in pixels. */
int tile_width, tile_height; /* Size in tiles. Rounded up. */
struct canvas_store *store;
+
+ /* The following fields are controlled by gui-.../mapview.c. */
+ struct canvas_store *window;
};
/* Holds all information about the overview aka minimap. */
@@ -205,5 +209,10 @@
void refresh_overview_canvas(void);
void overview_update_tile(int x, int y);
void set_overview_dimensions(int width, int height);
+
+void dirty_rect(int canvas_x, int canvas_y,
+ int pixel_width, int pixel_height);
+void dirty_all(void);
+void flush_dirty(void);
#endif /* FC__MAPVIEW_COMMON_H */
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.144
diff -u -u -r1.144 gui_main.c
--- client/gui-gtk/gui_main.c 2004/02/03 20:16:07 1.144
+++ client/gui-gtk/gui_main.c 2004/02/04 20:45:36
@@ -957,6 +957,10 @@
canvas_store_create(mapview_canvas.width, mapview_canvas.height);
map_canvas_store = mapview_canvas.store->pixmap;
+ mapview_canvas.window = fc_malloc(sizeof(*mapview_canvas.window));
+ mapview_canvas.window->pixmap = map_canvas->window;
+ mapview_canvas.window->pixcomm = NULL;
+
overview.store = NULL;
overview.window = fc_malloc(sizeof(*overview.window));
overview.window->pixmap = overview_canvas->window;
@@ -1188,4 +1192,17 @@
{
gdk_input_remove(gdk_input_id);
gdk_window_set_cursor(root_window, NULL);
+}
+
+static gboolean idle_callback_wrapper(gpointer data)
+{
+ void (*callback) (void) = data;
+
+ callback();
+ return FALSE;
+}
+
+void add_idle_callback(void (*callback) (void))
+{
+ g_idle_add(idle_callback_wrapper, callback);
}
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.190
diff -u -u -r1.190 mapview.c
--- client/gui-gtk/mapview.c 2004/02/03 20:16:07 1.190
+++ client/gui-gtk/mapview.c 2004/02/04 20:45:38
@@ -574,95 +574,6 @@
}
/**************************************************************************
- Flush the given part of the canvas buffer (if there is one) to the
- screen.
-**************************************************************************/
-void flush_mapcanvas(int canvas_x, int canvas_y,
- int pixel_width, int pixel_height)
-{
- gdk_draw_pixmap(map_canvas->window, civ_gc, map_canvas_store,
- canvas_x, canvas_y, canvas_x, canvas_y,
- pixel_width, pixel_height);
-
-}
-
-#define MAX_DIRTY_RECTS 20
-static int num_dirty_rects = 0;
-static GdkRectangle dirty_rects[MAX_DIRTY_RECTS];
-static bool is_flush_queued = FALSE;
-
-/**************************************************************************
- A callback invoked as a result of gtk_idle_add, this function simply
- flushes the mapview canvas.
-**************************************************************************/
-static gint unqueue_flush(gpointer data)
-{
- flush_dirty();
- is_flush_queued = FALSE;
- return 0;
-}
-
-/**************************************************************************
- Called when a region is marked dirty, this function queues a flush event
- to be handled later by GTK. The flush may end up being done
- by freeciv before then, in which case it will be a wasted call.
-**************************************************************************/
-static void queue_flush(void)
-{
- if (!is_flush_queued) {
- gtk_idle_add(unqueue_flush, NULL);
- is_flush_queued = TRUE;
- }
-}
-
-/**************************************************************************
- Mark the rectangular region as 'dirty' so that we know to flush it
- later.
-**************************************************************************/
-void dirty_rect(int canvas_x, int canvas_y,
- int pixel_width, int pixel_height)
-{
- if (num_dirty_rects < MAX_DIRTY_RECTS) {
- dirty_rects[num_dirty_rects].x = canvas_x;
- dirty_rects[num_dirty_rects].y = canvas_y;
- dirty_rects[num_dirty_rects].width = pixel_width;
- dirty_rects[num_dirty_rects].height = pixel_height;
- num_dirty_rects++;
- queue_flush();
- }
-}
-
-/**************************************************************************
- Mark the entire screen area as "dirty" so that we can flush it later.
-**************************************************************************/
-void dirty_all(void)
-{
- num_dirty_rects = MAX_DIRTY_RECTS;
- queue_flush();
-}
-
-/**************************************************************************
- Flush all regions that have been previously marked as dirty. See
- dirty_rect and dirty_all. This function is generally called after we've
- processed a batch of drawing operations.
-**************************************************************************/
-void flush_dirty(void)
-{
- if (num_dirty_rects == MAX_DIRTY_RECTS) {
- flush_mapcanvas(0, 0, map_canvas->allocation.width,
- map_canvas->allocation.height);
- } else {
- int i;
-
- for (i = 0; i < num_dirty_rects; i++) {
- flush_mapcanvas(dirty_rects[i].x, dirty_rects[i].y,
- dirty_rects[i].width, dirty_rects[i].height);
- }
- }
- num_dirty_rects = 0;
-}
-
-/**************************************************************************
Update display of descriptions associated with cities on the main map.
**************************************************************************/
void update_city_descriptions(void)
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.65
diff -u -u -r1.65 gui_main.c
--- client/gui-gtk-2.0/gui_main.c 2004/02/04 20:06:12 1.65
+++ client/gui-gtk-2.0/gui_main.c 2004/02/04 20:45:40
@@ -1194,7 +1194,10 @@
timer_id = gtk_timeout_add(TIMER_INTERVAL, timer_callback, NULL);
- overview.store = NULL;
+ mapview_canvas.window = fc_malloc(sizeof(*mapview_canvas.window));
+ mapview_canvas.window->pixmap = map_canvas->window;
+ mapview_canvas.window->pixcomm = NULL;
+
overview.window = fc_malloc(sizeof(*overview.window));
overview.window->pixmap = overview_canvas->window;
overview.window->pixcomm = NULL;
@@ -1499,4 +1502,17 @@
{
gtk_input_remove(input_id);
gdk_window_set_cursor(root_window, NULL);
+}
+
+static gboolean idle_callback_wrapper(gpointer data)
+{
+ void (*callback) (void) = data;
+
+ callback();
+ return FALSE;
+}
+
+void add_idle_callback(void (*callback) (void))
+{
+ g_idle_add(idle_callback_wrapper, callback);
}
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.90
diff -u -u -r1.90 mapview.c
--- client/gui-gtk-2.0/mapview.c 2004/02/04 20:06:12 1.90
+++ client/gui-gtk-2.0/mapview.c 2004/02/04 20:45:48
@@ -641,57 +641,6 @@
}
/**************************************************************************
- Flush the given part of the canvas buffer (if there is one) to the
- screen.
-**************************************************************************/
-void flush_mapcanvas(int canvas_x, int canvas_y,
- int pixel_width, int pixel_height)
-{
- gdk_draw_drawable(map_canvas->window, civ_gc, map_canvas_store,
- canvas_x, canvas_y, canvas_x, canvas_y,
- pixel_width, pixel_height);
-}
-
-/**************************************************************************
- Mark the rectangular region as "dirty" so that we know to flush it
- later.
-**************************************************************************/
-void dirty_rect(int canvas_x, int canvas_y,
- int pixel_width, int pixel_height)
-{
- /* GDK gives an error if we invalidate out-of-bounds parts of the
- window. */
- GdkRectangle rect = {MAX(canvas_x, 0), MAX(canvas_y, 0),
- MIN(pixel_width,
- map_canvas->allocation.width - canvas_x),
- MIN(pixel_height,
- map_canvas->allocation.height - canvas_y)};
-
- gdk_window_invalidate_rect(map_canvas->window, &rect, FALSE);
-}
-
-/**************************************************************************
- Mark the entire screen area as "dirty" so that we can flush it later.
-**************************************************************************/
-void dirty_all(void)
-{
- GdkRectangle rect = {0, 0, map_canvas->allocation.width,
- map_canvas->allocation.height};
-
- gdk_window_invalidate_rect(map_canvas->window, &rect, FALSE);
-}
-
-/**************************************************************************
- Flush all regions that have been previously marked as dirty. See
- dirty_rect and dirty_all. This function is generally called after we've
- processed a batch of drawing operations.
-**************************************************************************/
-void flush_dirty(void)
-{
- gdk_window_process_updates(map_canvas->window, FALSE);
-}
-
-/**************************************************************************
Update display of descriptions associated with cities on the main map.
**************************************************************************/
void update_city_descriptions(void)
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.86
diff -u -u -r1.86 gui_main.c
--- client/gui-xaw/gui_main.c 2004/02/03 20:16:08 1.86
+++ client/gui-xaw/gui_main.c 2004/02/04 20:45:49
@@ -448,6 +448,9 @@
map_canvas_resize();
+ mapview_canvas.window = fc_malloc(sizeof(*mapview_canvas.window));
+ mapview_canvas.window->pixmap = XtWindow(map_canvas);
+
overview.store = NULL;
overview.window = fc_malloc(sizeof(*overview.window));
overview.window->pixmap = XtWindow(overview_canvas);
@@ -874,4 +877,17 @@
xaw_set_bitmap(more_arrow_label, None);
showing = FALSE;
}
+}
+
+static void idle_callback_wrapper(XtPointer client_data, XtIntervalId * id)
+{
+ void (*callback) (void) = client_data;
+
+ callback();
+
+}
+
+void add_idle_callback(void (*callback) (void))
+{
+ (void) XtAppAddTimeOut(app_context, 0, idle_callback_wrapper, callback);
}
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.155
diff -u -u -r1.155 mapview.c
--- client/gui-xaw/mapview.c 2004/02/03 20:16:08 1.155
+++ client/gui-xaw/mapview.c 2004/02/04 20:45:50
@@ -593,96 +593,6 @@
}
/**************************************************************************
- Flush the given part of the canvas buffer (if there is one) to the
- screen.
-**************************************************************************/
-void flush_mapcanvas(int canvas_x, int canvas_y,
- int pixel_width, int pixel_height)
-{
- XCopyArea(display, map_canvas_store, XtWindow(map_canvas),
- civ_gc,
- canvas_x, canvas_y, pixel_width, pixel_height,
- canvas_x, canvas_y);
-}
-
-#define MAX_DIRTY_RECTS 20
-static int num_dirty_rects = 0;
-static XRectangle dirty_rects[MAX_DIRTY_RECTS];
-bool is_flush_queued = FALSE;
-
-/**************************************************************************
- A callback invoked as a result of a 0-length timer, this function simply
- flushes the mapview canvas.
-**************************************************************************/
-static void unqueue_flush(XtPointer client_data, XtIntervalId * id)
-{
- flush_dirty();
- is_flush_queued = FALSE;
-}
-
-/**************************************************************************
- Called when a region is marked dirty, this function queues a flush event
- to be handled later by Xaw. The flush may end up being done
- by freeciv before then, in which case it will be a wasted call.
-**************************************************************************/
-static void queue_flush(void)
-{
- if (!is_flush_queued) {
- (void) XtAppAddTimeOut(app_context, 0, unqueue_flush, NULL);
- is_flush_queued = TRUE;
- }
-}
-
-/**************************************************************************
- Mark the rectangular region as 'dirty' so that we know to flush it
- later.
-**************************************************************************/
-void dirty_rect(int canvas_x, int canvas_y,
- int pixel_width, int pixel_height)
-{
- if (num_dirty_rects < MAX_DIRTY_RECTS) {
- dirty_rects[num_dirty_rects].x = canvas_x;
- dirty_rects[num_dirty_rects].y = canvas_y;
- dirty_rects[num_dirty_rects].width = pixel_width;
- dirty_rects[num_dirty_rects].height = pixel_height;
- num_dirty_rects++;
- queue_flush();
- }
-}
-
-/**************************************************************************
- Mark the entire screen area as "dirty" so that we can flush it later.
-**************************************************************************/
-void dirty_all(void)
-{
- num_dirty_rects = MAX_DIRTY_RECTS;
- queue_flush();
-}
-
-/**************************************************************************
- Flush all regions that have been previously marked as dirty. See
- dirty_rect and dirty_all. This function is generally called after we've
- processed a batch of drawing operations.
-**************************************************************************/
-void flush_dirty(void)
-{
- if (num_dirty_rects == MAX_DIRTY_RECTS) {
- Dimension width, height;
-
- XtVaGetValues(map_canvas, XtNwidth, &width, XtNheight, &height, NULL);
- flush_mapcanvas(0, 0, width, height);
- } else {
- int i;
-
- for (i = 0; i < num_dirty_rects; i++) {
- flush_mapcanvas(dirty_rects[i].x, dirty_rects[i].y,
- dirty_rects[i].width, dirty_rects[i].height);
- }
- }
- num_dirty_rects = 0;
-}
-
-/**************************************************************************
...
**************************************************************************/
void update_map_canvas_scrollbars(void)
Index: client/include/gui_main_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/gui_main_g.h,v
retrieving revision 1.9
diff -u -u -r1.9 gui_main_g.h
--- client/include/gui_main_g.h 2003/05/03 20:20:16 1.9
+++ client/include/gui_main_g.h 2004/02/04 20:45:50
@@ -23,6 +23,7 @@
void sound_bell(void);
void add_net_input(int);
void remove_net_input(void);
+void add_idle_callback(void (*callback)(void));
void set_unit_icon(int idx, struct unit *punit);
void set_unit_icons_more_arrow(bool onoff);
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.42
diff -u -u -r1.42 mapview_g.h
--- client/include/mapview_g.h 2004/02/03 20:16:08 1.42
+++ client/include/mapview_g.h 2004/02/04 20:45:50
@@ -58,13 +58,6 @@
int src_x, int src_y, int dest_x, int dest_y, int width,
int height);
-void flush_mapcanvas(int canvas_x, int canvas_y,
- int pixel_width, int pixel_height);
-void dirty_rect(int canvas_x, int canvas_y,
- int pixel_width, int pixel_height);
-void dirty_all(void);
-void flush_dirty(void);
-
void update_map_canvas_scrollbars(void);
void put_cross_overlay_tile(int x,int y);
|
|