Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #define BRUSH_MONO   (0<<4)
  3.  
  4.  
  5. int DrawRect(draw_t* draw)
  6. {
  7.   int x0, y0, x1, y1;
  8.  
  9.   pixmap_t *dstpixmap;
  10.  
  11.   dstpixmap = (draw->dstpix == (void*)-1) ? &scr_pixmap : draw->dstpix ;
  12.  
  13.   x0 = draw->x;
  14.   y0 = draw->y;
  15.  
  16.   x1 = x0+draw->w-1;
  17.   y1 = y0+draw->h-1;
  18.  
  19. //  dbgprintf("draw rect x0:%d, y0:%d, x1:%d, y1:%d, color: %x\n",
  20. //             x0, y0, x1, y1, draw->color);
  21.  
  22.   if( ! BlockClip( &x0, &y0, &x1, &y1))
  23.   {
  24.      u32 *ring, write;
  25.      int w, h;
  26.      u32 ifl;
  27.  
  28.      w = x1-x0+1;
  29.      h = y1-y0+1;
  30.  
  31.      ifl = safe_cli();
  32.  
  33.  
  34. #if R300_PIO
  35.  
  36.      R5xxFIFOWait(7);
  37.  
  38.      OUTREG(R5XX_DP_GUI_MASTER_CNTL, rhd.gui_control | R5XX_ROP3_P |
  39.                                      R5XX_GMC_BRUSH_SOLID_COLOR |
  40.                                      R5XX_GMC_SRC_DATATYPE_COLOR);
  41.  
  42.      OUTREG(R5XX_DP_BRUSH_FRGD_CLR, draw->color);
  43.      OUTREG(R5XX_DP_WRITE_MASK, 0xFFFFFFFF);
  44.      OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
  45.      OUTREG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
  46.      OUTREG(R5XX_DST_Y_X,(y0<<16)|x0);
  47.      OUTREG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|h);
  48.  
  49. #else
  50.  
  51.      BEGIN_RING();
  52.        OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
  53.  
  54.        OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  55.                 RADEON_GMC_BRUSH_SOLID_COLOR      |
  56.                 RADEON_GMC_DST_32BPP              |
  57.                 RADEON_GMC_SRC_DATATYPE_COLOR     |
  58.                 (1 << 28)+(1 << 30) | R5XX_ROP3_P);
  59.  
  60.        OUT_RING(dstpixmap->pitch_offset);
  61.        OUT_RING(draw->color);
  62.        OUT_RING((x0<<16)|y0);
  63.        OUT_RING((w<<16)|h);
  64.      COMMIT_RING();
  65.  
  66. #endif
  67.  
  68.      safe_sti(ifl);
  69.   } ;
  70.   return ERR_OK;
  71. }
  72.  
  73. int FillRect(fill_t *fill)
  74. {
  75.   pixmap_t *dstpixmap;
  76.   int x0, y0, x1, y1;
  77.  
  78.   dstpixmap = (fill->dstpix == (void*)-1) ? &scr_pixmap : fill->dstpix ;
  79.  
  80.   x0 = fill->x;
  81.   y0 = fill->y;
  82.  
  83.   x1 = x0+fill->w-1;
  84.   y1 = y0+fill->h-1;
  85.  
  86. //  dbgprintf("fill rect x0:%d, y0:%d, x1:%d, y1:%d\n",
  87. //             x0, y0, x1, y1);
  88.  
  89.   if( ! BlockClip( &x0, &y0, &x1, &y1))
  90.   {
  91.      u32 *ring, write;
  92.      u32 ifl;
  93.  
  94.      ifl = safe_cli();
  95.  
  96. #if R300_PIO
  97.  
  98. #else
  99.  
  100.      BEGIN_RING();
  101.        OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT, 7));
  102.        OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL    |
  103.                 BRUSH_MONO                          |
  104.                 RADEON_GMC_DST_32BPP                |
  105.                 RADEON_GMC_SRC_DATATYPE_COLOR       |
  106.                 (1 << 28)+(1 << 30) | R5XX_ROP3_P);
  107.  
  108.          OUT_RING(dstpixmap->pitch_offset);
  109.          OUT_RING(fill->bkcolor);
  110.          OUT_RING(fill->fcolor);
  111.  
  112.          OUT_RING(fill->bmp0);
  113.          OUT_RING(fill->bmp1);
  114.  
  115.          OUT_RING((y0<<16)|x0);
  116.          OUT_RING((y1<<16)|x1);
  117.      COMMIT_RING();
  118.  
  119. #endif
  120.  
  121.      safe_sti(ifl);
  122.   };
  123.   return ERR_OK;
  124. }
  125.  
  126. int Blit(blit_t *blit)
  127. {
  128.   int x0, y0, x1, y1;
  129.  
  130.   x0 = blit->src_x;
  131.   y0 = blit->src_y;
  132.  
  133.   x1 = x0+blit->w-1;
  134.   y1 = y0+blit->h-1;
  135.  
  136.  
  137.   if( ! BlockClip( &x0, &y0, &x1, &y1))
  138.   {
  139.      u32 *ring, write;
  140.      int w, h;
  141.      u32 ifl;
  142.  
  143.      w = x1-x0+1;
  144.      h = y1-y0+1;
  145.  
  146.      ifl = safe_cli();
  147.  
  148. #if R300_PIO
  149.  
  150.  
  151. #else
  152.  
  153.      BEGIN_RING();
  154.        OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT, 5));
  155.  
  156.        OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL  |
  157.                 RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  158.                 RADEON_GMC_BRUSH_NONE             |
  159.                 RADEON_GMC_DST_32BPP              |
  160.                 RADEON_GMC_SRC_DATATYPE_COLOR     |
  161.                 RADEON_DP_SRC_SOURCE_MEMORY       |
  162.                 (1 << 28)+(1 << 30) | R5XX_ROP3_S);
  163.  
  164.        OUT_RING(rhd.dst_pitch_offset);
  165.        OUT_RING(rhd.dst_pitch_offset);
  166.  
  167.        OUT_RING((x0<<16)|y0);
  168.        OUT_RING((blit->dst_x<<16)|blit->dst_y);
  169.        OUT_RING((w<<16)|h);
  170.      COMMIT_RING();
  171.  
  172. #endif
  173.  
  174.      safe_sti(ifl);
  175.   } ;
  176.   return ERR_OK;
  177. }
  178.  
  179. int Line2P(line2p_t *draw)
  180. {
  181.  
  182.   int x0, y0, x1, y1;
  183.  
  184.   x0 = draw->x0;
  185.   y0 = draw->y0;
  186.  
  187.   x1 = draw->x1;
  188.   y1 = draw->y1;
  189.  
  190.   if ( !LineClip( &x0, &y0, &x1, &y1 ))
  191.   {
  192.     u32 ifl;
  193.     u32 *ring, write;
  194.  
  195.     ifl = safe_cli();
  196.  
  197. #if R300_PIO
  198.  
  199.      R5xxFIFOWait(7);
  200.  
  201.      OUTREG(R5XX_DP_GUI_MASTER_CNTL, rhd.gui_control | R5XX_ROP3_P |
  202.                                      R5XX_GMC_BRUSH_SOLID_COLOR |
  203.                                      R5XX_GMC_SRC_DATATYPE_COLOR);
  204.  
  205.      OUTREG(R5XX_DST_LINE_PATCOUNT, 0x55 << R5XX_BRES_CNTL_SHIFT);
  206.  
  207.      OUTREG(R5XX_DP_BRUSH_FRGD_CLR, draw->color);
  208.      OUTREG(R5XX_DP_WRITE_MASK, 0xFFFFFFFF);
  209.      OUTREG(R5XX_DST_PITCH_OFFSET, rhd.dst_pitch_offset);
  210.  
  211.      OUTREG(R5XX_DST_LINE_START,(y0<<16)|x0);
  212.      OUTREG(R5XX_DST_LINE_END,(y1<<16)|x1);
  213.  
  214. #else
  215.  
  216.      BEGIN_RING();
  217.          OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_POLYLINE, 4));
  218.          OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  219.                   RADEON_GMC_BRUSH_SOLID_COLOR      |
  220.                   RADEON_GMC_DST_32BPP              |
  221.                   RADEON_GMC_SRC_DATATYPE_COLOR     |
  222.                   (1 << 28)+(1 << 30) | R5XX_ROP3_P);
  223.  
  224.          OUT_RING(rhd.dst_pitch_offset);
  225.          OUT_RING(draw->color);
  226.          OUT_RING((y0<<16)|x0);
  227.          OUT_RING((y1<<16)|x1);
  228.      COMMIT_RING();
  229.  
  230. #endif
  231.      safe_sti(ifl);
  232.  
  233.   };
  234.   return ERR_OK;
  235. }
  236.  
  237.  
  238. int CreatePixmap(userpixmap_t *io)
  239. {
  240.  
  241.   pixmap_t *pixmap;
  242.  
  243.   u32_t pitch;
  244.   void *raw;
  245.  
  246.   if( (io->width == 0) || (io->width > 2048)||
  247.       (io->height == 0)|| (io->height > 2048))
  248.   {
  249.      dbgprintf("Invalid pixmap size w:%d h:%d\n", io->width,io->height);
  250.      return ERR_PARAM;
  251.  
  252.   };
  253.  
  254.   pitch = ((io->width+15)&~15)*4;
  255.   dbgprintf("pitch = %d\n", pitch);
  256.  
  257.   raw = rhd_mem_alloc(&rhd,RHD_MEM_FB,pitch*io->height) ;
  258.   if (! raw)
  259.   {
  260.     dbgprintf("Not enough memory for pixmap\n");
  261.     return ERR_PARAM;
  262.   };
  263.  
  264.   pixmap = malloc(sizeof(pixmap_t));
  265.   if(!pixmap)
  266.   {
  267.     rhd_mem_free(&rhd, RHD_MEM_FB,raw);
  268.     return ERR_PARAM;
  269.   }
  270.   else
  271.   {
  272.     io->pixmap  = pixmap;
  273.     io->usermap = NULL;
  274.     io->format  = PICT_a8r8g8b8;
  275.     io->pitch   = 0;
  276.  
  277.     pixmap->width   = io->width;
  278.     pixmap->height  = io->height;
  279.     pixmap->format  = PICT_a8r8g8b8;
  280.     pixmap->flags   = 0;
  281.     pixmap->pitch   = pitch;
  282.     pixmap->offset  = (u32_t)raw+rhd.FbIntAddress;
  283.     pixmap->pitch_offset =  ((pitch/64)<<22)| (pixmap->offset>>10);
  284.     pixmap->raw     = raw;
  285.     pixmap->usermap = NULL;
  286.  
  287.     dbgprintf("pixmap.pitch_offset: %x\n", pixmap->pitch_offset);
  288.     dbgprintf("width: %d height: %d\n",pixmap->width,pixmap->height );
  289.     dbgprintf("pixmap.offset: %x\n", pixmap->offset);
  290.  
  291.   }
  292.   return ERR_OK;
  293. }
  294.  
  295. int LockPixmap(userpixmap_t *io)
  296. {
  297.   pixmap_t *pixmap;
  298.   size_t    size;
  299.   void     *usermap;
  300.  
  301.   dbgprintf("Lock pixmap %x\n", io->pixmap);
  302.  
  303.   if(io->pixmap == (pixmap_t*)-1)
  304.     return ERR_PARAM;
  305.   else
  306.     pixmap = io->pixmap;
  307.  
  308.   if(pixmap->flags & 1 == 1 )
  309.     return ERR_PARAM;
  310.  
  311.   size = pixmap->pitch*pixmap->width;
  312.   if (usermap = UserAlloc(size))
  313.   {
  314.     CommitPages(usermap, ((u32_t)pixmap->raw+rhd.PhisBase)|7|(1<<9), size);
  315.     pixmap->flags |= 1;
  316.     pixmap->usermap = usermap;
  317.     io->usermap = usermap;
  318.     io->pitch   = pixmap->pitch;
  319.     dbgprintf("map at %x\n", io->usermap);
  320.  
  321.     return ERR_OK;
  322.   }
  323.   else
  324.     return ERR_PARAM;
  325. };
  326.  
  327.  
  328. int PixBlit(pixblit_t *blit)
  329. {
  330.  
  331.      u32 *ring, write;
  332.      int w, h;
  333.      u32 ifl;
  334.      int x0, y0;
  335.  
  336.      pixmap_t *srcpixmap;
  337.      pixmap_t *dstpixmap;
  338.  
  339.      //dbgprintf("Pixblit src: %x dst: %x\n",blit->srcpix, blit->dstpix);
  340.  
  341.      dstpixmap = (blit->dstpix == (void*)-1) ? &scr_pixmap : blit->dstpix ;
  342.      srcpixmap = (blit->srcpix == (void*)-1) ? &scr_pixmap : blit->srcpix ;
  343.  
  344.      //dbgprintf("srcpixmap: %x dstpixmap: %x\n",srcpixmap, dstpixmap);
  345.  
  346.      //dbgprintf("dst.width: %d dst.height: %d\n", dstpixmap->width,dstpixmap->height);
  347.      //dbgprintf("src.width: %d src.height: %d\n", srcpixmap->width,srcpixmap->height);
  348.      //dbgprintf("srcpitch: %x dstpitch: %x\n",
  349.      //           srcpixmap->pitch_offset,dstpixmap->pitch_offset);
  350.  
  351.      ifl = safe_cli();
  352.  
  353.  
  354.      BEGIN_RING();
  355.        OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT, 5));
  356.  
  357.        OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL  |
  358.                 RADEON_GMC_DST_PITCH_OFFSET_CNTL  |
  359.                 RADEON_GMC_BRUSH_NONE             |
  360.                 RADEON_GMC_DST_32BPP              |
  361.                 RADEON_GMC_SRC_DATATYPE_COLOR     |
  362.                 RADEON_DP_SRC_SOURCE_MEMORY       |
  363.                 (1 << 28)+(1 << 30) | R5XX_ROP3_S);
  364.  
  365.        OUT_RING(srcpixmap->pitch_offset);
  366.        OUT_RING(dstpixmap->pitch_offset);
  367.  
  368.        OUT_RING((blit->src_x<<16)|blit->src_y);
  369.        OUT_RING((blit->dst_x<<16)|blit->dst_y);
  370.        OUT_RING((blit->w<<16)|blit->h);
  371.      COMMIT_RING();
  372.  
  373.      safe_sti(ifl);
  374.   return ERR_OK;
  375. }
  376.