Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. int CreatePixmap(pixmap_t *io)
  3. {
  4.      local_pixmap_t *pixmap;
  5.  
  6.      unsigned pitch;
  7.      size_t size;
  8.  
  9.      void *local;
  10.  
  11.      if( (io->width == 0) || (io->width > 2048)||
  12.          (io->height == 0)|| (io->height > 2048))
  13.      {
  14.         dbgprintf("Invalid pixmap size w:%d h:%d\n", io->width,io->height);
  15.         return ERR_PARAM;
  16.      };
  17.  
  18.      pitch = ((io->width+15)&~15)*4;
  19.      size = pitch*io->height;
  20.  
  21.      dbgprintf("pitch = %d\n", pitch);
  22.  
  23.      local = rhd_mem_alloc(&rhd,RHD_MEM_FB,size) ;
  24.      if ( !local)
  25.      {
  26.         dbgprintf("Not enough memory for pixmap\n");
  27.         return ERR_PARAM;
  28.      };
  29.  
  30.      pixmap = malloc(sizeof(local_pixmap_t));
  31.      if(!pixmap)
  32.      {
  33.         rhd_mem_free(&rhd, RHD_MEM_FB,local);
  34.         return ERR_PARAM;
  35.      }
  36.      else
  37.      {
  38.         void *mapped;
  39.  
  40.         size = (size+4095) & ~ 4095;
  41.  
  42.         if (mapped = UserAlloc(size))
  43.         {
  44.            CommitPages(mapped, ((u32_t)local+rhd.PhisBase)|7|(1<<9), size);
  45.  
  46.            io->mapped = mapped;
  47.            io->pitch   = pitch;
  48.            io->handle  = (u32_t)pixmap;
  49.  
  50.            pixmap->width   = io->width;
  51.            pixmap->height  = io->height;
  52.            pixmap->format  = PICT_a8r8g8b8;
  53.            pixmap->flags   = io->flags;
  54.            pixmap->pitch   = pitch;
  55.            pixmap->mapped  = mapped;
  56.            pixmap->pitch_offset =  ((pitch/64)<<22)| (((u32_t)local+rhd.FbIntAddress)>>10);
  57.            pixmap->local   = local;
  58.  
  59.            dbgprintf("pixmap.pitch_offset: %x\n", pixmap->pitch_offset);
  60.            dbgprintf("width: %d height: %d\n",pixmap->width,pixmap->height );
  61.            dbgprintf("map at %x\n", pixmap->mapped);
  62.  
  63.            return ERR_OK;
  64.         };
  65.         rhd_mem_free(&rhd, RHD_MEM_FB,local);
  66.         free(pixmap);
  67.      };
  68.      return ERR_PARAM;
  69. };
  70.  
  71.  
  72. int DestroyPixmap( pixmap_t *io )
  73. {
  74.      local_pixmap_t *pixmap;
  75.      size_t size;
  76.  
  77.      dbgprintf("Destroy pixmap %x\n", io->handle);
  78.  
  79.      if(io->handle == -1)
  80.         return ERR_PARAM;
  81.      else
  82.         pixmap = (local_pixmap_t*)io->handle;
  83.  
  84.      size = (pixmap->pitch*pixmap->height+4095) & ~ 4095;
  85.  
  86.      UnmapPages(pixmap->mapped, size);
  87.      UserFree(pixmap->mapped);
  88.  
  89.      rhd_mem_free(&rhd,RHD_MEM_FB,pixmap->local);
  90.      free(pixmap);
  91.  
  92.      io->format  = 0;
  93.      io->pitch   = 0;
  94.      io->mapped  = NULL;
  95.      io->handle  = 0;
  96.  
  97.      return ERR_OK;
  98. };
  99.