i830_rotate.c

来自「是由intel提供的针对intel显卡915以上系列的linux驱动」· C语言 代码 · 共 1,181 行 · 第 1/3 页

C
1,181
字号
/**************************************************************************Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas.All Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sub license, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice (including thenext paragraph) shall be included in all copies or substantial portionsof the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FORANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* * Reformatted with GNU indent (2.2.8), using the following options: * *    -bad -bap -c41 -cd0 -ncdb -ci6 -cli0 -cp0 -ncs -d0 -di3 -i3 -ip3 -l78 *    -lp -npcs -psl -sob -ss -br -ce -sc -hnl * * This provides a good match with the original i810 code and preferred * XFree86 formatting conventions. * * When editing this driver, please follow the existing formatting, and edit * with <TAB> characters expanded at 8-column intervals. *//* * Authors: *   Alan Hourihane <alanh@tungstengraphics.com> *   Brian Paul <brian.paul@tungstengraphics.com> *   Keith Whitwell <keith@tungstengraphics.com> */#include "xf86.h"#include "xf86_ansic.h"#include "xf86_OSproc.h"#include "servermd.h"#include "shadow.h"#include "i830.h"#ifdef XF86DRI#include "dri.h"#endifstatic void *I830WindowLinear (ScreenPtr pScreen,		 CARD32    row,		 CARD32    offset,		 int	   mode,		 CARD32    *size,		 void	   *closure){   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];   I830Ptr pI830 = I830PTR(pScrn);   CARD8 *ptr;   *size = (pScrn->bitsPerPixel * pI830->displayWidth >> 3);   if (I830IsPrimary(pScrn))      ptr = (CARD8 *) (pI830->FbBase + pI830->FrontBuffer.Start) + row * (*size) + offset;   else {      I830Ptr pI8301 = I830PTR(pI830->entityPrivate->pScrn_1);      ptr = (CARD8 *) (pI830->FbBase + pI8301->FrontBuffer2.Start) + row * (*size) + offset;   }   return (void *)ptr;}struct matrix23{	int m00, m01, m02;	int m10, m11, m12;};static voidmatrix23Set(struct matrix23 *m,            int m00, int m01, int m02,            int m10, int m11, int m12){   m->m00 = m00;   m->m01 = m01;   m->m02 = m02;   m->m10 = m10;   m->m11 = m11;   m->m12 = m12;}/* * Transform (x,y) coordinate by the given matrix. */static voidmatrix23TransformCoordf(const struct matrix23 *m, float *x, float *y){   const float x0 = *x;   const float y0 = *y;   *x = m->m00 * x0 + m->m01 * y0 + m->m02;   *y = m->m10 * x0 + m->m11 * y0 + m->m12;}/* * Make rotation matrix for width X height screen. */static voidmatrix23Rotate(struct matrix23 *m, int width, int height, int angle){   switch (angle) {   case 0:      matrix23Set(m, 1, 0, 0, 0, 1, 0);      break;   case 90:      matrix23Set(m, 0, 1, 0,  -1, 0, width);      break;   case 180:      matrix23Set(m, -1, 0, width,  0, -1, height);      break;   case 270:      matrix23Set(m, 0, -1, height,  1, 0, 0);      break;   default:      break;   }}/* Doesn't matter on the order for our purposes */typedef struct {   GLubyte red, green, blue, alpha;} intel_color_t;/* Vertex format */typedef union {   struct {      GLfloat x, y, z, w;      intel_color_t color;      intel_color_t specular;      GLfloat u0, v0;      GLfloat u1, v1;      GLfloat u2, v2;      GLfloat u3, v3;   } v;   GLfloat f[24];   GLuint  ui[24];   GLubyte ub4[24][4];} intelVertex, *intelVertexPtr;static void draw_poly(CARD32 *vb,                      float verts[][2],                      float texcoords[][2]){   int vertex_size = 8;   intelVertex tmp;   int i, k;   /* initial constant vertex fields */   tmp.v.z = 1.0;   tmp.v.w = 1.0;    tmp.v.color.red = 255;   tmp.v.color.green = 255;   tmp.v.color.blue = 255;   tmp.v.color.alpha = 255;   tmp.v.specular.red = 0;   tmp.v.specular.green = 0;   tmp.v.specular.blue = 0;   tmp.v.specular.alpha = 0;   for (k = 0; k < 4; k++) {      tmp.v.x = verts[k][0];      tmp.v.y = verts[k][1];      tmp.v.u0 = texcoords[k][0];      tmp.v.v0 = texcoords[k][1];      for (i = 0 ; i < vertex_size ; i++)         vb[i] = tmp.ui[i];      vb += vertex_size;   }}static voidI915UpdateRotate (ScreenPtr      pScreen,                 shadowBufPtr   pBuf){   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];   I830Ptr pI830 = I830PTR(pScrn);   ScrnInfoPtr pScrn1 = pScrn;   I830Ptr pI8301 = NULL;   RegionPtr	damage = shadowDamage(pBuf);   int		nbox = REGION_NUM_RECTS (damage);   BoxPtr		pbox = REGION_RECTS (damage);   int		box_x1, box_x2, box_y1, box_y2;   CARD32	vb[32];	/* 32 dword vertex buffer */   float verts[4][2], tex[4][2];   struct matrix23 rotMatrix;   int j;   int use_fence;   Bool updateInvarient = FALSE;#ifdef XF86DRI   drmI830Sarea *sarea = NULL;   drm_context_t myContext = 0;#endif   Bool didLock = FALSE;   if (I830IsPrimary(pScrn)) {      pI8301 = pI830;   } else {      pI8301 = I830PTR(pI830->entityPrivate->pScrn_1);      pScrn1 = pI830->entityPrivate->pScrn_1;   }   switch (pI830->rotation) {      case RR_Rotate_90:         matrix23Rotate(&rotMatrix,                     pScreen->width, pScreen->height,                     90);	 break;      case RR_Rotate_180:         matrix23Rotate(&rotMatrix,                     pScreen->width, pScreen->height,                     180);	 break;      case RR_Rotate_270:         matrix23Rotate(&rotMatrix,                     pScreen->width, pScreen->height,                     270);	 break;      default:	 break;   }#ifdef XF86DRI   if (pI8301->directRenderingEnabled) {      sarea = DRIGetSAREAPrivate(pScrn1->pScreen);      myContext = DRIGetContext(pScrn1->pScreen);      didLock = I830DRILock(pScrn1);   }#endif   if (pScrn->scrnIndex != *pI830->used3D)      updateInvarient = TRUE;    if (sarea->ctxOwner != myContext)      updateInvarient = TRUE;   if (updateInvarient) {      *pI830->used3D = pScrn->scrnIndex;#ifdef XF86DRI      if (sarea)         sarea->ctxOwner = myContext;#endif      BEGIN_LP_RING(64);      /* invarient state */      OUT_RING(MI_NOOP);      OUT_RING(0x66014140);      OUT_RING(0x7d990000);      OUT_RING(0x00000000);      OUT_RING(0x7d9a0000);      OUT_RING(0x00000000);      OUT_RING(0x7d980000);      OUT_RING(0x00000000);      OUT_RING(0x76fac688);      OUT_RING(0x6700a770);      OUT_RING(0x7d040081);      OUT_RING(0x00000000);      /* flush map & render cache */      OUT_RING(MI_FLUSH | MI_WRITE_DIRTY_STATE | MI_INVALIDATE_MAP_CACHE);      OUT_RING(0x00000000);      /* draw rect */      OUT_RING(0x7d800003);      OUT_RING(0x00000000);      OUT_RING(0x00000000);      OUT_RING((pScrn->virtualX - 1) | (pScrn->virtualY - 1) << 16);      OUT_RING(0x00000000);      OUT_RING(0x00000000);      /* scissor */      OUT_RING(0x7c800002);      OUT_RING(0x7d810001);      OUT_RING(0x00000000);      OUT_RING(0x00000000);      OUT_RING(0x7c000003);      OUT_RING(0x7d070000);      OUT_RING(0x00000000);      OUT_RING(0x68000002);      /* context setup */      OUT_RING(0x6db3ffff);      OUT_RING(0x7d040744);      OUT_RING(0xfffffff0);      OUT_RING(0x00902c80);      OUT_RING(0x00000000);      OUT_RING(0x00020216);      OUT_RING(0x6ba008a1);      OUT_RING(0x7d880000);      OUT_RING(0x00000000);      /* dv0 */      OUT_RING(0x7d850000);      /* dv1 */      if (pI830->cpp == 1)         OUT_RING(0x10880000);      else if (pI830->cpp == 2)            OUT_RING(0x10880200);         else            OUT_RING(0x10880308);      /* stipple */      OUT_RING(0x7d830000);      OUT_RING(0x00000000);      /* fragment program - texture blend replace*/      OUT_RING(0x7d050008);      OUT_RING(0x19180000);      OUT_RING(0x00000000);      OUT_RING(0x00000000);      OUT_RING(0x19083c00);      OUT_RING(0x00000000);      OUT_RING(0x00000000);      OUT_RING(0x15200000);      OUT_RING(0x01000000);      OUT_RING(0x00000000);      /* texture sampler state */      OUT_RING(0x7d010003);      OUT_RING(0x00000001);      OUT_RING(0x00000000);      OUT_RING(0x00000000);      OUT_RING(0x00000000);      /* front buffer, pitch, offset */      OUT_RING(0x7d8e0001);      OUT_RING(0x03800000 | (((pI830->displayWidth * pI830->cpp) / 4) << 2));      if (I830IsPrimary(pScrn))         OUT_RING(pI830->FrontBuffer.Start);      else          OUT_RING(pI8301->FrontBuffer2.Start);      /* Set the entire frontbuffer up as a texture */      OUT_RING(0x7d000003);      OUT_RING(0x00000001);      if (I830IsPrimary(pScrn))          OUT_RING(pI830->RotatedMem.Start);      else 	 OUT_RING(pI8301->RotatedMem2.Start);      if (pI830->disableTiling)         use_fence = 0;      else         use_fence = 4;            if (pI830->cpp == 1)         use_fence |= 0x80; /* MAPSURF_8BIT */      else      if (pI830->cpp == 2)         use_fence |= 0x100; /* MAPSURF_16BIT */      else         use_fence |= 0x180; /* MAPSURF_32BIT */      OUT_RING(use_fence | (pScreen->height - 1) << 21 | (pScreen->width - 1) << 10);      OUT_RING(((((pScrn->displayWidth * pI830->cpp) / 4) - 1) << 21));      ADVANCE_LP_RING();   }      {      BEGIN_LP_RING(2);      OUT_RING(MI_FLUSH | MI_WRITE_DIRTY_STATE | MI_INVALIDATE_MAP_CACHE);      OUT_RING(0x00000000);      ADVANCE_LP_RING();   }   while (nbox--)   {      box_x1 = pbox->x1;      box_y1 = pbox->y1;      box_x2 = pbox->x2;      box_y2 = pbox->y2;      pbox++;      BEGIN_LP_RING(40);      OUT_RING(MI_NOOP);      OUT_RING(MI_NOOP);      OUT_RING(MI_NOOP);      OUT_RING(MI_NOOP);      OUT_RING(MI_NOOP);      OUT_RING(MI_NOOP);      OUT_RING(MI_NOOP);      /* vertex data */      OUT_RING(0x7f0c001f);      verts[0][0] = box_x1; verts[0][1] = box_y1;      verts[1][0] = box_x2; verts[1][1] = box_y1;      verts[2][0] = box_x2; verts[2][1] = box_y2;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?