Subversion Repositories Kolibri OS

Rev

Rev 3248 | 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 inline uint32_t GetScreenSize()
  68. {
  69.      uint32_t retval;
  70.  
  71.      __asm__ __volatile__(
  72.      "int $0x40"
  73.      :"=a"(retval)
  74.      :"a"(61), "b"(1));
  75.      return retval;
  76. }
  77.  
  78. static uint32_t get_service(char *name)
  79. {
  80.   uint32_t retval = 0;
  81.   asm volatile ("int $0x40"
  82.       :"=a"(retval)
  83.       :"a"(68),"b"(16),"c"(name)
  84.       :"memory");
  85.  
  86.   return retval;
  87. };
  88.  
  89. static int call_service(ioctl_t *io)
  90. {
  91.   int retval;
  92.  
  93.   asm volatile("int $0x40"
  94.       :"=a"(retval)
  95.       :"a"(68),"b"(17),"c"(io)
  96.       :"memory","cc");
  97.  
  98.   return retval;
  99. };
  100.  
  101.  
  102. uint32_t init_pixlib(uint32_t caps)
  103. {
  104.     uint32_t  api_version;
  105.     uint32_t  screensize;
  106.     hwcaps_t  hwcaps;
  107.     ioctl_t   io;
  108.  
  109.  //   __asm__ __volatile__("int3");
  110.  
  111.     screensize    = GetScreenSize();
  112.     screen_width  = screensize >> 16;
  113.     screen_height = screensize & 0xFFFF;
  114.  
  115.     service = get_service("DISPLAY");
  116.     if(service == 0)
  117.         goto fail;
  118.  
  119.     io.handle   = service;
  120.     io.io_code  = SRV_GETVERSION;
  121.     io.input    = NULL;
  122.     io.inp_size = 0;
  123.     io.output   = &api_version;
  124.     io.out_size = BUFFER_SIZE(1);
  125.  
  126.     if (call_service(&io)!=0)
  127.         goto fail;
  128.  
  129.     if( (DISPLAY_VERSION > (api_version & 0xFFFF)) ||
  130.         (DISPLAY_VERSION < (api_version >> 16)))
  131.         goto fail;
  132.  
  133. #if 0
  134. /*
  135.  * Let's see what this service can do
  136. */
  137.     hwcaps.idx  = 0;
  138.  
  139.     io.handle   = service;
  140.     io.io_code  = SRV_GET_CAPS;
  141.     io.input    = &hwcaps;
  142.     io.inp_size = sizeof(hwcaps);
  143.     io.output   = NULL;
  144.     io.out_size = 0;
  145.  
  146.     if (call_service(&io)!=0)
  147.         goto fail;
  148.  
  149.     blit_caps = hwcaps.opt[0];
  150.  
  151.     printf("\nDISPLAY service handle %x\n", service);
  152.  
  153.     if( blit_caps )
  154.         printf("service caps %s%s%s\n",
  155.                (blit_caps & HW_BIT_BLIT) != 0 ?"HW_BIT_BLIT ":"",
  156.                (blit_caps & HW_TEX_BLIT) != 0 ?"HW_TEX_BLIT ":"",
  157.                (blit_caps & HW_VID_BLIT) != 0 ?"HW_VID_BLIT ":"");
  158. #endif
  159.  
  160.     blit_caps = caps & sna_init(service);
  161.  
  162.     if( blit_caps )
  163.         printf("service caps %s%s%s\n",
  164.                (blit_caps & HW_BIT_BLIT) != 0 ?"HW_BIT_BLIT ":"",
  165.                (blit_caps & HW_TEX_BLIT) != 0 ?"HW_TEX_BLIT ":"",
  166.                (blit_caps & HW_VID_BLIT) != 0 ?"HW_VID_BLIT ":"");
  167.    
  168.     return blit_caps;
  169.  
  170. fail:
  171.     service = 0;
  172.     return 0;
  173. };
  174.  
  175. void done_pixlib()
  176. {
  177.    
  178.     sna_fini();    
  179.    
  180. };
  181.  
  182.  
  183. int create_bitmap(bitmap_t *bitmap)
  184. {
  185.  //    __asm__ __volatile__("int3");
  186.  
  187.     uint32_t   size;
  188.     uint32_t   pitch;
  189.     uint8_t   *buffer;
  190.  
  191.     if( bitmap->flags & (HW_BIT_BLIT | HW_TEX_BLIT ))
  192.         return sna_create_bitmap(bitmap);
  193.  
  194. //    if( bitmap->flags &&  blit_caps & HW_BIT_BLIT )
  195. //        return sna_create_bitmap(bitmap);
  196.  
  197.     pitch = ALIGN(bitmap->width*4, 16);
  198.     size  = pitch * bitmap->height;
  199.  
  200.     buffer = (uint8_t*)user_alloc(size);
  201.     if( buffer )
  202.     {
  203.         bitmap->handle = 0;
  204.         bitmap->pitch  = pitch;
  205.         bitmap->data   = buffer;
  206.         bitmap->flags  = 0;
  207.         return 0;
  208.     };
  209.  
  210.     printf("Cannot alloc frame buffer\n\r");
  211.  
  212.     return -1;
  213.    
  214. };
  215.  
  216. int destroy_bitmap(bitmap_t *bitmap)
  217. {
  218.     if( bitmap->flags & (HW_BIT_BLIT | HW_TEX_BLIT ))
  219.         sna_destroy_bitmap(bitmap);
  220.     return 0;    
  221. };
  222.  
  223. int lock_bitmap(bitmap_t *bitmap)
  224. {
  225.  //    __asm__ __volatile__("int3");
  226.  
  227.     if( bitmap->flags & (HW_BIT_BLIT | HW_TEX_BLIT ))
  228.         sna_lock_bitmap(bitmap);
  229.  
  230.     return 0;
  231. };
  232.  
  233. int blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y,
  234.                 int w, int h)
  235. {
  236.     int err;
  237.  
  238.     if( bitmap->flags & (HW_BIT_BLIT | HW_TEX_BLIT ) )
  239.         return sna_blit_tex(bitmap, dst_x, dst_y, w, h, 0, 0);
  240.  
  241.  
  242.     struct blit_call bc;
  243.  
  244.     bc.dstx = dst_x;
  245.     bc.dsty = dst_y;
  246.     bc.w    = w;
  247.     bc.h    = h;
  248.     bc.srcx = 0;
  249.     bc.srcy = 0;
  250.     bc.srcw = w;
  251.     bc.srch = h;
  252.     bc.stride = bitmap->pitch;
  253.     bc.bitmap = bitmap->data;
  254.  
  255.     __asm__ __volatile__(
  256.     "int $0x40"
  257.     :"=a"(err)
  258.     :"a"(73),"b"(0x00),"c"(&bc)
  259.     :"memory");
  260.    
  261.     return err;
  262. };
  263.  
  264. int resize_bitmap(bitmap_t *bitmap)
  265. {
  266.  //    __asm__ __volatile__("int3");
  267.  
  268.     if( bitmap->flags && blit_caps & HW_BIT_BLIT )
  269.     {
  270.         struct __attribute__((packed))
  271.         {
  272.             uint32_t  handle;
  273.             char     *data;
  274.             uint32_t  new_w;
  275.             uint32_t  new_h;
  276.             uint32_t  pitch;
  277.         }io_14;
  278.  
  279.         ioctl_t io;
  280.         int     err;
  281.  
  282.         io_14.handle = bitmap->handle;
  283.         io_14.new_w  = bitmap->width;
  284.         io_14.new_h  = bitmap->height;
  285.  
  286.         io.handle    = service;
  287.         io.io_code   = SRV_RESIZE_SURFACE;
  288.         io.input     = &io_14;
  289.         io.inp_size  = BUFFER_SIZE(5);
  290.         io.output    = NULL;
  291.         io.out_size  = 0;
  292.  
  293.         err = call_service(&io);
  294.         if(err==0)
  295.     {
  296.             bitmap->pitch  = io_14.pitch;
  297.             bitmap->data   = io_14.data;
  298.         };
  299.         return err;
  300.     };
  301.  
  302.     uint32_t   size;
  303.     uint32_t   pitch;
  304.     uint8_t   *buffer;
  305.  
  306.     pitch = ALIGN(bitmap->width*4, 16);
  307.     size  = pitch * bitmap->height;
  308.  
  309.     buffer = (uint8_t*)user_realloc(bitmap->data, size);
  310.     if( buffer )
  311.     {
  312.         bitmap->handle = 0;
  313.         bitmap->pitch  = pitch;
  314.         bitmap->data   = buffer;
  315.         return 0;
  316.     };
  317.  
  318.     printf("Cannot realloc frame buffer\n\r");
  319.  
  320.     return -1;
  321. };
  322.  
  323.