Subversion Repositories Kolibri OS

Rev

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

  1. /**************************************************************************
  2.  
  3. Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
  4. Copyright © 2002 David Dawes
  5.  
  6. All Rights Reserved.
  7.  
  8. Permission is hereby granted, free of charge, to any person obtaining a
  9. copy of this software and associated documentation files (the
  10. "Software"), to deal in the Software without restriction, including
  11. without limitation the rights to use, copy, modify, merge, publish,
  12. distribute, sub license, and/or sell copies of the Software, and to
  13. permit persons to whom the Software is furnished to do so, subject to
  14. the following conditions:
  15.  
  16. The above copyright notice and this permission notice (including the
  17. next paragraph) shall be included in all copies or substantial portions
  18. of the Software.
  19.  
  20. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
  24. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27.  
  28. **************************************************************************/
  29.  
  30. /*
  31.  * Authors:
  32.  *   Keith Whitwell <keith@tungstengraphics.com>
  33.  *   David Dawes <dawes@xfree86.org>
  34.  *
  35.  */
  36.  
  37. #ifndef _SNA_H_
  38. #define _SNA_H_
  39.  
  40. #ifdef HAVE_CONFIG_H
  41. #include "config.h"
  42. #endif
  43.  
  44. #include <stdint.h>
  45. #include <memory.h>
  46. #include <malloc.h>
  47.  
  48.  
  49. #include "intel_driver.h"
  50. #include "pciaccess.h"
  51.  
  52. #include "compiler.h"
  53.  
  54. //#define DBG(x)
  55. //#define DBG(x) ErrorF x
  56.  
  57. #define assert(x)
  58.  
  59.  
  60. typedef struct
  61. {
  62.   unsigned      handle;
  63.   unsigned      io_code;
  64.   void          *input;
  65.   int           inp_size;
  66.   void          *output;
  67.   int           out_size;
  68. }ioctl_t;
  69.  
  70. #define SRV_GET_INFO            20
  71. #define SRV_GET_PARAM           21
  72. #define SRV_I915_GEM_CREATE     22
  73. #define SRV_DRM_GEM_CLOSE       23
  74. #define SRV_I915_GEM_PIN        24
  75.  
  76. static int call_service(ioctl_t *io)
  77. {
  78.   int retval;
  79.  
  80.   asm volatile("int $0x40"
  81.       :"=a"(retval)
  82.       :"a"(68),"b"(17),"c"(io)
  83.       :"memory","cc");
  84.  
  85.   return retval;
  86. };
  87.  
  88.  
  89. #define PIXMAN_FORMAT(bpp,type,a,r,g,b) (((bpp) << 24) |    \
  90.                                         ((type) << 16) |    \
  91.                                         ((a) << 12)    |    \
  92.                                         ((r) << 8) |        \
  93.                                         ((g) << 4) |        \
  94.                                         ((b)))
  95. #define PIXMAN_TYPE_OTHER       0
  96. #define PIXMAN_TYPE_A           1
  97. #define PIXMAN_TYPE_ARGB        2
  98. #define PIXMAN_TYPE_ABGR        3
  99. #define PIXMAN_TYPE_COLOR       4
  100. #define PIXMAN_TYPE_GRAY        5
  101. #define PIXMAN_TYPE_YUY2        6
  102. #define PIXMAN_TYPE_YV12        7
  103. #define PIXMAN_TYPE_BGRA        8
  104. #define PIXMAN_TYPE_RGBA        9
  105. #define PIXMAN_TYPE_ARGB_SRGB   10
  106.  
  107. /* 32bpp formats */
  108. typedef enum {
  109.     PIXMAN_a8r8g8b8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,8,8,8,8),
  110.     PIXMAN_x8r8g8b8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,8,8,8),
  111.     PIXMAN_a8b8g8r8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,8,8,8,8),
  112.     PIXMAN_x8b8g8r8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,0,8,8,8),
  113.     PIXMAN_b8g8r8a8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_BGRA,8,8,8,8),
  114.     PIXMAN_b8g8r8x8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_BGRA,0,8,8,8),
  115.     PIXMAN_r8g8b8a8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_RGBA,8,8,8,8),
  116.     PIXMAN_r8g8b8x8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_RGBA,0,8,8,8),
  117.     PIXMAN_x14r6g6b6 =   PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,6,6,6),
  118.     PIXMAN_x2r10g10b10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,10,10,10),
  119.     PIXMAN_a2r10g10b10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,2,10,10,10),
  120.     PIXMAN_x2b10g10r10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,0,10,10,10),
  121.     PIXMAN_a2b10g10r10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,2,10,10,10)
  122.  
  123. } pixman_format_code_t;
  124.  
  125.  
  126. typedef unsigned long   Picture;
  127. typedef unsigned long   PictFormat;
  128.  
  129. typedef struct _Pixmap  *PixmapPtr;
  130. typedef struct _Picture *PicturePtr;
  131.  
  132. typedef struct _Drawable {
  133.     unsigned char type;         /* DRAWABLE_<type> */
  134.     unsigned char class;        /* specific to type */
  135.     unsigned char depth;
  136.     unsigned char bitsPerPixel;
  137.     unsigned int   id;           /* resource id */
  138.     short x;                    /* window: screen absolute, pixmap: 0 */
  139.     short y;                    /* window: screen absolute, pixmap: 0 */
  140.     unsigned short width;
  141.     unsigned short height;
  142. } DrawableRec;
  143.  
  144. /*
  145.  * PIXMAP -- device dependent
  146.  */
  147.  
  148. typedef struct _Pixmap {
  149.     DrawableRec drawable;
  150. //    PrivateRec *devPrivates;
  151.     int refcnt;
  152.     int devKind;                /* This is the pitch of the pixmap, typically width*bpp/8. */
  153. //    DevUnion devPrivate;        /* When !NULL, devPrivate.ptr points to the raw pixel data. */
  154. #ifdef COMPOSITE
  155.     short screen_x;
  156.     short screen_y;
  157. #endif
  158.     unsigned usage_hint;        /* see CREATE_PIXMAP_USAGE_* */
  159.  
  160.     PixmapPtr master_pixmap;    /* pointer to master copy of pixmap for pixmap sharing */
  161. } PixmapRec;
  162.  
  163.  
  164.  
  165. struct pixman_box16
  166. {
  167.     int16_t x1, y1, x2, y2;
  168. };
  169.  
  170. typedef struct pixman_box16 BoxRec;
  171. typedef unsigned int   CARD32;
  172. typedef unsigned short CARD16;
  173.  
  174. #include "sna_render.h"
  175. #include "kgem.h"
  176.  
  177. #define GXclear                 0x0
  178. #define GXcopy                  0x3
  179.  
  180. #define PictOpClear             0
  181. #define PictOpSrc               1
  182. #define PictOpDst               2
  183. #define PictOpOver              3
  184. #define PictOpOverReverse       4
  185. #define PictOpIn                5
  186. #define PictOpInReverse         6
  187. #define PictOpOut               7
  188. #define PictOpOutReverse        8
  189. #define PictOpAtop              9
  190. #define PictOpAtopReverse       10
  191. #define PictOpXor               11
  192. #define PictOpAdd               12
  193. #define PictOpSaturate          13
  194. #define PictOpMaximum           13
  195.  
  196.  
  197.  
  198. struct sna {
  199.     unsigned flags;
  200. #define SNA_NO_WAIT             0x1
  201. #define SNA_NO_FLIP             0x2
  202. #define SNA_TRIPLE_BUFFER       0x4
  203. #define SNA_TEAR_FREE           0x10
  204. #define SNA_FORCE_SHADOW        0x20
  205.  
  206.         struct list flush_pixmaps;
  207.         struct list active_pixmaps;
  208.  
  209.  
  210.  
  211. //    int vblank_interval;
  212.  
  213. //    struct list deferred_free;
  214. //    struct list dirty_pixmaps;
  215. //    struct list active_pixmaps;
  216. //    struct list inactive_clock[2];
  217.  
  218.     unsigned int tiling;
  219. #define SNA_TILING_DISABLE  0x0
  220. #define SNA_TILING_FB       0x1
  221. #define SNA_TILING_2D       0x2
  222. #define SNA_TILING_ALL     (~0)
  223.  
  224.         struct pci_device *PciInfo;
  225.         const struct intel_device_info *info;
  226.  
  227. //    PicturePtr clear;
  228.     struct {
  229.         uint32_t fill_bo;
  230.         uint32_t fill_pixel;
  231.         uint32_t fill_alu;
  232.     } blt_state;
  233.     union {
  234. //        struct gen2_render_state gen2;
  235. //        struct gen3_render_state gen3;
  236. //        struct gen4_render_state gen4;
  237. //        struct gen5_render_state gen5;
  238.         struct gen6_render_state gen6;
  239.                 struct gen7_render_state gen7;
  240.     } render_state;
  241.  
  242.  
  243.     /* Broken-out options. */
  244. //    OptionInfoPtr Options;
  245.  
  246.     /* Driver phase/state information */
  247. //    Bool suspended;
  248.  
  249.     struct kgem kgem;
  250.     struct sna_render render;
  251.  
  252. #if DEBUG_MEMORY
  253.         struct {
  254.                int shadow_pixels_allocs;
  255.                int cpu_bo_allocs;
  256.                size_t shadow_pixels_bytes;
  257.                size_t cpu_bo_bytes;
  258.         } debug_memory;
  259. #endif
  260. };
  261.  
  262. static inline int vertex_space(struct sna *sna)
  263. {
  264.     return sna->render.vertex_size - sna->render.vertex_used;
  265. }
  266.  
  267. static inline void vertex_emit(struct sna *sna, float v)
  268. {
  269.     assert(sna->render.vertex_used < sna->render.vertex_size);
  270.     sna->render.vertices[sna->render.vertex_used++] = v;
  271. }
  272.  
  273. static inline void vertex_emit_2s(struct sna *sna, int16_t x, int16_t y)
  274. {
  275.     int16_t *v = (int16_t *)&sna->render.vertices[sna->render.vertex_used++];
  276.     assert(sna->render.vertex_used <= sna->render.vertex_size);
  277.     v[0] = x;
  278.     v[1] = y;
  279. }
  280.  
  281. static inline void batch_emit(struct sna *sna, uint32_t dword)
  282. {
  283.     assert(sna->kgem.mode != KGEM_NONE);
  284.     assert(sna->kgem.nbatch + KGEM_BATCH_RESERVED < sna->kgem.surface);
  285.     sna->kgem.batch[sna->kgem.nbatch++] = dword;
  286. }
  287.  
  288. #ifndef ARRAY_SIZE
  289. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
  290. #endif
  291.  
  292. #ifndef ALIGN
  293. #define ALIGN(i,m)      (((i) + (m) - 1) & ~((m) - 1))
  294. #endif
  295.  
  296. #ifndef MIN
  297. #define MIN(a,b)        ((a) <= (b) ? (a) : (b))
  298. #endif
  299.  
  300. #ifndef MAX
  301. #define MAX(a,b)        ((a) >= (b) ? (a) : (b))
  302. #endif
  303. #endif /* _SNA_H */
  304.