iOS/libraries/allegro/allegro/src/modesel.c
/* create_mode_list:
 *  Creates a mode list table.
 *  Returns 0 on success and -1 on failure.
 */
Creates a mode list table.
Returns 0 on success and -1 on failure.
Creates a mode list table . Returns 0 on success and - 1 on failure .
static int create_mode_list(DRIVER_LIST *driver_list_entry, FILTER_FUNCTION filter)
{
   MODE_LIST *temp_mode_list = NULL;
   GFX_MODE_LIST *gfx_mode_list;
   GFX_MODE *gfx_mode_entry;
   int mode, n, w, h, bpp;
   int is_autodetected = ((driver_list_entry->id == GFX_AUTODETECT)
			  || (driver_list_entry->id == GFX_AUTODETECT_WINDOWED)
			  || (driver_list_entry->id == GFX_AUTODETECT_FULLSCREEN));
   driver_list_entry->mode_count = 0;
   if (is_autodetected || !(gfx_mode_list = get_gfx_mode_list(driver_list_entry->id))) {
      if (!filter) {
	 driver_list_entry->mode_count = sizeof(default_mode_list) / sizeof(MODE_LIST) - 1;
	 driver_list_entry->mode_list = default_mode_list;
	 driver_list_entry->mode_list_owned = FALSE;
	 return 0;
      }
      for (mode = 0; default_mode_list[mode].w; mode++) {
	 w = default_mode_list[mode].w;
	 h = default_mode_list[mode].h;
	 for (n = 0; n < N_COLOR_DEPTH; n++) {
	    bpp = bpp_value(n);
	    if (filter(driver_list_entry->id, w, h, bpp) == 0) {
	        if (add_mode(&temp_mode_list, &driver_list_entry->mode_count, w, h, bpp) != 0)
		  return -1;
	    }
	 }
      }
      if (driver_list_entry->mode_count > 0) {
	 if (terminate_list(&temp_mode_list, driver_list_entry->mode_count) != 0)
	    return -1;
      }
      driver_list_entry->mode_list = temp_mode_list;
      driver_list_entry->mode_list_owned = TRUE;
      return 0;
   }
   for (gfx_mode_entry = gfx_mode_list->mode; gfx_mode_entry->width; gfx_mode_entry++) {
      w = gfx_mode_entry->width;
      h = gfx_mode_entry->height;
      bpp = gfx_mode_entry->bpp;
      if (!filter || filter(driver_list_entry->id, w, h, bpp) == 0) {
	 if (add_mode(&temp_mode_list, &driver_list_entry->mode_count, w, h, bpp) != 0) {
	    destroy_gfx_mode_list(gfx_mode_list);
	    return -1;
	 }
      } 
   }
   if (driver_list_entry->mode_count > 0) {
      if (terminate_list(&temp_mode_list, driver_list_entry->mode_count) != 0) {
	 destroy_gfx_mode_list(gfx_mode_list);
	 return -1;
      }
   }
   driver_list_entry->mode_list = temp_mode_list;
   driver_list_entry->mode_list_owned = TRUE;
   destroy_gfx_mode_list(gfx_mode_list);
   return 0;
}
static int create_mode_list ( DRIVER_LIST * driver_list_entry , FILTER_FUNCTION filter ) { MODE_LIST * temp_mode_list = NULL ; GFX_MODE_LIST * gfx_mode_list ; GFX_MODE * gfx_mode_entry ; int mode , n , w , h , bpp ; int is_autodetected = ( ( driver_list_entry -> id == GFX_AUTODETECT ) || ( driver_list_entry -> id == GFX_AUTODETECT_WINDOWED ) || ( driver_list_entry -> id == GFX_AUTODETECT_FULLSCREEN ) ) ; driver_list_entry -> mode_count = 0 ; if ( is_autodetected || ! ( gfx_mode_list = get_gfx_mode_list ( driver_list_entry -> id ) ) ) { if ( ! filter ) { driver_list_entry -> mode_count = sizeof ( default_mode_list ) / sizeof ( MODE_LIST ) - 1 ; driver_list_entry -> mode_list = default_mode_list ; driver_list_entry -> mode_list_owned = FALSE ; return 0 ; } for ( mode = 0 ; default_mode_list [ mode ] . w ; mode ++ ) { w = default_mode_list [ mode ] . w ; h = default_mode_list [ mode ] . h ; for ( n = 0 ; n < N_COLOR_DEPTH ; n ++ ) { bpp = bpp_value ( n ) ; if ( filter ( driver_list_entry -> id , w , h , bpp ) == 0 ) { if ( add_mode ( & temp_mode_list , & driver_list_entry -> mode_count , w , h , bpp ) != 0 ) return -1 ; } } } if ( driver_list_entry -> mode_count > 0 ) { if ( terminate_list ( & temp_mode_list , driver_list_entry -> mode_count ) != 0 ) return -1 ; } driver_list_entry -> mode_list = temp_mode_list ; driver_list_entry -> mode_list_owned = TRUE ; return 0 ; } for ( gfx_mode_entry = gfx_mode_list -> mode ; gfx_mode_entry -> width ; gfx_mode_entry ++ ) { w = gfx_mode_entry -> width ; h = gfx_mode_entry -> height ; bpp = gfx_mode_entry -> bpp ; if ( ! filter || filter ( driver_list_entry -> id , w , h , bpp ) == 0 ) { if ( add_mode ( & temp_mode_list , & driver_list_entry -> mode_count , w , h , bpp ) != 0 ) { destroy_gfx_mode_list ( gfx_mode_list ) ; return -1 ; } } } if ( driver_list_entry -> mode_count > 0 ) { if ( terminate_list ( & temp_mode_list , driver_list_entry -> mode_count ) != 0 ) { destroy_gfx_mode_list ( gfx_mode_list ) ; return -1 ; } } driver_list_entry -> mode_list = temp_mode_list ; driver_list_entry -> mode_list_owned = TRUE ; destroy_gfx_mode_list ( gfx_mode_list ) ; return 0 ; }
create_mode_list:
  Creates a mode list table.
create_mode_list : Creates a mode list table .
/* Start with zero modes. */ /* We use the default mode list in two cases:
    *  - the driver is GFX_AUTODETECT*,
    *  - the driver doesn't support get_gfx_mode_list().
    */ /* Simply return the default mode list if we can. */ /* Build mode list from the default list. */ /* We should not terminate the list if the list is empty since the caller
       * of this function will simply discard this driver_list entry in that
       * case.
       */ /* Build mode list from the fetched list. */