SDL v1.2

SDL_SWSURFACE、SDL_HWSURFACE


區別如下:

SDL_SWSURFACE從系統記憶體配置使用(system memory)
SDL_HWSURFACE從顯示卡記憶體配置使用(video memory if possible), 讀寫Pixels時,需要先呼叫SDL_LockSurface()鎖住記憶體

(SDL 1.2.15)src/video/SDL_video.c

583 SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
...
683   mode = video->SetVideoMode(this, prev_mode,video_w,video_h,video_bpp,flags);

(SDL 1.2.15)src/video/fbcon/SDL_fbvideo.c

998 static SDL_Surface *FB_SetVideoMode(_THIS, SDL_Surface *current,
999         int width, int height, int bpp, Uint32 flags)
...
1132   /* Set up the new mode framebuffer */
1133   current->flags &= SDL_FULLSCREEN;
1134   if (shadow_fb) {
1135     current->flags |= SDL_SWSURFACE;
1136   } else {
1137     current->flags |= SDL_HWSURFACE;
1138   }
1139   current->w = vinfo.xres;
1140   current->h = vinfo.yres;
1141   if (shadow_fb) {
1142     current->pitch = current->w * ((vinfo.bits_per_pixel + 7) / 8);
1143     current->pixels = shadow_mem;
1144     physlinebytes = finfo.line_length;
1145   } else {
1146     current->pitch = finfo.line_length;
1147     current->pixels = mapped_mem+mapped_offset;
1148   }
1149 
1150   /* Set up the information for hardware surfaces */
1151   surfaces_mem = (char *)current->pixels +
1152     vinfo.yres_virtual*current->pitch;
1153   surfaces_len = (shadow_fb) ?
1154     0 : (mapped_memlen-(surfaces_mem-mapped_mem));
1155 
1156   FB_FreeHWSurfaces(this);
1157   FB_InitHWSurfaces(this, current, surfaces_mem, surfaces_len);

1218 static int FB_InitHWSurfaces(_THIS, SDL_Surface *screen, char *base, int size)
1219 {
1220   vidmem_bucket *bucket;
1221 
1222   surfaces_memtotal = size;
1223   surfaces_memleft = size;
1224 
1225   if ( surfaces_memleft > 0 ) {
1226     bucket = (vidmem_bucket *)SDL_malloc(sizeof(*bucket));

(SDL 1.2.15)src/stdlib/SDL_malloc.c

614 #define malloc  SDL_malloc


返回上一頁