SetAlpha and UpdateRect Performance

Hi,

I’m using the following code to dim the screen (i.e. to disable focus on the
background for a popup menu) on an embeded linux device.

However, it takes almost a complete second for UpdateRect to complete. Can
anyone comment on improving the performance of this code?

Thanks!

void dim_screen (SDL_Rect* rect)
{
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 160);
SDL_FillRect(screen, rect, SDL_MapRGB(screen->format,1,1,1));
SDL_UpdateRect(screen, rect->x, rect->y, rect->w, rect->h);
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 255);
}

It’s not really clear if you’re using all of this correctly without any code
context. In what context does one use ‘dim_screen’? How frequently are you
calling this?

Are you sure that it’s the call to SDL_UpdateRect that is slow? I would be
very surprised to see it take more than 10ms on a reasonably-sized display
surface, even on an embedded device. Where else are you calling
SDL_UpdateRect or SDL_Flip?

‘screen’ must be your display surface. I’ve never messed with the
per-surface alpha of the display surface. Does that work? I usually blit a
black surface on the screen and modify the alpha of that surface.

Jonny DOn Fri, Mar 12, 2010 at 1:29 PM, Dan wrote:

Hi,

I’m using the following code to dim the screen (i.e. to disable focus on
the
background for a popup menu) on an embeded linux device.

However, it takes almost a complete second for UpdateRect to complete. Can
anyone comment on improving the performance of this code?

Thanks!

void dim_screen (SDL_Rect* rect)
{
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 160);
SDL_FillRect(screen, rect, SDL_MapRGB(screen->format,1,1,1));
SDL_UpdateRect(screen, rect->x, rect->y, rect->w, rect->h);
SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 255);
}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Dan,

Have you tried taking another approach and just making a "dimmed"
version of your background as a screen shot?

Then you can keep that in a surface and use it for the background when
your popup menu is displayed…

ErikOn Fri, Mar 12, 2010 at 11:29 AM, Dan wrote:

Hi,

I’m using the following code to dim the screen (i.e. to disable focus on the
background for a popup menu) on an embeded linux device.

However, it takes almost a complete second for UpdateRect to complete. Can
anyone comment on improving the performance of this code?

Thanks!

void dim_screen (SDL_Rect* rect)
{
? ?SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 160);
? ?SDL_FillRect(screen, rect, SDL_MapRGB(screen->format,1,1,1));
? ?SDL_UpdateRect(screen, rect->x, rect->y, rect->w, rect->h);
? ?SDL_SetAlpha(screen, SDL_SRCALPHA | SDL_RLEACCEL, 255);
}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Erik Yuzwa
I’d love to help out! Find me on:


http://www.erikyuzwa.com
http://www.twitter.com/eyuzwa