<commit_before>/*
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 *
 * Graphics driver for ATI Radeon cards written by
 *             <NAME> <<EMAIL>>.  
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
 
#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <dfb_types.h>
#include <directfb.h>

#include <direct/types.h>
#include <direct/messages.h>
#include <direct/util.h>

#include <core/coredefs.h>
#include <core/coretypes.h>
#include <core/state.h>
#include <core/gfxcard.h>

#include "radeon.h"
#include "radeon_regs.h"
#include "radeon_mmio.h"
#include "radeon_3d.h"


static __inline__ void
out_vertex2d0( volatile __u8 *mmio, float x, float y )
{
     *((volatile float*)(mmio+SE_PORT_DATA0)) = x;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = y;
}

static __inline__ void
out_vertex2d2( volatile __u8 *mmio, float x, float y, float s, float t )
{
     *((volatile float*)(mmio+SE_PORT_DATA0)) = x;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = y;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = s;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = t;
}

static __inline__ void
out_vertex3d( volatile __u8 *mmio,
              float x, float y, float z, float w, float s, float t )
{
     *((volatile float*)(mmio+SE_PORT_DATA0)) = x;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = y;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = z;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = w;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = s;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = t;
}


static void
r200DoFillRectangle3D( RadeonDriverData *rdrv,
                       RadeonDeviceData *rdev,
                       DFBRectangle     *rect )
{
     volatile __u8 *mmio = rdrv->mmio_base;

     if (rect->w == 1 && rect->h == 1) {
          radeon_waitfifo( rdrv, rdev, 3 );
          
          radeon_out32( mmio, SE_VF_CNTL, VF_PRIM_TYPE_POINT_LIST |
                                          VF_PRIM_WALK_DATA      |
                                          (1 << VF_NUM_VERTICES_SHIFT) );

          out_vertex2d0( mmio, rect->x, rect->y );
     }
     else {
          radeon_waitfifo( rdrv, rdev, 7 );
     
          radeon_out32( mmio, SE_VF_CNTL, VF_PRIM_TYPE_RECTANGLE_LIST |
                                          VF_PRIM_WALK_DATA           |
                                          (3 << VF_NUM_VERTICES_SHIFT) );

          out_vertex2d0( mmio, rect->x        , rect->y         );
          out_vertex2d0( mmio, rect->x+rect->w, rect->y         );
          out_vertex2d0( mmio, rect->x+rect->w, rect->y+rect->h );
     }
}

bool r200FillRectangle3D( void *drv, void *dev, DFBRectangle *rect )
{
     RadeonDriverData *rdrv = (RadeonDriverData*) drv;
     RadeonDeviceData *rdev = (RadeonDeviceData*) dev;

     r200DoFillRectangle3D( rdrv, rdev, rect );

     return true;
}

bool r200FillRectangle3D_420( void *drv, void *dev, DFBRectangle *rect )
{
     RadeonDriverData *rdrv = (RadeonDriverData*) drv;
     RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
     DFBRegion      *clip = &rdev->clip;
     volatile __u8  *mmio = rdrv->mmio_base;

     /* Fill Luma plane */
     r200DoFillRectangle3D( rdrv, rdev, rect );
          
     /* Scale coordinates */
     rect->x /= 2;
     rect->y /= 2;
     rect->w  = (rect->w+1) >> 1;
     rect->h  = (rect->h+1) >> 1;

     /* Prepare Cb plane */
     radeon_waitfifo( rdrv, rdev, 5 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cb );
     radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch/2 );
     radeon_out32( mmio, RE_TOP_LEFT, (clip->y1/2 << 16) |
                                      (clip->x1/2 & 0xffff) );
     radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2/2 << 16) |
                                          (clip->x2/2 & 0xffff) );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->cb_cop );

     /* Fill Cb plane */
     r200DoFillRectangle3D( rdrv, rdev, rect );

     radeon_waitfifo( rdrv, rdev, 2 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cr );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->cr_cop );

     /* Fill Cr plane */
     r200DoFillRectangle3D( rdrv, rdev, rect );

     /* Reset */
     radeon_waitfifo( rdrv, rdev, 5 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset );
     radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch );
     radeon_out32( mmio, RE_TOP_LEFT, (clip->y1 << 16) |
                                      (clip->x1 & 0xffff) );
     radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2 << 16) |
                                          (clip->x2 & 0xffff) );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->y_cop );

     return true;
}

