⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgapixel.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
      for (i = 0 ; i < nbox ; )      {	 int nr = MIN2(i + MGA_NR_SAREA_CLIPRECTS, dPriv->numClipRects);	 drm_clip_rect_t *box = dPriv->pClipRects;	 drm_clip_rect_t *b = mmesa->sarea->boxes;	 int n = 0;	 for ( ; i < nr ; i++) {	    GLint bx = box[i].x1;	    GLint by = box[i].y1;	    GLint bw = box[i].x2 - bx;	    GLint bh = box[i].y2 - by;	    if (bx < x) bw -= x - bx, bx = x;	    if (by < y) bh -= y - by, by = y;	    if (bx + bw > x + width) bw = x + width - bx;	    if (by + bh > y + height) bh = y + height - by;	    if (bw <= 0) continue;	    if (bh <= 0) continue;	    b->x1 = bx;	    b->y1 = by;	    b->x2 = bx + bw;	    b->y2 = by + bh;	    b++;	    n++;	 }	 mmesa->sarea->nbox = n;	 if (n && (retcode = drmCommandWrite( mmesa->driFd, DRM_MGA_BLIT,                                              &blit, sizeof(drmMGABlit)))) {	    fprintf(stderr, "blit ioctl failed, retcode = %d\n", retcode);	    UNLOCK_HARDWARE( mmesa );	    exit(1);	 }      }      UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT );   }#endif   UNLOCK_HARDWARE( mmesa );   return GL_TRUE;}static voidmgaDDReadPixels( GLcontext *ctx,		 GLint x, GLint y, GLsizei width, GLsizei height,		 GLenum format, GLenum type,		 const struct gl_pixelstore_attrib *pack,		 GLvoid *pixels ){   if (!mgaTryReadPixels( ctx, x, y, width, height, format, type, pack, pixels))      _swrast_ReadPixels( ctx, x, y, width, height, format, type, pack, pixels);}static void do_draw_pix( GLcontext *ctx,			 GLint x, GLint y, GLsizei width, GLsizei height,			 GLint pitch,			 const void *pixels,			 GLuint dest, GLuint planemask){#if 0   mgaContextPtr mmesa = MGA_CONTEXT(ctx);   drmMGABlit blit;   __DRIdrawablePrivate *dPriv = mmesa->driDrawable;   drm_clip_rect_t pbox = dPriv->pClipRects;   int nbox = dPriv->numClipRects;   int retcode, i;   y = dPriv->h - y - height;   x += mmesa->drawX;   y += mmesa->drawY;   blit.dest = dest;   blit.planemask = planemask;   blit.source = ((mmesa->mgaScreen->agp.handle + AGP_OFFSET(mmesa, pixels))		  | SO_srcmap_sys | SO_srcacc_agp);   blit.dest_pitch = mmesa->mgaScreen->frontPitch / mmesa->mgaScreen->cpp;   blit.source_pitch = pitch;   blit.delta_sx = -x;   blit.delta_sy = -y;   blit.delta_dx = 0;   blit.delta_dy = 0;   if (ctx->Pixel.ZoomY == -1) {      blit.height = height;      blit.ydir = 1;   } else {      blit.height = height;      blit.ydir = -1;   }   if (0) fprintf(stderr,		  "doing drawpixel blit src_pitch %d dst_pitch %d\n",		  blit.source_pitch, blit.dest_pitch);   for (i = 0 ; i < nbox ; )   {      int nr = MIN2(i + MGA_NR_SAREA_CLIPRECTS, dPriv->numClipRects);      drm_clip_rect_t *box = mmesa->pClipRects;      drm_clip_rect_t *b = mmesa->sarea->boxes;      int n = 0;      for ( ; i < nr ; i++) {	 GLint bx = box[i].x1;	 GLint by = box[i].y1;	 GLint bw = box[i].x2 - bx;	 GLint bh = box[i].y2 - by;	 if (bx < x) bw -= x - bx, bx = x;	 if (by < y) bh -= y - by, by = y;	 if (bx + bw > x + width) bw = x + width - bx;	 if (by + bh > y + height) bh = y + height - by;	 if (bw <= 0) continue;	 if (bh <= 0) continue;	 b->x1 = bx;	 b->y1 = by;	 b->x2 = bx + bw;	 b->y2 = by + bh;	 b++;	 n++;      }      mmesa->sarea->nbox = n;      if (n && (retcode = drmCommandWrite( mmesa->driFd, DRM_MGA_BLIT,                                              &blit, sizeof(drmMGABlit)))) {	 fprintf(stderr, "blit ioctl failed, retcode = %d\n", retcode);	 UNLOCK_HARDWARE( mmesa );	 exit(1);      }   }#endif}static GLbooleanmgaTryDrawPixels( GLcontext *ctx,		  GLint x, GLint y, GLsizei width, GLsizei height,		  GLenum format, GLenum type,		  const struct gl_pixelstore_attrib *unpack,		  const GLvoid *pixels ){   mgaContextPtr mmesa = MGA_CONTEXT(ctx);   GLint size, skipPixels, skipRows;   GLint pitch = unpack->RowLength ? unpack->RowLength : width;   GLuint dest, planemask;   GLuint cpp = mmesa->mgaScreen->cpp;   if (!clip_pixelrect(ctx, ctx->DrawBuffer,		       &x, &y, &width, &height,		       &skipPixels, &skipRows, &size)) {      return GL_TRUE;   }   switch (format) {#if defined(MESA_packed_depth_stencil)   case GL_DEPTH_STENCIL_MESA:      dest = mmesa->mgaScreen->depthOffset;      planemask = ~0;      if (!check_depth_stencil_24_8(ctx, type, unpack, pixels, size, pitch) ||	  !check_depth_per_fragment_ops(ctx) ||	  !check_stencil_per_fragment_ops(ctx))	 return GL_FALSE;      break;#endif   case GL_DEPTH_COMPONENT:      dest = mmesa->mgaScreen->depthOffset;      if (ctx->Visual.depthBits == 24)	 planemask = ~0xff;      else	 planemask = ~0;      if (!check_depth(ctx, type, unpack, pixels, size, pitch) ||	  !check_depth_per_fragment_ops(ctx))	 return GL_FALSE;      break;   case GL_RGB:   case GL_BGRA:      dest = (mmesa->draw_buffer == MGA_FRONT ?	      mmesa->mgaScreen->frontOffset :	      mmesa->mgaScreen->backOffset);      planemask = mgaPackColor(cpp,			       ctx->Color.ColorMask[RCOMP],			       ctx->Color.ColorMask[GCOMP],			       ctx->Color.ColorMask[BCOMP],			       ctx->Color.ColorMask[ACOMP]);      if (cpp == 2)	 planemask |= planemask << 16;      if (!check_color(ctx, type, format, unpack, pixels, size, pitch)) {	 return GL_FALSE;      }      if (!check_color_per_fragment_ops(ctx)) {	 return GL_FALSE;      }      break;   default:      return GL_FALSE;   }   LOCK_HARDWARE_QUIESCENT( mmesa );   if (mmesa->dirty_cliprects & MGA_FRONT)      mgaUpdateRects( mmesa, MGA_FRONT );   if ( IS_AGP_MEM(mmesa, (char *)pixels) &&	IS_AGP_MEM(mmesa, (char *)pixels + size) )   {      do_draw_pix( ctx, x, y, width, height, pitch, pixels,		   dest, planemask );      UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT );   }   else   {      /* Pixels is in regular memory -- get dma buffers and perform       * upload through them.       *//*        drmBufPtr buf = mgaGetBufferLocked(mmesa); */      GLuint bufferpitch = (width*cpp+31)&~31;      char *address = 0; /*  mmesa->mgaScreen->agp.map; */      do {/*  	 GLuint rows = MIN2( height, MGA_DMA_BUF_SZ / bufferpitch ); */	 GLuint rows = height;	 if (0) fprintf(stderr, "trying to upload %d rows (pitch %d)\n",			rows, bufferpitch);	 /* The texture conversion code is so slow that there is only	  * negligble speedup when the buffers/images don't exactly	  * match:	  */#if 0	 if (cpp == 2) {	    if (!_mesa_convert_texsubimage2d( MESA_FORMAT_RGB565,					      0, 0, width, rows,					      bufferpitch, format, type,					      unpack, pixels, address )) {/*  	       mgaReleaseBufLocked( mmesa, buf ); */	       UNLOCK_HARDWARE(mmesa);	       return GL_FALSE;	    }	 } else {	    if (!_mesa_convert_texsubimage2d( MESA_FORMAT_ARGB8888,					      0, 0, width, rows,					      bufferpitch, format, type,					      unpack, pixels, address )) {/*  	       mgaReleaseBufLocked( mmesa, buf ); */	       UNLOCK_HARDWARE(mmesa);	       return GL_FALSE;	    }	 }#else	 MEMCPY( address, pixels, rows*bufferpitch );#endif	 do_draw_pix( ctx, x, y, width, rows,		      bufferpitch/cpp, address, dest, planemask );	 /* Fix me -- use multiple buffers to avoid flush.	  */	 UPDATE_LOCK( mmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT );	 pixels = (void *)((char *) pixels + rows * pitch);	 height -= rows;	 y += rows;      } while (height);/*        mgaReleaseBufLocked( mmesa, buf ); */   }   UNLOCK_HARDWARE( mmesa );   mmesa->dirty |= MGA_UPLOAD_CLIPRECTS;   return GL_TRUE;}static voidmgaDDDrawPixels( GLcontext *ctx,		 GLint x, GLint y, GLsizei width, GLsizei height,		 GLenum format, GLenum type,		 const struct gl_pixelstore_attrib *unpack,		 const GLvoid *pixels ){   if (!mgaTryDrawPixels( ctx, x, y, width, height, format, type,			  unpack, pixels ))      _swrast_DrawPixels( ctx, x, y, width, height, format, type,			  unpack, pixels );}#endif/* Stub functions - not a real allocator, always returns pointer to * the same block of agp space which isn't used for anything else at * present. */void mgaDDInitPixelFuncs( GLcontext *ctx ){#if 0   /* evidently, these functions don't always work */   if (getenv("MGA_BLIT_PIXELS")) {      ctx->Driver.ReadPixels = mgaDDReadPixels; /* requires agp dest */      ctx->Driver.DrawPixels = mgaDDDrawPixels; /* works with agp/normal mem */   }#endif}

⌨️ 快捷键说明

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