Mercurial > sdl-ios-xcode
view src/video/SDL_blendrect.c @ 3162:dc1eb82ffdaa
Von: Thomas Zimmermann
Betreff: [SDL] [PATCH] Make static variables const
Datum: Tue, 19 May 2009 19:45:37 +0200
Hi,
this is a set of simple changes which make some of SDL's internal static
arrays constant. The purpose is to shrink the number of write-able
static bytes and thus increase the number of memory pages shared between
SDL applications.
The patch set is against trunk@4513. Each of the attached patch files is
specific to a sub-system. The set is completed by a second mail, because
of the list's 40 KiB limit.
The files readelf-r4513.txt and readelf-const-patch.txt where made by
calling 'readelf -S libSDL.so'. They show the difference in ELF sections
without and with the patch. Some numbers measured on my x86-64:
Before
[13] .rodata PROGBITS 00000000000eaaa0 000eaaa0
0000000000008170 0000000000000000 A 0 0 32
[19] .data.rel.ro PROGBITS 00000000003045e0 001045e0
00000000000023d0 0000000000000000 WA 0 0 32
[23] .data PROGBITS 00000000003076e0 001076e0
0000000000004988 0000000000000000 WA 0 0 32
After
[13] .rodata PROGBITS 00000000000eaaa0 000eaaa0
0000000000009a50 0000000000000000 A 0 0 32
[19] .data.rel.ro PROGBITS 0000000000306040 00106040
0000000000002608 0000000000000000 WA 0 0 32
[23] .data PROGBITS 0000000000309360 00109360
0000000000002e88 0000000000000000 WA 0 0 32
The size of the write-able data section decreased considerably. Some
entries became const-after-relocation, while most of its content went
straight into the read-only data section.
Best regards, Thomas
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 03 Jun 2009 04:37:27 +0000 |
parents | 3a9636c83849 |
children | 0267b8b1595c |
line wrap: on
line source
/* SDL - Simple DirectMedia Layer Copyright (C) 1997-2009 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Sam Lantinga slouken@libsdl.org */ #include "SDL_config.h" #include "SDL_video.h" #include "SDL_draw.h" static int SDL_BlendRect_RGB555(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555); break; default: FILLRECT(Uint16, DRAW_SETPIXEL_RGB555); break; } return 0; } static int SDL_BlendRect_RGB565(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565); break; default: FILLRECT(Uint16, DRAW_SETPIXEL_RGB565); break; } return 0; } static int SDL_BlendRect_RGB888(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_RGB888); break; } return 0; } static int SDL_BlendRect_ARGB8888(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888); break; } return 0; } static int SDL_BlendRect_RGB(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; unsigned inva = 0xff - a; switch (fmt->BytesPerPixel) { case 2: switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB); break; default: FILLRECT(Uint16, DRAW_SETPIXEL_RGB); break; } return 0; case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_RGB); break; } return 0; default: SDL_Unsupported(); return -1; } } static int SDL_BlendRect_RGBA(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; unsigned inva = 0xff - a; switch (fmt->BytesPerPixel) { case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA); break; case SDL_BLENDMODE_ADD: FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA); break; case SDL_BLENDMODE_MOD: FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA); break; default: FILLRECT(Uint32, DRAW_SETPIXEL_RGBA); break; } return 0; default: SDL_Unsupported(); return -1; } } int SDL_BlendRect(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; /* This function doesn't work on surfaces < 8 bpp */ if (fmt->BitsPerPixel < 8) { SDL_SetError("SDL_BlendRect(): Unsupported surface format"); return (-1); } /* If 'dstrect' == NULL, then fill the whole surface */ if (dstrect) { /* Perform clipping */ if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) { return (0); } } else { dstrect = &dst->clip_rect; } if ((blendMode == SDL_BLENDMODE_BLEND) || (blendMode == SDL_BLENDMODE_ADD)) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } switch (fmt->BitsPerPixel) { case 15: switch (fmt->Rmask) { case 0x7C00: return SDL_BlendRect_RGB555(dst, dstrect, blendMode, r, g, b, a); } break; case 16: switch (fmt->Rmask) { case 0xF800: return SDL_BlendRect_RGB565(dst, dstrect, blendMode, r, g, b, a); } break; case 32: switch (fmt->Rmask) { case 0x00FF0000: if (!fmt->Amask) { return SDL_BlendRect_RGB888(dst, dstrect, blendMode, r, g, b, a); } else { return SDL_BlendRect_ARGB8888(dst, dstrect, blendMode, r, g, b, a); } break; } default: break; } if (!fmt->Amask) { return SDL_BlendRect_RGB(dst, dstrect, blendMode, r, g, b, a); } else { return SDL_BlendRect_RGBA(dst, dstrect, blendMode, r, g, b, a); } } /* vi: set ts=4 sw=4 expandtab: */