static void
r200DoFillTriangle( RadeonDriverData *rdrv,
                    RadeonDeviceData *rdev,
                    DFBTriangle      *tri )
{
     volatile __u8 *mmio = rdrv->mmio_base;

     radeon_waitfifo( rdrv, rdev, 7 );
     
     radeon_out32( mmio, SE_VF_CNTL, VF_PRIM_TYPE_TRIANGLE_LIST |
                                     VF_PRIM_WALK_DATA          |
                                     (3 << VF_NUM_VERTICES_SHIFT) );
     
     out_vertex2d0( mmio, tri->x1, tri->y1 );
     out_vertex2d0( mmio, tri->x2, tri->y2 );
     out_vertex2d0( mmio, tri->x3, tri->y3 );
}

bool r200FillTriangle( void *drv, void *dev, DFBTriangle *tri )
{
     RadeonDriverData *rdrv = (RadeonDriverData*) drv;
     RadeonDeviceData *rdev = (RadeonDeviceData*) dev;

     r200DoFillTriangle( rdrv, rdev, tri );
     
     return true;
}

bool r200FillTriangle_420( void *drv, void *dev, DFBTriangle *tri )
{
     RadeonDriverData *rdrv = (RadeonDriverData*) drv;
     RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
     DFBRegion        *clip = &rdev->clip;
     volatile __u8    *mmio = rdrv->mmio_base;

     /* Fill Luma plane */
     r200DoFillTriangle( rdrv, rdev, tri );
          
     /* Scale coordinates */
     tri->x1 /= 2;
     tri->y1 /= 2;
     tri->x2 /= 2;
     tri->y2 /= 2;
     tri->x3 /= 2;
     tri->y3 /= 2;

     /* Prepare Cb plane */
     radeon_waitfifo( rdrv, rdev, 5 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cb );
     radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch/2 );
     radeon_out32( mmio, RE_TOP_LEFT, (clip->y1/2 << 16) |
                                      (clip->x1/2 & 0xffff) );
     radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2/2 << 16) |
                                          (clip->x2/2 & 0xffff) );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->cb_cop );

     /* Fill Cb plane */
     r200DoFillTriangle( rdrv, rdev, tri );

     radeon_waitfifo( rdrv, rdev, 2 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cr );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->cr_cop );

     /* Fill Cr plane */
     r200DoFillTriangle( rdrv, rdev, tri );

     /* Reset */
     radeon_waitfifo( rdrv, rdev, 5 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset );
     radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch );
     radeon_out32( mmio, RE_TOP_LEFT, (clip->y1 << 16) |
                                      (clip->x1 & 0xffff) );
     radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2 << 16) |
                                        (clip->x2 & 0xffff) );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->y_cop );
     
     return true;
}

