Merging the resize buttons work.

This commit is contained in:
Pere Pujal i Carabantes 2021-01-18 14:32:51 +01:00
commit 2faf78fd21
2 changed files with 25 additions and 8 deletions

View file

@ -8,7 +8,7 @@ http://www.tuxpaint.org/
$Id$ $Id$
2021.January.15 (0.9.26) 2021.January.16 (0.9.26)
* New Magic Tools: * New Magic Tools:
---------------- ----------------
* Pixels * Pixels
@ -29,6 +29,14 @@ $Id$
* Other Improvements * Other Improvements
------------------ ------------------
* Reduce CPU usage by increasing delay in main loop
from 1ms to 10ms, and only using SDL's Timer subsystem
when scrolling happens.
(Details at
https://sourceforge.net/p/tuxpaint/tuxpaint/ci/7727b995c53df208596eff89ac1acb954a16098c/)
Mark K. Kim <markuskimius@gmail.com>
(h/t @bbugwong on Twitter for reporting the issue)
* If parent of export directory doesn't exist, Tux Paint will * If parent of export directory doesn't exist, Tux Paint will
try to create it as well. try to create it as well.
(Only one level up; e.g., with an export location like (Only one level up; e.g., with an export location like

View file

@ -4013,18 +4013,25 @@ static void mainloop(void)
if (!scrolling && event.type == SDL_MOUSEBUTTONDOWN) if (!scrolling && event.type == SDL_MOUSEBUTTONDOWN)
{ {
/* printf("Starting scrolling\n"); */ DEBUG_PRINTF("Starting scrolling\n");
memcpy(&scrolltimer_event, &event, sizeof(SDL_Event)); memcpy(&scrolltimer_event, &event, sizeof(SDL_Event));
scrolltimer_event.type = TP_SDL_MOUSEBUTTONSCROLL; scrolltimer_event.type = TP_SDL_MOUSEBUTTONSCROLL;
scrolling = 1; /*
* We enable the timer subsystem only when needed (e.g., to use SDL_AddTimer() needed
* for scrolling) then disable it immediately after (e.g., after the timer has fired or
* after SDL_RemoveTimer()) because enabling the timer subsystem in SDL1 has a high
* energy impact on the Mac.
*/
scrolling = 1;
SDL_InitSubSystem(SDL_INIT_TIMER);
scrolltimer = scrolltimer =
SDL_AddTimer(REPEAT_SPEED, scrolltimer_callback, (void *)&scrolltimer_event); SDL_AddTimer(REPEAT_SPEED, scrolltimer_callback, (void *)&scrolltimer_event);
} }
else else
{ {
/* printf("Continuing scrolling\n"); */ DEBUG_PRINTF("Continuing scrolling\n");
scrolltimer = scrolltimer =
SDL_AddTimer(REPEAT_SPEED / 3, scrolltimer_callback, (void *)&scrolltimer_event); SDL_AddTimer(REPEAT_SPEED / 3, scrolltimer_callback, (void *)&scrolltimer_event);
} }
@ -4040,6 +4047,7 @@ static void mainloop(void)
scrolltimer = NULL; scrolltimer = NULL;
} }
scrolling = 0; scrolling = 0;
SDL_QuitSubSystem(SDL_INIT_TIMER);
} }
} }
} }
@ -4931,6 +4939,7 @@ static void mainloop(void)
scrolltimer = NULL; scrolltimer = NULL;
} }
scrolling = 0; scrolling = 0;
SDL_QuitSubSystem(SDL_INIT_TIMER);
/* printf("Killing scrolling\n"); */ /* printf("Killing scrolling\n"); */
} }
@ -5589,7 +5598,7 @@ static void mainloop(void)
handle_motioners(oldpos_x, oldpos_y, motioner, hatmotioner, old_hat_ticks, val_x, val_y, valhat_x, valhat_y); handle_motioners(oldpos_x, oldpos_y, motioner, hatmotioner, old_hat_ticks, val_x, val_y, valhat_x, valhat_y);
SDL_Delay(1); SDL_Delay(10);
} }
while (!done); while (!done);
} }
@ -17298,13 +17307,13 @@ static Uint32 scrolltimer_callback(Uint32 interval, void *param)
/* printf("scrolltimer_callback(%d) -- ", interval); */ /* printf("scrolltimer_callback(%d) -- ", interval); */
if (scrolling) if (scrolling)
{ {
/* printf("(Still scrolling)\n"); */ DEBUG_PRINTF("(Still scrolling)\n");
SDL_PushEvent((SDL_Event *) param); SDL_PushEvent((SDL_Event *) param);
return interval; return interval;
} }
else else
{ {
/* printf("(all done)\n"); */ DEBUG_PRINTF("(all done scrolling)\n");
return 0; return 0;
} }
} }
@ -23933,7 +23942,7 @@ static void setup(void)
if (joystick_dev != -1) if (joystick_dev != -1)
do_lock_file(); do_lock_file();
init_flags = SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK; init_flags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
if (use_sound) if (use_sound)
init_flags |= SDL_INIT_AUDIO; init_flags |= SDL_INIT_AUDIO;
if (!fullscreen) if (!fullscreen)