Re: [AD] Two Windows patches |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Sunday 22 January 2006 22:50, Evert Glebbeek wrote:
> Ideally, there would be a way to return a status to destroy_bitmap() to
> tell it that it should go ahead and do what it normally would have done.
> ie,
>
> destroy_bitmap: `Hey, destroy_system_bitmap, you destroy this bitmap!'
> destroy_system_bitmap: `Nah, you do it.'
> destroy_bitmap: `Ok.'
>
> Maybe this is actually a better idea, I'll see if I can do it this way
> instead.
Patch (completely untested) attached; I suspect it can be cleaned up a bit
more though. It makes the destroy_system_bitmap and destroy_video_bitmap
(which is used for destroy_system_bitmap on MacOS X, by the way: is that
correct?) functions return a status code (TRUE or FALSE) that is checked
by the general purpose code. If the special-case function returns FALSE,
the general purpose code does what it normally would do.
Now that I've seen it I'm not actually sure if I prefer it to duplicating a
few lines of code...
Evert
Index: src/win/wddbmp.c
===================================================================
--- src/win/wddbmp.c (revision 5686)
+++ src/win/wddbmp.c (working copy)
@@ -493,7 +493,7 @@
/* gfx_directx_destroy_video_bitmap:
*/
-void gfx_directx_destroy_video_bitmap(BITMAP *bmp)
+int gfx_directx_destroy_video_bitmap(BITMAP *bmp)
{
DDRAW_SURFACE *surf, *tail_page;
@@ -525,6 +525,8 @@
}
_AL_FREE(bmp);
+
+ return TRUE;
}
@@ -653,12 +655,18 @@
/* gfx_directx_destroy_system_bitmap:
*/
-void gfx_directx_destroy_system_bitmap(BITMAP *bmp)
+int gfx_directx_destroy_system_bitmap(BITMAP *bmp)
{
+ /* Special case: we don't deal with subbitmaps */
+ if (is_sub_bitmap(bmp)) {
+ return FALSE;
+ }
+
/* destroy the surface */
gfx_directx_destroy_surface(DDRAW_SURFACE_OF(bmp));
_AL_FREE(bmp);
+ return TRUE;
}
Index: src/win/wddwin.c
===================================================================
--- src/win/wddwin.c (revision 5686)
+++ src/win/wddwin.c (working copy)
@@ -32,7 +32,7 @@
static void gfx_directx_set_palette_win(AL_CONST struct RGB *p, int from, int to, int vsync);
static BITMAP *gfx_directx_create_video_bitmap_win(int width, int height);
-static void gfx_directx_destroy_video_bitmap_win(BITMAP *bmp);
+static int gfx_directx_destroy_video_bitmap_win(BITMAP *bmp);
static int gfx_directx_show_video_bitmap_win(struct BITMAP *bmp);
static BITMAP *init_directx_win(int w, int h, int v_w, int v_h, int color_depth);
static void gfx_directx_win_exit(struct BITMAP *bmp);
@@ -448,7 +448,7 @@
/* gfx_directx_destroy_video_bitmap_win:
*/
-static void gfx_directx_destroy_video_bitmap_win(BITMAP *bmp)
+static int gfx_directx_destroy_video_bitmap_win(BITMAP *bmp)
{
DDRAW_SURFACE *surf;
@@ -463,6 +463,8 @@
}
_AL_FREE(bmp);
+
+ return TRUE;
}
Index: src/win/wddraw.h
===================================================================
--- src/win/wddraw.h (revision 5686)
+++ src/win/wddraw.h (working copy)
@@ -79,11 +79,11 @@
AL_FUNC(int, gfx_directx_poll_scroll, (void));
AL_FUNC(void, gfx_directx_created_sub_bitmap, (BITMAP *bmp, BITMAP *parent));
AL_FUNC(BITMAP *, gfx_directx_create_video_bitmap, (int width, int height));
-AL_FUNC(void, gfx_directx_destroy_video_bitmap, (BITMAP *bmp));
+AL_FUNC(int, gfx_directx_destroy_video_bitmap, (BITMAP *bmp));
AL_FUNC(int, gfx_directx_show_video_bitmap, (BITMAP *bmp));
AL_FUNC(int, gfx_directx_request_video_bitmap, (BITMAP *bmp));
AL_FUNC(BITMAP *, gfx_directx_create_system_bitmap, (int width, int height));
-AL_FUNC(void, gfx_directx_destroy_system_bitmap, (BITMAP *bmp));
+AL_FUNC(int, gfx_directx_destroy_system_bitmap, (BITMAP *bmp));
AL_FUNC(GFX_MODE_LIST *, gfx_directx_fetch_mode_list, (void));
AL_FUNC(int, gfx_directx_set_mouse_sprite, (struct BITMAP *sprite, int xfocus, int yfocus));
AL_FUNC(int, gfx_directx_show_mouse, (struct BITMAP *bmp, int x, int y));
Index: src/graphics.c
===================================================================
--- src/graphics.c (revision 5686)
+++ src/graphics.c (working copy)
@@ -1446,7 +1446,7 @@
if (pos->x < 0) {
/* the driver is in charge of this object */
- gfx_driver->destroy_video_bitmap(bitmap);
+ gfx_driver->destroy_video_bitmap(bitmap);
_AL_FREE(pos);
return;
}
@@ -1477,9 +1477,15 @@
/* special case for getting rid of system memory bitmaps */
ASSERT(gfx_driver != NULL);
+ /* For system bitmaps, we need to be a little careful: subbitmaps may
+ * need to be handled by the general purpose code. For this, we test
+ * the return value of gfx_driver->destroy_system_bitmap: this returns
+ * TRUE if it destroyed the bitmap and false if we need to do it here.
+ */
if (gfx_driver->destroy_system_bitmap) {
- gfx_driver->destroy_system_bitmap(bitmap);
- return;
+ if (gfx_driver->destroy_system_bitmap(bitmap))
+ return;
+ /* We destroy it using the regular bitmap destruction code */
}
}
Index: src/qnx/qphwin.c
===================================================================
--- src/qnx/qphwin.c (revision 5686)
+++ src/qnx/qphwin.c (working copy)
@@ -34,7 +34,7 @@
static void qnx_ph_vsync_win(void);
static void qnx_ph_set_palette_win(AL_CONST struct RGB *, int, int, int);
static BITMAP *qnx_ph_create_video_bitmap_win(int width, int height);
-static void qnx_ph_destroy_video_bitmap_win(BITMAP *bmp);
+static int qnx_ph_destroy_video_bitmap_win(BITMAP *bmp);
static int qnx_ph_show_video_bitmap_win(BITMAP *bmp);
@@ -610,11 +610,11 @@
/* qnx_ph_destroy_video_bitmap_win:
*/
-static void qnx_ph_destroy_video_bitmap_win(BITMAP *bmp)
+static int qnx_ph_destroy_video_bitmap_win(BITMAP *bmp)
{
if (bmp == screen) {
reused_screen = FALSE;
- return;
+ return TRUE;
}
if (bmp == pseudo_screen) {
@@ -632,6 +632,8 @@
PhDCRelease(BMP_EXTRA(bmp)->context);
destroy_photon_bitmap(bmp);
}
+
+ return TRUE;
}
Index: src/qnx/qphbmp.c
===================================================================
--- src/qnx/qphbmp.c (revision 5686)
+++ src/qnx/qphbmp.c (working copy)
@@ -214,11 +214,11 @@
/* qnx_ph_destroy_video_bitmap:
*/
-void qnx_ph_destroy_video_bitmap(BITMAP *bmp)
+int qnx_ph_destroy_video_bitmap(BITMAP *bmp)
{
if (bmp == screen) {
reused_screen = FALSE;
- return;
+ return TRUE;
}
if (bmp == ph_frontbuffer) {
@@ -230,6 +230,8 @@
PhDCRelease(BMP_EXTRA(bmp)->context);
destroy_photon_bitmap(bmp);
+
+ return TRUE;
}
Index: src/macosx/quartz.m
===================================================================
--- src/macosx/quartz.m (revision 5686)
+++ src/macosx/quartz.m (working copy)
@@ -215,12 +215,12 @@
/* osx_qz_destroy_video_bitmap:
* Frees memory used by bitmap structure and releases associated GWorld.
*/
-void osx_qz_destroy_video_bitmap(BITMAP *bmp)
+int osx_qz_destroy_video_bitmap(BITMAP *bmp)
{
if (bmp) {
if (bmp == screen) {
osx_screen_used = FALSE;
- return;
+ return TRUE;
}
if (bmp->extra) {
if (BMP_EXTRA(bmp)->port)
@@ -229,6 +229,7 @@
}
free(bmp);
}
+ return TRUE;
}
Index: src/macosx/qzfull.m
===================================================================
--- src/macosx/qzfull.m (revision 5686)
+++ src/macosx/qzfull.m (working copy)
@@ -64,11 +64,11 @@
NULL, /* AL_METHOD(int, poll_scroll, (void)); */
NULL, /* AL_METHOD(void, enable_triple_buffer, (void)); */
osx_qz_create_video_bitmap, /* AL_METHOD(struct BITMAP *, create_video_bitmap, (int width, int height)); */
- osx_qz_destroy_video_bitmap, /* AL_METHOD(void, destroy_video_bitmap, (struct BITMAP *bitmap)); */
+ osx_qz_destroy_video_bitmap, /* AL_METHOD(int, destroy_video_bitmap, (struct BITMAP *bitmap)); */
osx_qz_show_video_bitmap, /* AL_METHOD(int, show_video_bitmap, (BITMAP *bitmap)); */
NULL, /* AL_METHOD(int, request_video_bitmap, (BITMAP *bitmap)); */
osx_qz_create_system_bitmap, /* AL_METHOD(BITMAP *, create_system_bitmap, (int width, int height)); */
- osx_qz_destroy_video_bitmap, /* AL_METHOD(void, destroy_system_bitmap, (BITMAP *bitmap)); */
+ osx_qz_destroy_video_bitmap, /* AL_METHOD(int, destroy_system_bitmap, (BITMAP *bitmap)); */
osx_mouse_set_sprite, /* AL_METHOD(int, set_mouse_sprite, (BITMAP *sprite, int xfocus, int yfocus)); */
osx_mouse_show, /* AL_METHOD(int, show_mouse, (BITMAP *bmp, int x, int y)); */
osx_mouse_hide, /* AL_METHOD(void, hide_mouse, (void)); */
Index: include/allegro/gfx.h
===================================================================
--- include/allegro/gfx.h (revision 5686)
+++ include/allegro/gfx.h (working copy)
@@ -81,11 +81,11 @@
AL_METHOD(int, poll_scroll, (void));
AL_METHOD(void, enable_triple_buffer, (void));
AL_METHOD(struct BITMAP *, create_video_bitmap, (int width, int height));
- AL_METHOD(void, destroy_video_bitmap, (struct BITMAP *bitmap));
+ AL_METHOD(int, destroy_video_bitmap, (struct BITMAP *bitmap));
AL_METHOD(int, show_video_bitmap, (struct BITMAP *bitmap));
AL_METHOD(int, request_video_bitmap, (struct BITMAP *bitmap));
AL_METHOD(struct BITMAP *, create_system_bitmap, (int width, int height));
- AL_METHOD(void, destroy_system_bitmap, (struct BITMAP *bitmap));
+ AL_METHOD(int, destroy_system_bitmap, (struct BITMAP *bitmap));
AL_METHOD(int, set_mouse_sprite, (struct BITMAP *sprite, int xfocus, int yfocus));
AL_METHOD(int, show_mouse, (struct BITMAP *bmp, int x, int y));
AL_METHOD(void, hide_mouse, (void));