Subversion Repositories Kolibri OS

Rev

Rev 3292 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <stdio.h>
  3. #include <pixlib2.h>
  4. #include "system.h"
  5.  
  6.  
  7. #define DISPLAY_VERSION     0x0200     /*      2.00     */
  8.  
  9. #define SRV_GETVERSION       0
  10. #define SRV_GET_CAPS         3
  11.  
  12. #define SRV_CREATE_SURFACE  10
  13. #define SRV_DESTROY_SURFACE     11
  14. #define SRV_LOCK_SURFACE    12
  15. #define SRV_UNLOCK_SURFACE      13
  16. #define SRV_RESIZE_SURFACE      14
  17. #define SRV_BLIT_BITMAP         15
  18. #define SRV_BLIT_TEXTURE        16
  19. #define SRV_BLIT_VIDEO          17
  20.  
  21.  
  22. #define BUFFER_SIZE(n) ((n)*sizeof(uint32_t))
  23. #define __ALIGN_MASK(x,mask)  (((x)+(mask))&~(mask))
  24. #define ALIGN(x,a)            __ALIGN_MASK(x,(typeof(x))(a)-1)
  25.  
  26. int sna_init(uint32_t service);
  27. void sna_fini();    
  28.  
  29. int  sna_create_bitmap(bitmap_t *bitmap);
  30. void sna_destroy_bitmap(bitmap_t *bitmap);
  31. void sna_lock_bitmap(bitmap_t *bitmap);
  32. int  sna_blit_copy(bitmap_t *src_bitmap, int dst_x, int dst_y,
  33.                   int w, int h, int src_x, int src_y);
  34. int  sna_blit_tex(bitmap_t *src_bitmap, int dst_x, int dst_y,
  35.                   int w, int h, int src_x, int src_y);
  36.  
  37.  
  38. static uint32_t service;
  39. static uint32_t blit_caps;
  40. static uint32_t screen_width;
  41. static uint32_t screen_height;
  42.  
  43. typedef struct
  44. {
  45.   unsigned      handle;
  46.   unsigned      io_code;
  47.   void          *input;
  48.   int           inp_size;
  49.   void          *output;
  50.   int           out_size;
  51. }ioctl_t;
  52.  
  53.  
  54. typedef struct
  55. {
  56.     uint32_t  idx;
  57.     union
  58.     {
  59.         uint32_t opt[2];
  60.         struct {
  61.             uint32_t max_tex_width;
  62.             uint32_t max_tex_height;
  63.         }cap1;
  64.     };
  65. }hwcaps_t;
  66.  
  67. static uint32_t get_service(char *name)
  68. {
  69.   uint32_t retval = 0;
  70.   asm volatile ("int $0x40"
  71.       :"=a"(retval)
  72.       :"a"(68),"b"(16),"c"(name)
  73.       :"memory");
  74.  
  75.   return retval;
  76. };
  77.  
  78. static int call_service(ioctl_t *io)
  79. {
  80.   int retval;
  81.  
  82.   asm volatile("int $0x40"
  83.       :"=a"(retval)
  84.       :"a"(68),"b"(17),"c"(io)
  85.       :"memory","cc");
  86.  
  87.   return retval;
  88. };
  89.  
  90.  
  91. uint32_t init_pixlib(uint32_t caps)
  92. {
  93.     uint32_t  api_version;
  94.     uint32_t  screensize;
  95.     hwcaps_t  hwcaps;
  96.     ioctl_t   io;
  97.  
  98.  //   __asm__ __volatile__("int3");
  99.  
  100.     screensize    = GetScreenSize();
  101.     screen_width  = screensize >> 16;
  102.     screen_height = screensize & 0xFFFF;
  103.  
  104.     service = get_service("DISPLAY");
  105.     if(service == 0)
  106.         goto fail;
  107.  
  108.     io.handle   = service;
  109.     io.io_code  = SRV_GETVERSION;
  110.     io.input    = NULL;
  111.     io.inp_size = 0;
  112.     io.output   = &api_version;
  113.     io.out_size = BUFFER_SIZE(1);
  114.  
  115.     if (call_service(&io)!=0)
  116.         goto fail;
  117.  
  118.     if( (DISPLAY_VERSION > (api_version & 0xFFFF)) ||
  119.         (DISPLAY_VERSION < (api_version >> 16)))
  120.         goto fail;
  121.  
  122. #if 0
  123. /*
  124.  * Let's see what this service can do
  125. */
  126.     hwcaps.idx  = 0;
  127.  
  128.     io.handle   = service;
  129.     io.io_code  = SRV_GET_CAPS;
  130.     io.input    = &hwcaps;
  131.     io.inp_size = sizeof(hwcaps);
  132.     io.output   = NULL;
  133.     io.out_size = 0;
  134.  
  135.     if (call_service(&io)!=0)
  136.         goto fail;
  137.  
  138.     blit_caps = hwcaps.opt[0];
  139.  
  140.     printf("\nDISPLAY service handle %x\n", service);
  141.  
  142.     if( blit_caps )
  143.         printf("service caps %s%s%s\n",
  144.                (blit_caps & HW_BIT_BLIT) != 0 ?"HW_BIT_BLIT ":"",
  145.                (blit_caps & HW_TEX_BLIT) != 0 ?"HW_TEX_BLIT ":"",
  146.                (blit_caps & HW_VID_BLIT) != 0 ?"HW_VID_BLIT ":"");
  147. #endif
  148.  
  149.     blit_caps = caps & sna_init(service);
  150.  
  151.     if( blit_caps )
  152.         printf("service caps %s%s%s\n",
  153.                (blit_caps & HW_BIT_BLIT) != 0 ?"HW_BIT_BLIT ":"",
  154.                (blit_caps & HW_TEX_BLIT) != 0 ?"HW_TEX_BLIT ":"",
  155.                (blit_caps & HW_VID_BLIT) != 0 ?"HW_VID_BLIT ":"");
  156.    
  157.     return blit_caps;
  158.  
  159. fail:
  160.     service = 0;
  161.     return 0;
  162. };
  163.  
  164. void done_pixlib()
  165. {
  166.    
  167.     sna_fini();    
  168.    
  169. };
  170.  
  171.  
  172. int create_bitmap(bitmap_t *bitmap)
  173. {
  174.  //    __asm__ __volatile__("int3");
  175.  
  176.     uint32_t   size;
  177.     uint32_t   pitch;
  178.     uint8_t   *buffer;
  179.  
  180.     if( bitmap->flags & (HW_BIT_BLIT | HW_TEX_BLIT ))
  181.         return sna_create_bitmap(bitmap);
  182.  
  183. //    if( bitmap->flags &&  blit_caps & HW_BIT_BLIT )
  184. //        return sna_create_bitmap(bitmap);
  185.  
  186.     pitch = ALIGN(bitmap->width*4, 16);
  187.     size  = pitch * bitmap->height;
  188.  
  189.     buffer = (uint8_t*)user_alloc(size);
  190.     if( buffer )
  191.     {
  192.         bitmap->handle = 0;
  193.         bitmap->pitch  = pitch;
  194.         bitmap->data   = buffer;
  195.         bitmap->flags  = 0;
  196.         return 0;
  197.     };
  198.  
  199.     printf("Cannot alloc frame buffer\n\r");
  200.  
  201.     return -1;
  202.    
  203. };
  204.  
  205. int destroy_bitmap(bitmap_t *bitmap)
  206. {
  207.     if( bitmap->flags & (HW_BIT_BLIT | HW_TEX_BLIT ))
  208.         sna_destroy_bitmap(bitmap);
  209.     return 0;    
  210. };
  211.  
  212. int lock_bitmap(bitmap_t *bitmap)
  213. {
  214.  //    __asm__ __volatile__("int3");
  215.  
  216.     if( bitmap->flags & (HW_BIT_BLIT | HW_TEX_BLIT ))
  217.         sna_lock_bitmap(bitmap);
  218.  
  219.     return 0;
  220. };
  221.  
  222. int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y,
  223.                 int w, int h)
  224. {
  225.     int err;
  226.  
  227.     if( bitmap->flags & (HW_BIT_BLIT | HW_TEX_BLIT ) )
  228.         return sna_blit_tex(bitmap, dst_x, dst_y, w, h, 0, 0);
  229.  
  230.  
  231.     struct blit_call bc;
  232.  
  233.     bc.dstx = dst_x;
  234.     bc.dsty = dst_y;
  235.     bc.w    = w;
  236.     bc.h    = h;
  237.     bc.srcx = 0;
  238.     bc.srcy = 0;
  239.     bc.srcw = w;
  240.     bc.srch = h;
  241.     bc.stride = bitmap->pitch;
  242.     bc.bitmap = bitmap->data;
  243.  
  244.     __asm__ __volatile__(
  245.     "int $0x40"
  246.     :"=a"(err)
  247.     :"a"(73),"b"(0x00),"c"(&bc)
  248.     :"memory");
  249.    
  250.     return err;
  251. };
  252.  
  253. int resize_bitmap(bitmap_t *bitmap)
  254. {
  255.  //    __asm__ __volatile__("int3");
  256.  
  257.     if( bitmap->flags && blit_caps & HW_BIT_BLIT )
  258.     {
  259.         struct __attribute__((packed))
  260.         {
  261.             uint32_t  handle;
  262.             char     *data;
  263.             uint32_t  new_w;
  264.             uint32_t  new_h;
  265.             uint32_t  pitch;
  266.         }io_14;
  267.  
  268.         ioctl_t io;
  269.         int     err;
  270.  
  271.         io_14.handle = bitmap->handle;
  272.         io_14.new_w  = bitmap->width;
  273.         io_14.new_h  = bitmap->height;
  274.  
  275.         io.handle    = service;
  276.         io.io_code   = SRV_RESIZE_SURFACE;
  277.         io.input     = &io_14;
  278.         io.inp_size  = BUFFER_SIZE(5);
  279.         io.output    = NULL;
  280.         io.out_size  = 0;
  281.  
  282.         err = call_service(&io);
  283.         if(err==0)
  284.     {
  285.             bitmap->pitch  = io_14.pitch;
  286.             bitmap->data   = io_14.data;
  287.         };
  288.         return err;
  289.     };
  290.  
  291.     uint32_t   size;
  292.     uint32_t   pitch;
  293.     uint8_t   *buffer;
  294.  
  295.     pitch = ALIGN(bitmap->width*4, 16);
  296.     size  = pitch * bitmap->height;
  297.  
  298.     buffer = (uint8_t*)user_realloc(bitmap->data, size);
  299.     if( buffer )
  300.     {
  301.         bitmap->handle = 0;
  302.         bitmap->pitch  = pitch;
  303.         bitmap->data   = buffer;
  304.         return 0;
  305.     };
  306.  
  307.     printf("Cannot realloc frame buffer\n\r");
  308.  
  309.     return -1;
  310. };
  311.  
  312.