iOS/libraries/allegro/allegro/src/psp/pgfx.c
/* psp_create_video_bitmap:
 *  Attempts to make a bitmap object for accessing offscreen video memory.
 */
Attempts to make a bitmap object for accessing offscreen video memory.
Attempts to make a bitmap object for accessing offscreen video memory .
static BITMAP *psp_create_video_bitmap(int width, int height)
{
   uintptr_t vram_addr, bitmap_offset = 0;
   GFX_VTABLE *vtable;
   BITMAP *bitmap;
   int pitch, used_height = height;
   int i, size, top_margin, left_margin;
   if (_color_depth == 8) {
      if (width >= SCREEN_W && height >= SCREEN_H)
         pitch = ALIGN_TO(width, 16);
      else
         pitch = width;
   }
   else {
      if (width == SCREEN_W && height == SCREEN_H) {
         pitch = MIN_BUF_WIDTH;
         used_height = MAX_SCR_HEIGHT;
         top_margin = (MAX_SCR_HEIGHT - height) / 2;
         left_margin = (MAX_SCR_WIDTH - width) / 2;
         bitmap_offset = (top_margin * MIN_BUF_WIDTH + left_margin) * BYTES_PER_PIXEL(_color_depth);
      }
      else
         pitch = ALIGN_TO(width, 8);
   }
   size = pitch * used_height * BYTES_PER_PIXEL(_color_depth);
   vram_addr = vmm_alloc_mem(size);
   if (!vram_addr)
      return NULL;
   for (i=0; i<size ;i++)
      *((unsigned char *)(vram_addr+i)) = 0;
   if (_color_depth == 8)
      vtable = &psp_vtable8;
   else
      vtable = _get_vtable(_color_depth);
   bitmap = _AL_MALLOC(sizeof(BITMAP) + (sizeof(char *) * height));
   if (!vtable || !bitmap) {
      vmm_free_mem(vram_addr, size);
      return NULL;
   }
   bitmap->w = bitmap->cr = width;
   bitmap->h = bitmap->cb = height;
   bitmap->clip = TRUE;
   bitmap->cl = bitmap->ct = 0;
   bitmap->vtable = vtable;
   bitmap->write_bank = bitmap->read_bank = _stub_bank_switch;
   bitmap->id = BMP_ID_VIDEO;
   bitmap->x_ofs = 0;
   bitmap->y_ofs = 0;
   bitmap->seg = _video_ds();
   if (height > 0) {
      bitmap->line[0] = (unsigned char *)(vram_addr + bitmap_offset);
      for (i=1; i<height; i++)
         bitmap->line[i] = bitmap->line[i-1] + pitch * BYTES_PER_PIXEL(_color_depth);
   }
   bitmap->extra = _AL_MALLOC(sizeof(struct BMP_EXTRA_INFO));
   if (!bitmap->extra) {
      vmm_free_mem(vram_addr, size);
      _AL_FREE(bitmap);
      return NULL;
   }
   BMP_EXTRA(bitmap)->pitch = pitch;
   BMP_EXTRA(bitmap)->size = size;
   BMP_EXTRA(bitmap)->hw_addr = vram_addr;
   return bitmap;
}
static BITMAP * psp_create_video_bitmap ( int width , int height ) { uintptr_t vram_addr , bitmap_offset = 0 ; GFX_VTABLE * vtable ; BITMAP * bitmap ; int pitch , used_height = height ; int i , size , top_margin , left_margin ; if ( _color_depth == 8 ) { if ( width >= SCREEN_W && height >= SCREEN_H ) pitch = ALIGN_TO ( width , 16 ) ; else pitch = width ; } else { if ( width == SCREEN_W && height == SCREEN_H ) { pitch = MIN_BUF_WIDTH ; used_height = MAX_SCR_HEIGHT ; top_margin = ( MAX_SCR_HEIGHT - height ) / 2 ; left_margin = ( MAX_SCR_WIDTH - width ) / 2 ; bitmap_offset = ( top_margin * MIN_BUF_WIDTH + left_margin ) * BYTES_PER_PIXEL ( _color_depth ) ; } else pitch = ALIGN_TO ( width , 8 ) ; } size = pitch * used_height * BYTES_PER_PIXEL ( _color_depth ) ; vram_addr = vmm_alloc_mem ( size ) ; if ( ! vram_addr ) return NULL ; for ( i = 0 ; i < size ; i ++ ) * ( ( unsigned char * ) ( vram_addr + i ) ) = 0 ; if ( _color_depth == 8 ) vtable = & psp_vtable8 ; else vtable = _get_vtable ( _color_depth ) ; bitmap = _AL_MALLOC ( sizeof ( BITMAP ) + ( sizeof ( char * ) * height ) ) ; if ( ! vtable || ! bitmap ) { vmm_free_mem ( vram_addr , size ) ; return NULL ; } bitmap -> w = bitmap -> cr = width ; bitmap -> h = bitmap -> cb = height ; bitmap -> clip = TRUE ; bitmap -> cl = bitmap -> ct = 0 ; bitmap -> vtable = vtable ; bitmap -> write_bank = bitmap -> read_bank = _stub_bank_switch ; bitmap -> id = BMP_ID_VIDEO ; bitmap -> x_ofs = 0 ; bitmap -> y_ofs = 0 ; bitmap -> seg = _video_ds ( ) ; if ( height > 0 ) { bitmap -> line [ 0 ] = ( unsigned char * ) ( vram_addr + bitmap_offset ) ; for ( i = 1 ; i < height ; i ++ ) bitmap -> line [ i ] = bitmap -> line [ i - 1 ] + pitch * BYTES_PER_PIXEL ( _color_depth ) ; } bitmap -> extra = _AL_MALLOC ( sizeof ( struct BMP_EXTRA_INFO ) ) ; if ( ! bitmap -> extra ) { vmm_free_mem ( vram_addr , size ) ; _AL_FREE ( bitmap ) ; return NULL ; } BMP_EXTRA ( bitmap ) -> pitch = pitch ; BMP_EXTRA ( bitmap ) -> size = size ; BMP_EXTRA ( bitmap ) -> hw_addr = vram_addr ; return bitmap ; }
psp_create_video_bitmap:
  Attempts to make a bitmap object for accessing offscreen video memory.
psp_create_video_bitmap : Attempts to make a bitmap object for accessing offscreen video memory .
/* This video bitmap or the derived sub bitmaps can be used for
          * page flipping. The pitch is calculated so that sceGuTexImage()
          * works correctly in that case.
          */ /* A regular 8 bpp video bitmap. */ /* Special code for video bitmaps created under truecolor modes that
          * can be used with the show_video_bitmap() and request_video_bitmap()
          * functions for page flipping and triple buffering.
          */ /* Center the bitmap. */ /* A regular truecolor video bitmap.
          * Its width must be multiple of 8 pixels in order to 
          * blit properly using sceGuCopyImage().
          */ /* Allocate video memory for the pixel data. */ /* Clean it. */ /* Create the Allegro bitmap. */ /* Setup info structure to store additional information. */