Subversion Repositories Kolibri OS

Rev

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

  1.  
  2.  
  3. int ClearPixmap(io_clear_t *io)
  4. {
  5.      u32_t ifl;
  6.      u32_t *ring;
  7.  
  8.      local_pixmap_t *dstpixmap;
  9.  
  10.      dstpixmap = (io->dstpix == (void*)-1) ? &scr_pixmap : io->dstpix ;
  11.  
  12.      ifl = safe_cli();
  13.  
  14. #if R300_PIO
  15.  
  16.      R5xxFIFOWait(6);
  17.  
  18.      OUTREG(R5XX_DP_GUI_MASTER_CNTL,
  19.             RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  20.             RADEON_GMC_BRUSH_SOLID_COLOR      |
  21.             RADEON_GMC_DST_32BPP              |
  22.             RADEON_GMC_SRC_DATATYPE_COLOR     |
  23.             R5XX_GMC_CLR_CMP_CNTL_DIS         |
  24.             R5XX_GMC_WR_MSK_DIS               |
  25.             R5XX_ROP3_P
  26.            );
  27.  
  28.      OUTREG(R5XX_DP_BRUSH_FRGD_CLR, io->color);
  29.      OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
  30.      OUTREG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  31.      OUTREG(R5XX_DST_Y_X, 0);
  32.      OUTREG(R5XX_DST_WIDTH_HEIGHT,(dstpixmap->width<<16)|dstpixmap->height);
  33.  
  34. #else
  35.       BEGIN_RING(6);
  36.  
  37.         OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
  38.  
  39.         OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  40.                  RADEON_GMC_BRUSH_SOLID_COLOR      |
  41.                  RADEON_GMC_DST_32BPP              |
  42.                  RADEON_GMC_SRC_DATATYPE_COLOR     |
  43.                  R5XX_GMC_CLR_CMP_CNTL_DIS         |
  44.                  R5XX_GMC_WR_MSK_DIS               |
  45.                  R5XX_ROP3_P
  46.                 );
  47.  
  48.         OUT_RING(dstpixmap->pitch_offset);
  49.         OUT_RING(io->color);
  50.         OUT_RING( 0 );
  51.         OUT_RING((dstpixmap->width<<16)|dstpixmap->height);
  52.       COMMIT_RING();
  53.  
  54. #endif
  55.  
  56.      safe_sti(ifl);
  57.  
  58.      return ERR_OK;
  59. }
  60.  
  61.  
  62. int Line(io_draw_t *draw)
  63. {
  64.      local_pixmap_t *dstpixmap;
  65.      clip_t clip;
  66.      int x0, y0, x1, y1;
  67.  
  68.      dstpixmap = (draw->dstpix == (void*)-1) ? &scr_pixmap : draw->dstpix ;
  69.  
  70.      x0 = draw->x0;
  71.      y0 = draw->y0;
  72.  
  73.      x1 = draw->x1;
  74.      y1 = draw->y1;
  75.  
  76.      clip.xmin = 0;
  77.      clip.ymin = 0;
  78.      clip.xmax = dstpixmap->width-1;
  79.      clip.ymax = dstpixmap->height-1;
  80.  
  81.      if ( !LineClip(&clip, &x0, &y0, &x1, &y1 ))
  82.      {
  83.         u32_t ifl;
  84.         u32_t *ring, write;
  85.  
  86.         ifl = safe_cli();
  87.  
  88. #if R300_PIO
  89.  
  90.         R5xxFIFOWait(6);
  91.  
  92.         OUTREG(R5XX_DP_GUI_MASTER_CNTL,
  93.                RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  94.                RADEON_GMC_BRUSH_SOLID_COLOR      |
  95.                RADEON_GMC_DST_32BPP              |
  96.                RADEON_GMC_SRC_DATATYPE_COLOR     |
  97.                R5XX_GMC_CLR_CMP_CNTL_DIS         |
  98.                R5XX_GMC_WR_MSK_DIS               |
  99.                R5XX_ROP3_P
  100.               );
  101.  
  102.         OUTREG(R5XX_DST_LINE_PATCOUNT, 0x55 << R5XX_BRES_CNTL_SHIFT);
  103.  
  104.         OUTREG(R5XX_DP_BRUSH_FRGD_CLR, draw->color);
  105.         OUTREG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  106.  
  107.         OUTREG(R5XX_DST_LINE_START,(y0<<16)|x0);
  108.         OUTREG(R5XX_DST_LINE_END,(y1<<16)|x1);
  109. #else
  110.        BEGIN_RING(6);
  111.  
  112.          OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_POLYLINE, 4));
  113.          OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  114.                   RADEON_GMC_BRUSH_SOLID_COLOR      |
  115.                   RADEON_GMC_DST_32BPP              |
  116.                   RADEON_GMC_SRC_DATATYPE_COLOR     |
  117.                   R5XX_GMC_CLR_CMP_CNTL_DIS         |
  118.                   R5XX_GMC_WR_MSK_DIS               |
  119.                   R5XX_ROP3_P);
  120.  
  121.          OUT_RING(dstpixmap->pitch_offset);
  122.          OUT_RING(draw->color);
  123.          OUT_RING((y0<<16)|x0);
  124.          OUT_RING((y1<<16)|x1);
  125.        COMMIT_RING();
  126. #endif
  127.         safe_sti(ifl);
  128.      };
  129.      return ERR_OK;
  130. }
  131.  
  132. int DrawRect(io_draw_t* draw)
  133. {
  134.      int x0, y0, x1, y1, xend, yend;
  135.  
  136.      local_pixmap_t *dstpixmap;
  137.      clip_t dst_clip;
  138.  
  139.      dstpixmap = (draw->dstpix == (void*)-1) ? &scr_pixmap : draw->dstpix ;
  140.  
  141.      x0 = draw->x0;
  142.      y0 = draw->y0;
  143.  
  144.      x1 = xend = x0 + draw->w - 1;
  145.      y1 = yend = y0 + draw->h - 1;
  146.  
  147.      dst_clip.xmin = 0;
  148.      dst_clip.ymin = 0;
  149.      dst_clip.xmax = dstpixmap->width-1;
  150.      dst_clip.ymax = dstpixmap->height-1;
  151.  
  152.  
  153. //  dbgprintf("draw rect x0:%d, y0:%d, x1:%d, y1:%d, color: %x\n",
  154. //             x0, y0, x1, y1, draw->color);
  155.  
  156.      if( ! BlockClip( &dst_clip, &x0, &y0, &x1, &y1))
  157.      {
  158.         u32_t *ring;
  159.         u32_t ifl;
  160.         int w, h;
  161.  
  162.         w = x1 - x0 + 1;
  163.         h = y1 - y0 + 1;
  164.  
  165.         ifl = safe_cli();
  166.  
  167. #if R300_PIO
  168.  
  169.         R5xxFIFOWait(6);
  170.  
  171.         OUTREG(R5XX_DP_GUI_MASTER_CNTL,
  172.                RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  173.                RADEON_GMC_BRUSH_SOLID_COLOR      |
  174.                RADEON_GMC_DST_32BPP              |
  175.                RADEON_GMC_SRC_DATATYPE_COLOR     |
  176.                R5XX_GMC_CLR_CMP_CNTL_DIS         |
  177.                R5XX_GMC_WR_MSK_DIS               |
  178.                R5XX_ROP3_P
  179.               );
  180.  
  181.         OUTREG(R5XX_DP_BRUSH_FRGD_CLR, draw->color);
  182.         OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
  183.         OUTREG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  184.         OUTREG(R5XX_DST_Y_X,(y0<<16)|x0);
  185.         OUTREG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|h);
  186.  
  187.         if( draw->color != draw->border)
  188.         {
  189.            OUTREG(R5XX_DP_BRUSH_FRGD_CLR, draw->border);
  190.  
  191.            if( y0 == draw->y0)
  192.            {
  193.               R5xxFIFOWait(2);
  194.  
  195.               OUTREG(R5XX_DST_Y_X,(y0<<16)|x0);
  196.               OUTREG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|1);
  197.               y0++;
  198.               h--;
  199.            }
  200.            if( y1 == yend )
  201.            {
  202.               R5xxFIFOWait(2);
  203.  
  204.               OUTREG(R5XX_DST_Y_X,(y1<<16)|x0);
  205.               OUTREG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|1);
  206.               h--;
  207.            }
  208.            if( (h > 0) && (x0 == draw->x0))
  209.            {
  210.               R5xxFIFOWait(2);
  211.  
  212.               OUTREG(R5XX_DST_Y_X,(y0<<16)|x0);
  213.               OUTREG(R5XX_DST_WIDTH_HEIGHT,(1<<16)|h);
  214.            }
  215.            if( (h > 0) && (x1 == xend))
  216.            {
  217.               R5xxFIFOWait(2);
  218.  
  219.               OUTREG(R5XX_DST_Y_X,(y0<<16)|x1);
  220.               OUTREG(R5XX_DST_WIDTH_HEIGHT,(1<<16)|h);
  221.            }
  222.         };
  223. #else
  224.  
  225.       BEGIN_RING(64);
  226.  
  227.         OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
  228.  
  229.         OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  230.                  RADEON_GMC_BRUSH_SOLID_COLOR      |
  231.                  RADEON_GMC_DST_32BPP              |
  232.                  RADEON_GMC_SRC_DATATYPE_COLOR     |
  233.                  R5XX_GMC_CLR_CMP_CNTL_DIS         |
  234.                  R5XX_GMC_WR_MSK_DIS               |
  235.                  R5XX_ROP3_P
  236.                 );
  237.  
  238.         OUT_RING(dstpixmap->pitch_offset);
  239.         OUT_RING(draw->color);
  240.         OUT_RING((x0<<16)|y0);
  241.         OUT_RING((w<<16)|h);
  242.         OUT_RING(CP_PACKET2());
  243.         OUT_RING(CP_PACKET2());
  244.  
  245.         if( draw->color != draw->border)
  246.         {
  247.            if( y0 == draw->y0) {
  248.               OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
  249.               OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  250.                        RADEON_GMC_BRUSH_SOLID_COLOR      |
  251.                        RADEON_GMC_DST_32BPP              |
  252.                        RADEON_GMC_SRC_DATATYPE_COLOR     |
  253.                        R5XX_GMC_CLR_CMP_CNTL_DIS         |
  254.                        R5XX_GMC_WR_MSK_DIS               |
  255.                        R5XX_ROP3_P
  256.                       );
  257.  
  258.               OUT_RING(dstpixmap->pitch_offset);
  259.               OUT_RING(draw->border);
  260.               OUT_RING((x0<<16)|y0);
  261.               OUT_RING((w<<16)|1);
  262.         OUT_RING(CP_PACKET2());
  263.         OUT_RING(CP_PACKET2());
  264.  
  265.            //   y0++;
  266.            //   h--;
  267.            }
  268.            if( y1 == yend ) {
  269.               OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
  270.               OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  271.                        RADEON_GMC_BRUSH_SOLID_COLOR      |
  272.                        RADEON_GMC_DST_32BPP              |
  273.                        RADEON_GMC_SRC_DATATYPE_COLOR     |
  274.                        R5XX_GMC_CLR_CMP_CNTL_DIS         |
  275.                        R5XX_GMC_WR_MSK_DIS               |
  276.                        R5XX_ROP3_P
  277.                       );
  278.  
  279.               OUT_RING(dstpixmap->pitch_offset);
  280.               OUT_RING(draw->border);
  281.               OUT_RING((x0<<16)|y1);
  282.               OUT_RING((w<<16)|1);
  283.         OUT_RING(CP_PACKET2());
  284.         OUT_RING(CP_PACKET2());
  285.  
  286.             //  h--;
  287.            }
  288.            if( (h > 0) && (x0 == draw->x0)) {
  289.               OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
  290.               OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  291.                        RADEON_GMC_BRUSH_SOLID_COLOR      |
  292.                        RADEON_GMC_DST_32BPP              |
  293.                        RADEON_GMC_SRC_DATATYPE_COLOR     |
  294.                        R5XX_GMC_CLR_CMP_CNTL_DIS         |
  295.                        R5XX_GMC_WR_MSK_DIS               |
  296.                        R5XX_ROP3_P
  297.                       );
  298.  
  299.               OUT_RING(dstpixmap->pitch_offset);
  300.               OUT_RING(draw->border);
  301.               OUT_RING((x0<<16)|y0);
  302.               OUT_RING((1<<16)|h);
  303.         OUT_RING(CP_PACKET2());
  304.         OUT_RING(CP_PACKET2());
  305.  
  306.            }
  307.            if( (h > 0) && (x1 == xend)) {
  308.               OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
  309.               OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  310.                        RADEON_GMC_BRUSH_SOLID_COLOR      |
  311.                        RADEON_GMC_DST_32BPP              |
  312.                        RADEON_GMC_SRC_DATATYPE_COLOR     |
  313.                        R5XX_GMC_CLR_CMP_CNTL_DIS         |
  314.                        R5XX_GMC_WR_MSK_DIS               |
  315.                        R5XX_ROP3_P
  316.                       );
  317.  
  318.               OUT_RING(dstpixmap->pitch_offset);
  319.               OUT_RING(draw->border);
  320.               OUT_RING((x1<<16)|y0);
  321.               OUT_RING((1<<16)|h);
  322.         OUT_RING(CP_PACKET2());
  323.         OUT_RING(CP_PACKET2());
  324.  
  325.            }
  326.         };
  327.  
  328. /*
  329.  
  330.         CP_REG(R5XX_DP_GUI_MASTER_CNTL,
  331.                  RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  332.                  RADEON_GMC_BRUSH_SOLID_COLOR      |
  333.                  RADEON_GMC_DST_32BPP              |
  334.                  RADEON_GMC_SRC_DATATYPE_COLOR     |
  335.                  R5XX_GMC_CLR_CMP_CNTL_DIS         |
  336.                  R5XX_GMC_WR_MSK_DIS               |
  337.                  R5XX_ROP3_P
  338.                 );
  339.         CP_REG(R5XX_DP_BRUSH_FRGD_CLR, draw->color);
  340.         CP_REG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
  341.  
  342.         CP_REG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  343.         CP_REG(R5XX_DST_Y_X,(y0<<16)|x0);
  344.         CP_REG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|h);
  345.         if( draw->color != draw->border)
  346.         {
  347.         CP_REG(R5XX_DP_GUI_MASTER_CNTL,
  348.                  RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  349.                  RADEON_GMC_BRUSH_SOLID_COLOR      |
  350.                  RADEON_GMC_DST_32BPP              |
  351.                  RADEON_GMC_SRC_DATATYPE_COLOR     |
  352.                  R5XX_GMC_CLR_CMP_CNTL_DIS         |
  353.                  R5XX_GMC_WR_MSK_DIS               |
  354.                  R5XX_ROP3_P
  355.                 );
  356.            CP_REG(R5XX_DP_BRUSH_FRGD_CLR, draw->border);
  357.         CP_REG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
  358.  
  359.         CP_REG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  360.  
  361.  
  362.            if( y0 == draw->y0) {
  363.               CP_REG(R5XX_DST_Y_X,(y0<<16)|x0);
  364.               CP_REG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|1);
  365.               y0++;
  366.               h--;
  367.            }
  368.            if( y1 == yend ) {
  369.               CP_REG(R5XX_DST_Y_X,(y1<<16)|x0);
  370.               CP_REG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|1);
  371.               h--;
  372.            }
  373.            if( (h > 0) && (x0 == draw->x0)) {
  374.               CP_REG(R5XX_DST_Y_X,(y0<<16)|x0);
  375.               CP_REG(R5XX_DST_WIDTH_HEIGHT,(1<<16)|h);
  376.            }
  377.            if( (h > 0) && (x1 == xend)) {
  378.               CP_REG(R5XX_DST_Y_X,(y0<<16)|x1);
  379.               CP_REG(R5XX_DST_WIDTH_HEIGHT,(1<<16)|h);
  380.            }
  381.         };
  382. */
  383.  
  384.       COMMIT_RING();
  385. #endif
  386.         safe_sti(ifl);
  387.      };
  388.      return ERR_OK;
  389. }
  390.  
  391. int FillRect(io_fill_t *fill)
  392. {
  393.      local_pixmap_t *dstpixmap;
  394.      clip_t dst_clip;
  395.      int x0, y0, x1, y1, xend, yend;
  396.  
  397.      dstpixmap = (fill->dstpix == (void*)-1) ? &scr_pixmap : fill->dstpix ;
  398.  
  399.      x0 = fill->x;
  400.      y0 = fill->y;
  401.  
  402.      xend = x1 = x0 + fill->w - 1;
  403.      yend = y1 = y0 + fill->h - 1;
  404.  
  405.      dst_clip.xmin = 0;
  406.      dst_clip.ymin = 0;
  407.      dst_clip.xmax = dstpixmap->width-1;
  408.      dst_clip.ymax = dstpixmap->height-1;
  409.  
  410. //  dbgprintf("fill rect x0:%d, y0:%d, x1:%d, y1:%d\n",
  411. //             x0, y0, x1, y1);
  412.  
  413.      if( ! BlockClip(&dst_clip, &x0, &y0, &x1, &y1))
  414.      {
  415.         u32_t *ring, write;
  416.         u32_t ifl;
  417.  
  418.         int w = x1 - x0 + 1;
  419.         int h = y1 - y0 + 1;
  420.  
  421.         ifl = safe_cli();
  422.  
  423. #if R300_PIO
  424.  
  425.         R5xxFIFOWait(9);
  426.  
  427.         OUTREG(R5XX_DP_GUI_MASTER_CNTL,
  428.                RADEON_GMC_DST_PITCH_OFFSET_CNTL |
  429.                R5XX_GMC_BRUSH_8X8_MONO_FG_BG    |
  430.                RADEON_GMC_DST_32BPP             |
  431.                R5XX_GMC_SRC_DATATYPE_COLOR      |
  432.                R5XX_GMC_CLR_CMP_CNTL_DIS        |
  433.                R5XX_GMC_WR_MSK_DIS              |
  434.                R5XX_ROP3_P
  435.                );
  436.  
  437.         OUTREG(R5XX_DP_BRUSH_BKGD_CLR, fill->bkcolor);
  438.         OUTREG(R5XX_DP_BRUSH_FRGD_CLR, fill->fcolor);
  439.  
  440.         OUTREG(R5XX_BRUSH_DATA0, fill->bmp0);
  441.         OUTREG(R5XX_BRUSH_DATA1, fill->bmp1);
  442.  
  443.         OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
  444.         OUTREG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  445.  
  446.         OUTREG(R5XX_DST_Y_X,(y0<<16)|x0);
  447.         OUTREG(R5XX_DST_HEIGHT_WIDTH,(h<<16)|w);
  448.  
  449.         if( (fill->border & 0xFF000000) != 0)
  450.         {
  451.            R5xxFIFOWait(2);
  452.  
  453.            OUTREG(R5XX_DP_GUI_MASTER_CNTL,
  454.                   RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  455.                   RADEON_GMC_BRUSH_SOLID_COLOR      |
  456.                   RADEON_GMC_DST_32BPP              |
  457.                   RADEON_GMC_SRC_DATATYPE_COLOR     |
  458.                   R5XX_GMC_CLR_CMP_CNTL_DIS         |
  459.                   R5XX_GMC_WR_MSK_DIS               |
  460.                   R5XX_ROP3_P
  461.                  );
  462.  
  463.            OUTREG(R5XX_DP_BRUSH_FRGD_CLR, fill->border);
  464.  
  465.            if( y0 == fill->y)
  466.            {
  467.               R5xxFIFOWait(2);
  468.  
  469.               OUTREG(R5XX_DST_Y_X,(y0<<16)|x0);
  470.               OUTREG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|1);
  471.               y0++;
  472.               h--;
  473.            }
  474.            if( y1 == yend )
  475.            {
  476.               R5xxFIFOWait(2);
  477.  
  478.               OUTREG(R5XX_DST_Y_X,(y1<<16)|x0);
  479.               OUTREG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|1);
  480.               h--;
  481.            }
  482.            if( (h > 0) && (x0 == fill->x))
  483.            {
  484.               R5xxFIFOWait(2);
  485.  
  486.               OUTREG(R5XX_DST_Y_X,(y0<<16)|x0);
  487.               OUTREG(R5XX_DST_WIDTH_HEIGHT,(1<<16)|h);
  488.            }
  489.            if( (h > 0) && (x1 == xend))
  490.            {
  491.               R5xxFIFOWait(2);
  492.  
  493.               OUTREG(R5XX_DST_Y_X,(y0<<16)|x1);
  494.               OUTREG(R5XX_DST_WIDTH_HEIGHT,(1<<16)|h);
  495.            }
  496.         };
  497.  
  498.  
  499. #else
  500.       BEGIN_RING(9+10*2);
  501.  
  502.         OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT, 7));
  503.         OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL    |
  504.                  R5XX_GMC_BRUSH_8X8_MONO_FG_BG       |
  505.                  RADEON_GMC_DST_32BPP                |
  506.                  RADEON_GMC_SRC_DATATYPE_COLOR       |
  507.                  R5XX_GMC_CLR_CMP_CNTL_DIS           |
  508.                  R5XX_GMC_WR_MSK_DIS                 |
  509.                  R5XX_ROP3_P
  510.                 );
  511.  
  512.         OUT_RING(dstpixmap->pitch_offset);
  513.         OUT_RING(fill->bkcolor);
  514.         OUT_RING(fill->fcolor);
  515.  
  516.         OUT_RING(fill->bmp0);
  517.         OUT_RING(fill->bmp1);
  518.  
  519.         OUT_RING((y0<<16)|x0);
  520.         OUT_RING((y1<<16)|x1);
  521.  
  522.         if( (fill->border & 0xFF000000) != 0)
  523.         {
  524.            CP_REG(R5XX_DP_GUI_MASTER_CNTL,
  525.                   RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  526.                   RADEON_GMC_BRUSH_SOLID_COLOR      |
  527.                   RADEON_GMC_DST_32BPP              |
  528.                   RADEON_GMC_SRC_DATATYPE_COLOR     |
  529.                   R5XX_GMC_CLR_CMP_CNTL_DIS         |
  530.                   R5XX_GMC_WR_MSK_DIS               |
  531.                   R5XX_ROP3_P
  532.                  );
  533.  
  534.            CP_REG(R5XX_DP_BRUSH_FRGD_CLR, fill->border);
  535.  
  536.            if( y0 == fill->y)
  537.            {
  538.               CP_REG(R5XX_DST_Y_X,(y0<<16)|x0);
  539.               CP_REG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|1);
  540.               y0++;
  541.               h--;
  542.            }
  543.            if( y1 == yend )
  544.            {
  545.               CP_REG(R5XX_DST_Y_X,(y1<<16)|x0);
  546.               CP_REG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|1);
  547.               h--;
  548.            }
  549.            if( (h > 0) && (x0 == fill->x))
  550.            {
  551.               CP_REG(R5XX_DST_Y_X,(y0<<16)|x0);
  552.               CP_REG(R5XX_DST_WIDTH_HEIGHT,(1<<16)|h);
  553.            }
  554.            if( (h > 0) && (x1 == xend))
  555.            {
  556.               CP_REG(R5XX_DST_Y_X,(y0<<16)|x1);
  557.               CP_REG(R5XX_DST_WIDTH_HEIGHT,(1<<16)|h);
  558.            }
  559.         };
  560.  
  561.       COMMIT_RING();
  562.  
  563. #endif
  564.         safe_sti(ifl);
  565.      };
  566.      return ERR_OK;
  567. };
  568.  
  569.  
  570. #define ADDRREG(addr)  ((volatile u32_t *)(rhd.MMIOBase + (addr)))
  571.  
  572.  
  573. static int blit_host(u32_t dstpitch, int dstx, int dsty,
  574.                      u32_t  src, int srcx, int srcy,
  575.                      int w, int h, int srcpitch)
  576. {
  577.     u32_t     ifl;
  578.     color_t  *src_addr;
  579.  
  580.     ifl = safe_cli();
  581.  
  582. #if R300_PIO
  583.  
  584.     R5xxFIFOWait(5);
  585.  
  586.     OUTREG(R5XX_DP_GUI_MASTER_CNTL,
  587.                RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  588. //               RADEON_GMC_DST_CLIPPING           |
  589.                RADEON_GMC_BRUSH_NONE             |
  590.                RADEON_GMC_DST_32BPP              |
  591.                RADEON_GMC_SRC_DATATYPE_COLOR     |
  592.                RADEON_DP_SRC_SOURCE_HOST_DATA    |
  593.           //     RADEON_GMC_BYTE_MSB_TO_LSB        |
  594.                R5XX_GMC_CLR_CMP_CNTL_DIS         |
  595.                R5XX_GMC_WR_MSK_DIS               |
  596.                R5XX_ROP3_S
  597.               );
  598.  
  599.     OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT |
  600.                          R5XX_DST_Y_TOP_TO_BOTTOM);
  601.  
  602.     OUTREG(R5XX_DST_PITCH_OFFSET, dstpitch);
  603.  
  604. //        OUTREG(RADEON_SC_TOP_LEFT, (y << 16) | ((x+skipleft) & 0xffff));
  605. //        OUTREG(RADEON_SC_BOTTOM_RIGHT,  ((y+h) << 16) | ((x+w) & 0xffff));
  606.  
  607.     OUTREG(RADEON_DST_Y_X, (dsty << 16) | (dstx & 0xffff));
  608.     OUTREG(RADEON_DST_HEIGHT_WIDTH, (h << 16) | w);
  609.  
  610.  
  611.     src_addr = &((color_t*)src)[srcpitch*srcy/4+srcx];
  612.  
  613.     while ( h-- )
  614.     {
  615.         color_t *tmp_src = src_addr;
  616.         src_addr += srcpitch/4;
  617.  
  618.         int left = w;
  619.  
  620.         while( left )
  621.         {
  622.             volatile u32_t *d;
  623.  
  624.             if( left > 8 )
  625.             {
  626.                 int i;
  627.  
  628.                 R5xxFIFOWait(8);
  629.                 d = ADDRREG(RADEON_HOST_DATA0);
  630.  
  631.                                 /* Unrolling doesn't improve performance */
  632.                for ( i = 0; i < 8; i++)
  633.                    *d++ = *tmp_src++;
  634.                left -= 8;
  635.            }
  636.            else
  637.            {
  638.                R5xxFIFOWait(left);
  639.  
  640.                if( h )
  641.                    d = ADDRREG(RADEON_HOST_DATA7) - (left - 1);
  642.                else
  643.                    d = ADDRREG(RADEON_HOST_DATA_LAST) - (left - 1);
  644.  
  645.                for ( ; left; --left)
  646.                    *d++ = *tmp_src++;
  647.                left = 0;
  648.            };
  649.        };
  650.    };
  651.  
  652. #endif
  653.  
  654.    safe_sti(ifl);
  655.  
  656.    return ERR_OK;
  657. }
  658.  
  659.  
  660. int Blit(io_blit_t *blit)
  661. {
  662.    clip_t src_clip, dst_clip;
  663.  
  664.    local_pixmap_t *srcpixmap;
  665.    local_pixmap_t *dstpixmap;
  666.  
  667.    //dbgprintf("Pixblit src: %x dst: %x\n",blit->srcpix, blit->dstpix);
  668.  
  669.    dstpixmap = (blit->dstpix == (void*)-1) ? &scr_pixmap : blit->dstpix ;
  670.    srcpixmap = (blit->srcpix == (void*)-1) ? &scr_pixmap : blit->srcpix ;
  671.  
  672.    //dbgprintf("srcpixmap: %x dstpixmap: %x\n",srcpixmap, dstpixmap);
  673.  
  674.    //dbgprintf("dst.width: %d dst.height: %d\n", dstpixmap->width,dstpixmap->height);
  675.    //dbgprintf("src.width: %d src.height: %d\n", srcpixmap->width,srcpixmap->height);
  676.    //dbgprintf("srcpitch: %x dstpitch: %x\n",
  677.    //           srcpixmap->pitch_offset,dstpixmap->pitch_offset);
  678.  
  679.    src_clip.xmin = 0;
  680.    src_clip.ymin = 0;
  681.    src_clip.xmax = srcpixmap->width-1;
  682.    src_clip.ymax = srcpixmap->height-1;
  683.  
  684.    dst_clip.xmin = 0;
  685.    dst_clip.ymin = 0;
  686.    dst_clip.xmax = dstpixmap->width-1;
  687.    dst_clip.ymax = dstpixmap->height-1;
  688.  
  689.    if( !blit_clip(&dst_clip, &blit->dst_x, &blit->dst_y,
  690.                   &src_clip, &blit->src_x, &blit->src_y,
  691.                   &blit->w, &blit->h) )
  692.    {
  693.        u32_t *ring, write;
  694.        u32_t ifl;
  695.  
  696.        if( (srcpixmap->flags & PX_MEM_MASK)==PX_MEM_SYSTEM)
  697.            return blit_host(dstpixmap->pitch_offset,
  698.                             blit->dst_x, blit->dst_y,
  699.                             srcpixmap->mapped,
  700.                             blit->src_x, blit->src_y,
  701.                             blit->w, blit->h,
  702.                             srcpixmap->pitch);
  703.  
  704.        ifl = safe_cli();
  705.  
  706. #if R300_PIO
  707.  
  708.        R5xxFIFOWait(7);
  709.  
  710.        OUTREG(R5XX_DP_GUI_MASTER_CNTL,
  711.               RADEON_GMC_SRC_PITCH_OFFSET_CNTL  |
  712.               RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  713.               RADEON_GMC_BRUSH_NONE             |
  714.               RADEON_GMC_DST_32BPP              |
  715.               RADEON_GMC_SRC_DATATYPE_COLOR     |
  716.               RADEON_DP_SRC_SOURCE_MEMORY       |
  717.               R5XX_GMC_CLR_CMP_CNTL_DIS         |
  718.               R5XX_GMC_WR_MSK_DIS               |
  719.               R5XX_ROP3_S
  720.              );
  721.  
  722.        OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
  723.  
  724.        OUTREG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  725.        OUTREG(R5XX_SRC_PITCH_OFFSET, srcpixmap->pitch_offset);
  726.  
  727.        OUTREG(R5XX_SRC_Y_X,(blit->src_y<<16)|blit->src_x);
  728.        OUTREG(R5XX_DST_Y_X,(blit->dst_y<<16)|blit->dst_x);
  729.        OUTREG(R5XX_DST_HEIGHT_WIDTH,(blit->h<<16)|blit->w);
  730.  
  731. #else
  732.    BEGIN_RING(7);
  733.  
  734.        OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT, 5));
  735.  
  736.        OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL  |
  737.                 RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  738.                 RADEON_GMC_BRUSH_NONE             |
  739.                 RADEON_GMC_DST_32BPP              |
  740.                 RADEON_GMC_SRC_DATATYPE_COLOR     |
  741.                 RADEON_DP_SRC_SOURCE_MEMORY       |
  742.                 R5XX_GMC_CLR_CMP_CNTL_DIS         |
  743.                 R5XX_GMC_WR_MSK_DIS               |
  744.                 R5XX_ROP3_S
  745.                );
  746.  
  747.        OUT_RING(srcpixmap->pitch_offset);
  748.        OUT_RING(dstpixmap->pitch_offset);
  749.  
  750.        OUT_RING((blit->src_x<<16)|blit->src_y);
  751.        OUT_RING((blit->dst_x<<16)|blit->dst_y);
  752.        OUT_RING((blit->w<<16)|blit->h);
  753.    COMMIT_RING();
  754.  
  755. #endif
  756.        safe_sti(ifl);
  757.     };
  758.     return ERR_OK;
  759. };
  760.  
  761.  
  762. int BlitTransparent(io_blit_t *blit)
  763. {
  764.     clip_t src_clip, dst_clip;
  765.  
  766.     local_pixmap_t *srcpixmap;
  767.     local_pixmap_t *dstpixmap;
  768.  
  769.    // dbgprintf("Transblit src: %x dst: %x\n",blit->srcpix, blit->dstpix);
  770.  
  771.     dstpixmap = (blit->dstpix == (void*)-1) ? &scr_pixmap : blit->dstpix ;
  772.     srcpixmap = (blit->srcpix == (void*)-1) ? &scr_pixmap : blit->srcpix ;
  773.  
  774.     //dbgprintf("srcpixmap: %x dstpixmap: %x\n",srcpixmap, dstpixmap);
  775.  
  776.     //dbgprintf("dst.width: %d dst.height: %d\n", dstpixmap->width,dstpixmap->height);
  777.     //dbgprintf("src.width: %d src.height: %d\n", srcpixmap->width,srcpixmap->height);
  778.     //dbgprintf("srcpitch: %x dstpitch: %x\n",
  779.     //           srcpixmap->pitch_offset,dstpixmap->pitch_offset);
  780.     src_clip.xmin = 0;
  781.     src_clip.ymin = 0;
  782.     src_clip.xmax = srcpixmap->width-1;
  783.     src_clip.ymax = srcpixmap->height-1;
  784.  
  785.     dst_clip.xmin = 0;
  786.     dst_clip.ymin = 0;
  787.     dst_clip.xmax = dstpixmap->width-1;
  788.     dst_clip.ymax = dstpixmap->height-1;
  789.  
  790.     if( !blit_clip(&dst_clip, &blit->dst_x, &blit->dst_y,
  791.                    &src_clip, &blit->src_x, &blit->src_y,
  792.                    &blit->w, &blit->h) )
  793.     {
  794.        u32_t *ring, write;
  795.  
  796.        u32_t ifl;
  797.  
  798.        ifl = safe_cli();
  799.  
  800. #if R300_PIO
  801.  
  802.        R5xxFIFOWait(10);
  803.  
  804.        OUTREG(R5XX_DP_GUI_MASTER_CNTL,
  805.               RADEON_GMC_SRC_PITCH_OFFSET_CNTL  |
  806.               RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  807.               RADEON_GMC_BRUSH_NONE             |
  808.               RADEON_GMC_DST_32BPP              |
  809.               RADEON_GMC_SRC_DATATYPE_COLOR     |
  810.               RADEON_DP_SRC_SOURCE_MEMORY       |
  811.               R5XX_GMC_WR_MSK_DIS               |
  812.               R5XX_ROP3_S
  813.              );
  814.  
  815.        OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
  816.  
  817.        OUTREG(R5XX_CLR_CMP_CLR_SRC, blit->key);
  818.        OUTREG(R5XX_CLR_CMP_MASK, R5XX_CLR_CMP_MSK);
  819.        OUTREG(R5XX_CLR_CMP_CNTL, R5XX_SRC_CMP_EQ_COLOR | R5XX_CLR_CMP_SRC_SOURCE);
  820.  
  821.        OUTREG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  822.        OUTREG(R5XX_SRC_PITCH_OFFSET, srcpixmap->pitch_offset);
  823.  
  824.        OUTREG(R5XX_SRC_Y_X,(blit->src_y<<16)|blit->src_x);
  825.        OUTREG(R5XX_DST_Y_X,(blit->dst_y<<16)|blit->dst_x);
  826.        OUTREG(R5XX_DST_HEIGHT_WIDTH,(blit->h<<16)|blit->w);
  827.  
  828. #else
  829.  
  830.        BEGIN_RING(10);
  831.  
  832.          OUT_RING(CP_PACKET3(RADEON_CNTL_TRANBLT, 8));
  833.  
  834.          OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL  |
  835.                   RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  836.                   RADEON_GMC_BRUSH_NONE             |
  837.                   RADEON_GMC_DST_32BPP              |
  838.                   RADEON_GMC_SRC_DATATYPE_COLOR     |
  839.                   RADEON_DP_SRC_SOURCE_MEMORY       |
  840.                   R5XX_GMC_WR_MSK_DIS               |
  841.                   R5XX_ROP3_S
  842.                  );
  843.  
  844.          OUT_RING(srcpixmap->pitch_offset);
  845.          OUT_RING(dstpixmap->pitch_offset);
  846.  
  847.          OUT_RING(R5XX_CLR_CMP_SRC_SOURCE | R5XX_SRC_CMP_EQ_COLOR);
  848.          OUT_RING(blit->key);
  849.          OUT_RING(0xFFFFFFFF);
  850.  
  851.          OUT_RING((blit->src_x<<16)|blit->src_y);
  852.          OUT_RING((blit->dst_x<<16)|blit->dst_y);
  853.          OUT_RING((blit->w<<16)|blit->h);
  854.  
  855.        COMMIT_RING();
  856.  
  857. #endif
  858.  
  859.       safe_sti(ifl);
  860.     };
  861.     return ERR_OK;
  862. }
  863.  
  864.  
  865. #if 0
  866.  
  867. int LockPixmap(userpixmap_t *io)
  868. {
  869.   pixmap_t *pixmap;
  870.   size_t    size;
  871.   void     *usermap;
  872.  
  873.   dbgprintf("Lock pixmap %x\n", io->pixmap);
  874.  
  875.   if(io->pixmap == (pixmap_t*)-1)
  876.     return ERR_PARAM;
  877.   else
  878.     pixmap = io->pixmap;
  879.  
  880.   if( (pixmap->flags & 1) == PX_LOCK )
  881.     return ERR_PARAM;
  882.  
  883.   size = (pixmap->pitch*pixmap->width+4095) & ~ 4095;
  884.   if (usermap = UserAlloc(size))
  885.   {
  886.     CommitPages(usermap, ((u32_t)pixmap->raw+rhd.PhisBase)|7|(1<<9), size);
  887.     pixmap->flags |= PX_LOCK;
  888.     pixmap->usermap = usermap;
  889.     io->usermap = usermap;
  890.     io->pitch   = pixmap->pitch;
  891.     dbgprintf("map at %x\n", io->usermap);
  892.  
  893.     return ERR_OK;
  894.   }
  895.   else
  896.     return ERR_PARAM;
  897. };
  898.  
  899. int UnlockPixmap(userpixmap_t *io)
  900. {
  901.  pixmap_t *pixmap;
  902.  size_t    size;
  903.  
  904.  dbgprintf("Unlock pixmap %x\n", io->pixmap);
  905.  
  906.  if(io->pixmap == (pixmap_t*)-1)
  907.    return ERR_PARAM;
  908.  else
  909.    pixmap = io->pixmap;
  910.  
  911.  if( (pixmap->flags & 1) != PX_LOCK )
  912.    return ERR_PARAM;
  913.  
  914. /*   Sanity checks  */
  915.  
  916.  if( (pixmap->usermap == 0)||
  917.      ((u32_t)pixmap->usermap >= 0x80000000) ||
  918.      ((u32_t)pixmap->usermap & 4095)
  919.    )
  920.    return ERR_PARAM;
  921.  
  922.  size = (pixmap->pitch*pixmap->width+4095) & ~ 4095;
  923.  
  924.  UnmapPages(pixmap->usermap, size);
  925.  UserFree(pixmap->usermap);
  926.  pixmap->usermap =  NULL;
  927.  pixmap->flags  &= ~PX_LOCK;
  928.  io->usermap     =  NULL;
  929.  io->pitch       =  0;
  930.  
  931.  return ERR_OK;
  932. };
  933.  
  934. #endif
  935.