Subversion Repositories Kolibri OS

Rev

Rev 4501 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | 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.  
  46. #include "compiler.h"
  47.  
  48.  
  49. //#include <memory.h>
  50. #include <malloc.h>
  51. #include <errno.h>
  52. #include <kos32sys.h>
  53.  
  54. #include "pciaccess.h"
  55. #include "intel_driver.h"
  56.  
  57. #include <drm.h>
  58. #include <i915_drm.h>
  59.  
  60. #ifdef HAVE_DRI2_H
  61. #include <dri2.h>
  62. #endif
  63.  
  64. #if HAVE_UDEV
  65. #include <libudev.h>
  66. #endif
  67.  
  68. #if 0
  69. #include <xorg-server.h>
  70.  
  71. #include <xf86Crtc.h>
  72. #if XF86_CRTC_VERSION >= 5
  73. #define HAS_PIXMAP_SHARING 1
  74. #endif
  75.  
  76. #include <xf86str.h>
  77. #include <windowstr.h>
  78. #include <glyphstr.h>
  79. #include <picturestr.h>
  80. #include <gcstruct.h>
  81. #include <xvdix.h>
  82.  
  83. #include <pciaccess.h>
  84.  
  85. #include <xf86drmMode.h>
  86.  
  87. #include "../compat-api.h"
  88.  
  89. #endif
  90.  
  91. #include <assert.h>
  92.  
  93. #define ErrorF printf
  94.  
  95. #if HAS_DEBUG_FULL
  96. #define DBG(x) ErrorF x
  97. #else
  98. #define DBG(x)
  99. #endif
  100.  
  101. # define ENTER() printf("ENTER %s\n", __FUNCTION__)
  102. # define LEAVE() printf("LEAVE %s\n", __FUNCTION__)
  103. # define FAIL() printf("FAIL %s\n", __FUNCTION__)
  104.  
  105. #define DEBUG_NO_BLT 0
  106.  
  107. #define DEBUG_FLUSH_BATCH 0
  108.  
  109. #define TEST_ALL 0
  110. #define TEST_ACCEL (TEST_ALL || 0)
  111. #define TEST_BATCH (TEST_ALL || 0)
  112. #define TEST_BLT (TEST_ALL || 0)
  113. #define TEST_COMPOSITE (TEST_ALL || 0)
  114. #define TEST_DAMAGE (TEST_ALL || 0)
  115. #define TEST_GRADIENT (TEST_ALL || 0)
  116. #define TEST_GLYPHS (TEST_ALL || 0)
  117. #define TEST_IO (TEST_ALL || 0)
  118. #define TEST_KGEM (TEST_ALL || 0)
  119. #define TEST_RENDER (TEST_ALL || 0)
  120.  
  121. int drmIoctl(int fd, unsigned long request, void *arg);
  122.  
  123.  
  124. #define PIXMAN_FORMAT(bpp,type,a,r,g,b) (((bpp) << 24) |    \
  125.                                         ((type) << 16) |    \
  126.                                         ((a) << 12)    |    \
  127.                                         ((r) << 8) |        \
  128.                                         ((g) << 4) |        \
  129.                                         ((b)))
  130. #define PIXMAN_TYPE_OTHER       0
  131. #define PIXMAN_TYPE_A           1
  132. #define PIXMAN_TYPE_ARGB        2
  133. #define PIXMAN_TYPE_ABGR        3
  134. #define PIXMAN_TYPE_COLOR       4
  135. #define PIXMAN_TYPE_GRAY        5
  136. #define PIXMAN_TYPE_YUY2        6
  137. #define PIXMAN_TYPE_YV12        7
  138. #define PIXMAN_TYPE_BGRA        8
  139. #define PIXMAN_TYPE_RGBA        9
  140. #define PIXMAN_TYPE_ARGB_SRGB   10
  141.  
  142. /* 32bpp formats */
  143. typedef enum {
  144.     PIXMAN_a8r8g8b8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,8,8,8,8),
  145.     PIXMAN_x8r8g8b8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,8,8,8),
  146.     PIXMAN_a8b8g8r8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,8,8,8,8),
  147.     PIXMAN_x8b8g8r8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,0,8,8,8),
  148.     PIXMAN_b8g8r8a8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_BGRA,8,8,8,8),
  149.     PIXMAN_b8g8r8x8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_BGRA,0,8,8,8),
  150.     PIXMAN_r8g8b8a8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_RGBA,8,8,8,8),
  151.     PIXMAN_r8g8b8x8 =    PIXMAN_FORMAT(32,PIXMAN_TYPE_RGBA,0,8,8,8),
  152.     PIXMAN_x14r6g6b6 =   PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,6,6,6),
  153.     PIXMAN_x2r10g10b10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,0,10,10,10),
  154.     PIXMAN_a2r10g10b10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB,2,10,10,10),
  155.     PIXMAN_x2b10g10r10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,0,10,10,10),
  156.     PIXMAN_a2b10g10r10 = PIXMAN_FORMAT(32,PIXMAN_TYPE_ABGR,2,10,10,10),
  157.  
  158. /* sRGB formats */
  159.     PIXMAN_a8r8g8b8_sRGB = PIXMAN_FORMAT(32,PIXMAN_TYPE_ARGB_SRGB,8,8,8,8),
  160.  
  161. /* 24bpp formats */
  162.     PIXMAN_r8g8b8 =      PIXMAN_FORMAT(24,PIXMAN_TYPE_ARGB,0,8,8,8),
  163.     PIXMAN_b8g8r8 =      PIXMAN_FORMAT(24,PIXMAN_TYPE_ABGR,0,8,8,8),
  164.  
  165. /* 16bpp formats */
  166.     PIXMAN_r5g6b5 =      PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,0,5,6,5),
  167.     PIXMAN_b5g6r5 =      PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,0,5,6,5),
  168.  
  169.     PIXMAN_a1r5g5b5 =    PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,1,5,5,5),
  170.     PIXMAN_x1r5g5b5 =    PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,0,5,5,5),
  171.     PIXMAN_a1b5g5r5 =    PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,1,5,5,5),
  172.     PIXMAN_x1b5g5r5 =    PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,0,5,5,5),
  173.     PIXMAN_a4r4g4b4 =    PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,4,4,4,4),
  174.     PIXMAN_x4r4g4b4 =    PIXMAN_FORMAT(16,PIXMAN_TYPE_ARGB,0,4,4,4),
  175.     PIXMAN_a4b4g4r4 =    PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,4,4,4,4),
  176.     PIXMAN_x4b4g4r4 =    PIXMAN_FORMAT(16,PIXMAN_TYPE_ABGR,0,4,4,4),
  177.  
  178. /* 8bpp formats */
  179.     PIXMAN_a8 =          PIXMAN_FORMAT(8,PIXMAN_TYPE_A,8,0,0,0),
  180.     PIXMAN_r3g3b2 =      PIXMAN_FORMAT(8,PIXMAN_TYPE_ARGB,0,3,3,2),
  181.     PIXMAN_b2g3r3 =      PIXMAN_FORMAT(8,PIXMAN_TYPE_ABGR,0,3,3,2),
  182.     PIXMAN_a2r2g2b2 =    PIXMAN_FORMAT(8,PIXMAN_TYPE_ARGB,2,2,2,2),
  183.     PIXMAN_a2b2g2r2 =    PIXMAN_FORMAT(8,PIXMAN_TYPE_ABGR,2,2,2,2),
  184.  
  185.     PIXMAN_c8 =          PIXMAN_FORMAT(8,PIXMAN_TYPE_COLOR,0,0,0,0),
  186.     PIXMAN_g8 =          PIXMAN_FORMAT(8,PIXMAN_TYPE_GRAY,0,0,0,0),
  187.  
  188.     PIXMAN_x4a4 =        PIXMAN_FORMAT(8,PIXMAN_TYPE_A,4,0,0,0),
  189.  
  190.     PIXMAN_x4c4 =        PIXMAN_FORMAT(8,PIXMAN_TYPE_COLOR,0,0,0,0),
  191.     PIXMAN_x4g4 =        PIXMAN_FORMAT(8,PIXMAN_TYPE_GRAY,0,0,0,0),
  192.  
  193. /* 4bpp formats */
  194.     PIXMAN_a4 =          PIXMAN_FORMAT(4,PIXMAN_TYPE_A,4,0,0,0),
  195.     PIXMAN_r1g2b1 =      PIXMAN_FORMAT(4,PIXMAN_TYPE_ARGB,0,1,2,1),
  196.     PIXMAN_b1g2r1 =      PIXMAN_FORMAT(4,PIXMAN_TYPE_ABGR,0,1,2,1),
  197.     PIXMAN_a1r1g1b1 =    PIXMAN_FORMAT(4,PIXMAN_TYPE_ARGB,1,1,1,1),
  198.     PIXMAN_a1b1g1r1 =    PIXMAN_FORMAT(4,PIXMAN_TYPE_ABGR,1,1,1,1),
  199.  
  200.     PIXMAN_c4 =          PIXMAN_FORMAT(4,PIXMAN_TYPE_COLOR,0,0,0,0),
  201.     PIXMAN_g4 =          PIXMAN_FORMAT(4,PIXMAN_TYPE_GRAY,0,0,0,0),
  202.  
  203. /* 1bpp formats */
  204.     PIXMAN_a1 =          PIXMAN_FORMAT(1,PIXMAN_TYPE_A,1,0,0,0),
  205.  
  206.     PIXMAN_g1 =          PIXMAN_FORMAT(1,PIXMAN_TYPE_GRAY,0,0,0,0),
  207.  
  208. /* YUV formats */
  209.     PIXMAN_yuy2 =        PIXMAN_FORMAT(16,PIXMAN_TYPE_YUY2,0,0,0,0),
  210.     PIXMAN_yv12 =        PIXMAN_FORMAT(12,PIXMAN_TYPE_YV12,0,0,0,0)
  211.  
  212. } pixman_format_code_t;
  213.  
  214. typedef enum _PictFormatShort {
  215.  
  216.     PICT_a2r10g10b10 = PIXMAN_a2r10g10b10,
  217.     PICT_x2r10g10b10 = PIXMAN_x2r10g10b10,
  218.     PICT_a2b10g10r10 = PIXMAN_a2b10g10r10,
  219.     PICT_x2b10g10r10 = PIXMAN_x2b10g10r10,
  220.  
  221.     PICT_a8r8g8b8 = PIXMAN_a8r8g8b8,
  222.     PICT_x8r8g8b8 = PIXMAN_x8r8g8b8,
  223.     PICT_a8b8g8r8 = PIXMAN_a8b8g8r8,
  224.     PICT_x8b8g8r8 = PIXMAN_x8b8g8r8,
  225.     PICT_b8g8r8a8 = PIXMAN_b8g8r8a8,
  226.     PICT_b8g8r8x8 = PIXMAN_b8g8r8x8,
  227.  
  228. /* 24bpp formats */
  229.     PICT_r8g8b8 = PIXMAN_r8g8b8,
  230.     PICT_b8g8r8 = PIXMAN_b8g8r8,
  231.  
  232. /* 16bpp formats */
  233.     PICT_r5g6b5 = PIXMAN_r5g6b5,
  234.     PICT_b5g6r5 = PIXMAN_b5g6r5,
  235.  
  236.     PICT_a1r5g5b5 = PIXMAN_a1r5g5b5,
  237.     PICT_x1r5g5b5 = PIXMAN_x1r5g5b5,
  238.     PICT_a1b5g5r5 = PIXMAN_a1b5g5r5,
  239.     PICT_x1b5g5r5 = PIXMAN_x1b5g5r5,
  240.     PICT_a4r4g4b4 = PIXMAN_a4r4g4b4,
  241.     PICT_x4r4g4b4 = PIXMAN_x4r4g4b4,
  242.     PICT_a4b4g4r4 = PIXMAN_a4b4g4r4,
  243.     PICT_x4b4g4r4 = PIXMAN_x4b4g4r4,
  244.  
  245. /* 8bpp formats */
  246.     PICT_a8 = PIXMAN_a8,
  247.     PICT_r3g3b2 = PIXMAN_r3g3b2,
  248.     PICT_b2g3r3 = PIXMAN_b2g3r3,
  249.     PICT_a2r2g2b2 = PIXMAN_a2r2g2b2,
  250.     PICT_a2b2g2r2 = PIXMAN_a2b2g2r2,
  251.  
  252.     PICT_c8 = PIXMAN_c8,
  253.     PICT_g8 = PIXMAN_g8,
  254.  
  255.     PICT_x4a4 = PIXMAN_x4a4,
  256.  
  257.     PICT_x4c4 = PIXMAN_x4c4,
  258.     PICT_x4g4 = PIXMAN_x4g4,
  259.  
  260. /* 4bpp formats */
  261.     PICT_a4 = PIXMAN_a4,
  262.     PICT_r1g2b1 = PIXMAN_r1g2b1,
  263.     PICT_b1g2r1 = PIXMAN_b1g2r1,
  264.     PICT_a1r1g1b1 = PIXMAN_a1r1g1b1,
  265.     PICT_a1b1g1r1 = PIXMAN_a1b1g1r1,
  266.  
  267.     PICT_c4 = PIXMAN_c4,
  268.     PICT_g4 = PIXMAN_g4,
  269.  
  270. /* 1bpp formats */
  271.     PICT_a1 = PIXMAN_a1,
  272.  
  273.     PICT_g1 = PIXMAN_g1
  274. } PictFormatShort;
  275.  
  276. #define PIXMAN_FORMAT_A(f)      (((f) >> 12) & 0x0f)
  277. #define PIXMAN_FORMAT_RGB(f)    (((f)      ) & 0xfff)
  278.  
  279. #define PICT_FORMAT_A(f)        PIXMAN_FORMAT_A(f)
  280.  
  281. #define RepeatNone                          0
  282. #define RepeatNormal                        1
  283. #define RepeatPad                           2
  284. #define RepeatReflect                       3
  285.  
  286. #define PictFilterNearest       0
  287. #define PictFilterBilinear      1
  288.  
  289. #define PictFilterFast          2
  290. #define PictFilterGood          3
  291. #define PictFilterBest          4
  292.  
  293. #define PictFilterConvolution   5
  294.  
  295. typedef int32_t                 pixman_fixed_16_16_t;
  296. typedef pixman_fixed_16_16_t    pixman_fixed_t;
  297.  
  298. struct pixman_transform
  299. {
  300.     pixman_fixed_t      matrix[3][3];
  301. };
  302.  
  303. typedef unsigned long   Picture;
  304. typedef unsigned long   PictFormat;
  305.  
  306. typedef struct _Pixmap  *PixmapPtr;
  307. typedef struct _Picture *PicturePtr;
  308. typedef struct _Drawable *DrawablePtr;
  309. typedef struct _PictFormat *PictFormatPtr;
  310.  
  311. typedef struct pixman_transform PictTransform, *PictTransformPtr;
  312.  
  313.  
  314.  
  315. typedef struct _Drawable {
  316.     unsigned char type;         /* DRAWABLE_<type> */
  317.     unsigned char class;        /* specific to type */
  318.     unsigned char depth;
  319.     unsigned char bitsPerPixel;
  320.     unsigned int   id;           /* resource id */
  321.     short x;                    /* window: screen absolute, pixmap: 0 */
  322.     short y;                    /* window: screen absolute, pixmap: 0 */
  323.     unsigned short width;
  324.     unsigned short height;
  325. } DrawableRec;
  326.  
  327. /*
  328.  * PIXMAP -- device dependent
  329.  */
  330.  
  331. typedef struct _Pixmap {
  332.     DrawableRec drawable;
  333. //    PrivateRec *devPrivates;
  334.     int refcnt;
  335.     int devKind;                /* This is the pitch of the pixmap, typically width*bpp/8. */
  336. //    DevUnion devPrivate;        /* When !NULL, devPrivate.ptr points to the raw pixel data. */
  337. #ifdef COMPOSITE
  338.     short screen_x;
  339.     short screen_y;
  340. #endif
  341.     unsigned usage_hint;        /* see CREATE_PIXMAP_USAGE_* */
  342.  
  343.     PixmapPtr master_pixmap;    /* pointer to master copy of pixmap for pixmap sharing */
  344. } PixmapRec;
  345.  
  346. typedef struct _PictFormat {
  347.     uint32_t id;
  348.     uint32_t format;              /* except bpp */
  349.     unsigned char type;
  350.     unsigned char depth;
  351. //    DirectFormatRec direct;
  352. //   IndexFormatRec index;
  353. } PictFormatRec;
  354.  
  355. typedef struct _Picture {
  356.     DrawablePtr pDrawable;
  357. //    PictFormatPtr pFormat;
  358.     PictFormatShort format;     /* PICT_FORMAT */
  359.     int refcnt;
  360.     uint32_t id;
  361.     unsigned int repeat:1;
  362.     unsigned int graphicsExposures:1;
  363.     unsigned int subWindowMode:1;
  364.     unsigned int polyEdge:1;
  365.     unsigned int polyMode:1;
  366.     unsigned int freeCompClip:1;
  367.     unsigned int clientClipType:2;
  368.     unsigned int componentAlpha:1;
  369.     unsigned int repeatType:2;
  370.     unsigned int filter:3;
  371. //    unsigned int stateChanges:CPLastBit;
  372. //    unsigned int unused:18 - CPLastBit;
  373.  
  374. //    PicturePtr alphaMap;
  375.  
  376. //    PictTransform *transform;
  377.  
  378. //    SourcePictPtr pSourcePict;
  379. //    xFixed *filter_params;
  380. //    int filter_nparams;
  381. } PictureRec;
  382.  
  383. #define PolyModePrecise                     0
  384. #define PolyModeImprecise                   1
  385.  
  386.  
  387. struct sna_fb
  388. {
  389.     uint32_t  name;
  390.     uint32_t  width;
  391.     uint32_t  height;
  392.     uint32_t  pitch;
  393.     uint32_t  tiling;
  394.     uint32_t  crtc;
  395.     uint32_t  pipe;
  396.  
  397.     struct kgem_bo *fb_bo;
  398. };
  399.  
  400. struct pixman_box16
  401. {
  402.     int16_t x1, y1, x2, y2;
  403. };
  404.  
  405. typedef struct pixman_box16 BoxRec;
  406. typedef unsigned int   CARD32;
  407. typedef unsigned short CARD16;
  408.  
  409. #include "sna_render.h"
  410. #include "kgem.h"
  411.  
  412. #define GXclear                 0x0
  413. #define GXcopy                  0x3
  414.  
  415. #define PictOpClear             0
  416. #define PictOpSrc               1
  417. #define PictOpDst               2
  418. #define PictOpOver              3
  419. #define PictOpOverReverse       4
  420. #define PictOpIn                5
  421. #define PictOpInReverse         6
  422. #define PictOpOut               7
  423. #define PictOpOutReverse        8
  424. #define PictOpAtop              9
  425. #define PictOpAtopReverse       10
  426. #define PictOpXor               11
  427. #define PictOpAdd               12
  428. #define PictOpSaturate          13
  429. #define PictOpMaximum           13
  430.  
  431.  
  432. #define SNA_CURSOR_X                    64
  433. #define SNA_CURSOR_Y                    SNA_CURSOR_X
  434.  
  435. struct sna_client {
  436.         int is_compositor; /* only 4 bits used */
  437. };
  438.  
  439.  
  440. //#define assert(x)
  441.  
  442.  
  443. struct sna {
  444.         struct kgem kgem;
  445.  
  446.         unsigned scrn;
  447.  
  448.     unsigned flags;
  449. #define SNA_NO_WAIT             0x1
  450. #define SNA_NO_FLIP             0x2
  451. #define SNA_NO_VSYNC            0x4
  452. #define SNA_TRIPLE_BUFFER       0x8
  453. #define SNA_TEAR_FREE           0x10
  454. #define SNA_FORCE_SHADOW        0x20
  455. #define SNA_FLUSH_GTT           0x40
  456. #define SNA_IS_HOSTED           0x80
  457. #define SNA_PERFORMANCE         0x100
  458. #define SNA_POWERSAVE           0x200
  459. #define SNA_REPROBE             0x80000000
  460.  
  461.         unsigned cpu_features;
  462. #define MMX 0x1
  463. #define SSE 0x2
  464. #define SSE2 0x4
  465. #define SSE3 0x8
  466. #define SSSE3 0x10
  467. #define SSE4_1 0x20
  468. #define SSE4_2 0x40
  469. #define AVX 0x80
  470. #define AVX2 0x100
  471.  
  472.         struct list flush_pixmaps;
  473.         struct list active_pixmaps;
  474.  
  475.  
  476.  
  477.  
  478.  
  479.     unsigned int tiling;
  480. #define SNA_TILING_FB       0x1
  481. #define SNA_TILING_2D       0x2
  482. #define SNA_TILING_ALL     (~0)
  483.  
  484.         struct pci_device *PciInfo;
  485.         const struct intel_device_info *info;
  486.  
  487. //    PicturePtr clear;
  488.     struct {
  489.         uint32_t fill_bo;
  490.         uint32_t fill_pixel;
  491.         uint32_t fill_alu;
  492.     } blt_state;
  493.     union {
  494.                 unsigned gt;
  495.         struct gen3_render_state gen3;
  496.         struct gen4_render_state gen4;
  497.         struct gen5_render_state gen5;
  498.         struct gen6_render_state gen6;
  499.                 struct gen7_render_state gen7;
  500.     } render_state;
  501.  
  502.         bool dri_available;
  503.         bool dri_open;
  504.  
  505.     /* Broken-out options. */
  506. //    OptionInfoPtr Options;
  507.  
  508.     /* Driver phase/state information */
  509. //    Bool suspended;
  510.  
  511.     struct sna_render render;
  512.  
  513. #if DEBUG_MEMORY
  514.         struct {
  515.                 int pixmap_allocs;
  516.                int cpu_bo_allocs;
  517.                size_t shadow_pixels_bytes;
  518.                size_t cpu_bo_bytes;
  519.         } debug_memory;
  520. #endif
  521. };
  522.  
  523. static inline struct sna *
  524. to_sna_from_kgem(struct kgem *kgem)
  525. {
  526.         return container_of(kgem, struct sna, kgem);
  527. }
  528.  
  529. #ifndef ARRAY_SIZE
  530. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
  531. #endif
  532.  
  533. #ifndef ALIGN
  534. #define ALIGN(i,m)      (((i) + (m) - 1) & ~((m) - 1))
  535. #endif
  536.  
  537. #ifndef MIN
  538. #define MIN(a,b)        ((a) <= (b) ? (a) : (b))
  539. #endif
  540.  
  541. #ifndef MAX
  542. #define MAX(a,b)        ((a) >= (b) ? (a) : (b))
  543. #endif
  544. static inline bool
  545. _sna_transform_point(const PictTransform *transform,
  546.                      int64_t x, int64_t y, int64_t result[3])
  547. {
  548.         int j;
  549.  
  550.         for (j = 0; j < 3; j++)
  551.                 result[j] = (transform->matrix[j][0] * x +
  552.                              transform->matrix[j][1] * y +
  553.                              transform->matrix[j][2]);
  554.  
  555.         return result[2] != 0;
  556. }
  557.  
  558. static inline void
  559. _sna_get_transformed_coordinates(int x, int y,
  560.                                  const PictTransform *transform,
  561.                                  float *x_out, float *y_out)
  562. {
  563.  
  564.         int64_t result[3];
  565.  
  566.         _sna_transform_point(transform, x, y, result);
  567.         *x_out = result[0] / (double)result[2];
  568.         *y_out = result[1] / (double)result[2];
  569. }
  570.  
  571. static inline void
  572. _sna_get_transformed_scaled(int x, int y,
  573.                             const PictTransform *transform, const float *sf,
  574.                             float *x_out, float *y_out)
  575. {
  576.         *x_out = sf[0] * (transform->matrix[0][0] * x +
  577.                           transform->matrix[0][1] * y +
  578.                           transform->matrix[0][2]);
  579.  
  580.         *y_out = sf[1] * (transform->matrix[1][0] * x +
  581.                           transform->matrix[1][1] * y +
  582.                           transform->matrix[1][2]);
  583. }
  584.  
  585. void
  586. sna_get_transformed_coordinates(int x, int y,
  587.                                 const PictTransform *transform,
  588.                                 float *x_out, float *y_out);
  589.  
  590. void
  591. sna_get_transformed_coordinates_3d(int x, int y,
  592.                                    const PictTransform *transform,
  593.                                    float *x_out, float *y_out, float *z_out);
  594.  
  595. bool sna_transform_is_affine(const PictTransform *t);
  596. bool sna_transform_is_integer_translation(const PictTransform *t,
  597.                                           int16_t *tx, int16_t *ty);
  598. bool sna_transform_is_translation(const PictTransform *t,
  599.                                   pixman_fixed_t *tx, pixman_fixed_t *ty);
  600. static inline bool
  601. sna_affine_transform_is_rotation(const PictTransform *t)
  602. {
  603.         assert(sna_transform_is_affine(t));
  604.         return t->matrix[0][1] | t->matrix[1][0];
  605. }
  606.  
  607. static inline bool
  608. sna_transform_equal(const PictTransform *a, const PictTransform *b)
  609. {
  610.         if (a == b)
  611.                 return true;
  612.  
  613.         if (a == NULL || b == NULL)
  614.                 return false;
  615.  
  616.         return memcmp(a, b, sizeof(*a)) == 0;
  617. }
  618.  
  619. int intel_get_device_id(struct sna *sna);
  620.  
  621. #endif /* _SNA_H */
  622.