static void
r200DoDrawRectangle3D( RadeonDriverData *rdrv,
                       RadeonDeviceData *rdev,
                       DFBRectangle     *rect )
{
     volatile __u8 *mmio = rdrv->mmio_base;

     radeon_waitfifo( rdrv, rdev, 25 );
          
     radeon_out32( mmio, SE_VF_CNTL, VF_PRIM_TYPE_RECTANGLE_LIST |
                                     VF_PRIM_WALK_DATA           |
                                     VF_RADEON_MODE              |
                                     (12 << VF_NUM_VERTICES_SHIFT) );
     /* top line */
     out_vertex2d0( mmio, rect->x          , rect->y           );
     out_vertex2d0( mmio, rect->x+rect->w  , rect->y           );
     out_vertex2d0( mmio, rect->x+rect->w  , rect->y+1         );
     /* right line */
     out_vertex2d0( mmio, rect->x+rect->w-1, rect->y+1         );
     out_vertex2d0( mmio, rect->x+rect->w  , rect->y+1         );<commit_msg>Removed (erroneously set) flag VF_RADEON_MODE in r200DoDrawRectangle3D().<commit_after>/*
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 *
 * Graphics driver for ATI Radeon cards written by
 *             <NAME> <<EMAIL>>.  
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
 
#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <dfb_types.h>
#include <directfb.h>

#include <direct/types.h>
#include <direct/messages.h>
#include <direct/util.h>

#include <core/coredefs.h>
#include <core/coretypes.h>
#include <core/state.h>
#include <core/gfxcard.h>

#include "radeon.h"
#include "radeon_regs.h"
#include "radeon_mmio.h"
#include "radeon_3d.h"


static __inline__ void
out_vertex2d0( volatile __u8 *mmio, float x, float y )
{
     *((volatile float*)(mmio+SE_PORT_DATA0)) = x;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = y;
}

static __inline__ void
out_vertex2d2( volatile __u8 *mmio, float x, float y, float s, float t )
{
     *((volatile float*)(mmio+SE_PORT_DATA0)) = x;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = y;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = s;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = t;
}

static __inline__ void
out_vertex3d( volatile __u8 *mmio,
              float x, float y, float z, float w, float s, float t )
{
     *((volatile float*)(mmio+SE_PORT_DATA0)) = x;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = y;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = z;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = w;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = s;
     *((volatile float*)(mmio+SE_PORT_DATA0)) = t;
}


static void
r200DoFillRectangle3D( RadeonDriverData *rdrv,
                       RadeonDeviceData *rdev,
                       DFBRectangle     *rect )
{
     volatile __u8 *mmio = rdrv->mmio_base;

     if (rect->w == 1 && rect->h == 1) {
          radeon_waitfifo( rdrv, rdev, 3 );
          
          radeon_out32( mmio, SE_VF_CNTL, VF_PRIM_TYPE_POINT_LIST |
                                          VF_PRIM_WALK_DATA      |
                                          (1 << VF_NUM_VERTICES_SHIFT) );

          out_vertex2d0( mmio, rect->x, rect->y );
     }
     else {
          radeon_waitfifo( rdrv, rdev, 7 );
     
          radeon_out32( mmio, SE_VF_CNTL, VF_PRIM_TYPE_RECTANGLE_LIST |
                                          VF_PRIM_WALK_DATA           |
                                          (3 << VF_NUM_VERTICES_SHIFT) );

          out_vertex2d0( mmio, rect->x        , rect->y         );
          out_vertex2d0( mmio, rect->x+rect->w, rect->y         );
          out_vertex2d0( mmio, rect->x+rect->w, rect->y+rect->h );
     }
}

bool r200FillRectangle3D( void *drv, void *dev, DFBRectangle *rect )
{
     RadeonDriverData *rdrv = (RadeonDriverData*) drv;
     RadeonDeviceData *rdev = (RadeonDeviceData*) dev;

     r200DoFillRectangle3D( rdrv, rdev, rect );

     return true;
}

bool r200FillRectangle3D_420( void *drv, void *dev, DFBRectangle *rect )
{
     RadeonDriverData *rdrv = (RadeonDriverData*) drv;
     RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
     DFBRegion      *clip = &rdev->clip;
     volatile __u8  *mmio = rdrv->mmio_base;

     /* Fill Luma plane */
     r200DoFillRectangle3D( rdrv, rdev, rect );
          
     /* Scale coordinates */
     rect->x /= 2;
     rect->y /= 2;
     rect->w  = (rect->w+1) >> 1;
     rect->h  = (rect->h+1) >> 1;

     /* Prepare Cb plane */
     radeon_waitfifo( rdrv, rdev, 5 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cb );
     radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch/2 );
     radeon_out32( mmio, RE_TOP_LEFT, (clip->y1/2 << 16) |
                                      (clip->x1/2 & 0xffff) );
     radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2/2 << 16) |
                                          (clip->x2/2 & 0xffff) );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->cb_cop );

     /* Fill Cb plane */
     r200DoFillRectangle3D( rdrv, rdev, rect );

     radeon_waitfifo( rdrv, rdev, 2 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cr );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->cr_cop );

     /* Fill Cr plane */
     r200DoFillRectangle3D( rdrv, rdev, rect );

     /* Reset */
     radeon_waitfifo( rdrv, rdev, 5 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset );
     radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch );
     radeon_out32( mmio, RE_TOP_LEFT, (clip->y1 << 16) |
                                      (clip->x1 & 0xffff) );
     radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2 << 16) |
                                          (clip->x2 & 0xffff) );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->y_cop );

     return true;
}

