From 63dcf9cc258aaf2e2e2edd4b01939d9ccac75d97 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sat, 16 Apr 2011 18:24:24 +0000 Subject: [PATCH] Performance improvement for slow graphic systems: avoid lag on X11 (Issue 405,269) git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1780 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/sdlscreen.c | 31 +++++++++++++++++++++++++++++++ src/sdlscreen.h | 2 ++ src/windows.c | 7 +------ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/sdlscreen.c b/src/sdlscreen.c index a8ef9476..ee1127e6 100644 --- a/src/sdlscreen.c +++ b/src/sdlscreen.c @@ -99,6 +99,8 @@ short Min_X=0; short Min_Y=0; short Max_X=10000; short Max_Y=10000; +short Status_line_dirty_begin=0; +short Status_line_dirty_end=0; #endif #if (UPDATE_METHOD == UPDATE_METHOD_FULL_PAGE) @@ -131,6 +133,13 @@ void Flush_update(void) Min_X=Min_Y=10000; Max_X=Max_Y=0; } + if (Status_line_dirty_end) + { + SDL_UpdateRect(Screen_SDL, (18+(Status_line_dirty_begin*8))*Menu_factor_X*Pixel_width,Menu_status_Y*Pixel_height,(Status_line_dirty_end-Status_line_dirty_begin)*8*Menu_factor_X*Pixel_width,8*Menu_factor_Y*Pixel_height); + } + Status_line_dirty_begin=25; + Status_line_dirty_end=0; + #endif } @@ -166,6 +175,28 @@ void Update_rect(short x, short y, unsigned short width, unsigned short height) } +void Update_status_line(short char_pos, short width) +{ + #if (UPDATE_METHOD == UPDATE_METHOD_MULTI_RECTANGLE) + SDL_UpdateRect(Screen_SDL, (18+char_pos*8)*Menu_factor_X*Pixel_width,Menu_status_Y*Pixel_height,width*8*Menu_factor_X*Pixel_width,8*Menu_factor_Y*Pixel_height); + #endif + + #if (UPDATE_METHOD == UPDATE_METHOD_CUMULATED) + // Merge the ranges + if (Status_line_dirty_end < char_pos+width) + Status_line_dirty_end=char_pos+width; + if (Status_line_dirty_begin > char_pos) + Status_line_dirty_begin=char_pos; + #endif + + #if (UPDATE_METHOD == UPDATE_METHOD_FULL_PAGE) + (void)char_pos; // unused parameter + (void)width; // unused parameter + update_is_required=1; + #endif + +} + /// /// Converts a SDL_Surface (indexed colors or RGB) into an array of bytes /// (indexed colors). diff --git a/src/sdlscreen.h b/src/sdlscreen.h index d0b7d004..8c58a141 100644 --- a/src/sdlscreen.h +++ b/src/sdlscreen.h @@ -44,6 +44,8 @@ byte* Screen_pixels; void Update_rect(short x, short y, unsigned short width, unsigned short height); void Flush_update(void); +void Update_status_line(short char_pos, short width); + /// /// Converts a SDL_Surface (indexed colors or RGB) into an array of bytes /// (indexed colors). diff --git a/src/windows.c b/src/windows.c index 06f38b33..e2e5fa27 100644 --- a/src/windows.c +++ b/src/windows.c @@ -697,11 +697,7 @@ void Print_in_window(short x,short y,const char * str,byte text_color,byte backg void Print_in_menu(const char * str, short position) { Print_general((18+(position<<3))*Menu_factor_X,Menu_status_Y,str,MC_Black,MC_Light); - Update_rect((18+(position<<3))*Menu_factor_X,Menu_status_Y,strlen(str)*8*Menu_factor_X,8*Menu_factor_Y); - // Might want to replace the above by: - // SDL_UpdateRect(Screen_SDL, (18+(position<<3))*Menu_factor_X*Pixel_width,Menu_status_Y*Pixel_height,strlen(str)*8*Menu_factor_X*Pixel_width,8*Menu_factor_Y*Pixel_height); - // It can divide by 1000 the amount of pixels that are refreshed - // when you draw in top right of image. + Update_status_line(position, strlen(str)); } /// Draws the mouse coordinates on the menu @@ -728,7 +724,6 @@ void Print_coordinates(void) Num2str(Colorpicker_color,temp,3); Print_in_menu(temp,20); Print_general(170*Menu_factor_X,Menu_status_Y," ",0,Colorpicker_color); - Update_rect(170*Menu_factor_X,Menu_status_Y,8*Menu_factor_X,8*Menu_factor_Y); } Num2str((dword)Paintbrush_X,temp,4);