static void
r200DoFillTriangle( RadeonDriverData *rdrv,
                    RadeonDeviceData *rdev,
                    DFBTriangle      *tri )
{
     volatile __u8 *mmio = rdrv->mmio_base;

     radeon_waitfifo( rdrv, rdev, 7 );
     
     radeon_out32( mmio, SE_VF_CNTL, VF_PRIM_TYPE_TRIANGLE_LIST |
                                     VF_PRIM_WALK_DATA          |
                                     (3 << VF_NUM_VERTICES_SHIFT) );
     
     out_vertex2d0( mmio, tri->x1, tri->y1 );
     out_vertex2d0( mmio, tri->x2, tri->y2 );
     out_vertex2d0( mmio, tri->x3, tri->y3 );
}

bool r200FillTriangle( void *drv, void *dev, DFBTriangle *tri )
{
     RadeonDriverData *rdrv = (RadeonDriverData*) drv;
     RadeonDeviceData *rdev = (RadeonDeviceData*) dev;

     r200DoFillTriangle( rdrv, rdev, tri );
     
     return true;
}

bool r200FillTriangle_420( void *drv, void *dev, DFBTriangle *tri )
{
     RadeonDriverData *rdrv = (RadeonDriverData*) drv;
     RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
     DFBRegion        *clip = &rdev->clip;
     volatile __u8    *mmio = rdrv->mmio_base;

     /* Fill Luma plane */
     r200DoFillTriangle( rdrv, rdev, tri );
          
     /* Scale coordinates */
     tri->x1 /= 2;
     tri->y1 /= 2;
     tri->x2 /= 2;
     tri->y2 /= 2;
     tri->x3 /= 2;
     tri->y3 /= 2;

     /* Prepare Cb plane */
     radeon_waitfifo( rdrv, rdev, 5 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cb );
     radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch/2 );
     radeon_out32( mmio, RE_TOP_LEFT, (clip->y1/2 << 16) |
                                      (clip->x1/2 & 0xffff) );
     radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2/2 << 16) |
                                          (clip->x2/2 & 0xffff) );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->cb_cop );

     /* Fill Cb plane */
     r200DoFillTriangle( rdrv, rdev, tri );

     radeon_waitfifo( rdrv, rdev, 2 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cr );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->cr_cop );

     /* Fill Cr plane */
     r200DoFillTriangle( rdrv, rdev, tri );

     /* Reset */
     radeon_waitfifo( rdrv, rdev, 5 );
     radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset );
     radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch );
     radeon_out32( mmio, RE_TOP_LEFT, (clip->y1 << 16) |
                                      (clip->x1 & 0xffff) );
     radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2 << 16) |
                                        (clip->x2 & 0xffff) );
     radeon_out32( mmio, R200_PP_TFACTOR_1, rdev->y_cop );
     
     return true;
}

static void
r200DoDrawRectangle3D( RadeonDriverData *rdrv,
                       RadeonDeviceData *rdev,
                       DFBRectangle     *rect )
{
     volatile __u8 *mmio = rdrv->mmio_base;

     radeon_waitfifo( rdrv, rdev, 25 );
          
     radeon_out32( mmio, SE_VF_CNTL, VF_PRIM_TYPE_RECTANGLE_LIST |
                                     VF_PRIM_WALK_DATA           |
                                     (12 << VF_NUM_VERTICES_SHIFT) );
     /* top line */
     out_vertex2d0( mmio, rect->x          , rect->y           );
     out_vertex2d0( mmio, rect->x+rect->w  , rect->y           );
     out_vertex2d0( mmio, rect->x+rect->w  , rect->y+1         );
     /* right line */
     out_vertex2d0( mmio, rect->x+rect->w-1, rect->y+1         );
     out_vertex2d0( mmio, rect->x+rect->w  , rect->y+1         );
{'fraction_non_alphanumeric': 0.12440566090507356, 'fraction_numerical': 0.035352687811154, 'mean_word_length': 2.1664895501239814, 'pattern_counts': {'":': 0, '<': 91, '<?xml version=': 0, '>': 219, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 49, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4863239', 'n_tokens_mistral': 6997, 'n_tokens_neox': 6414, 'n_words': 1415}