📄 r128_ioctl.c
字号:
if ( R128_DEBUG & DEBUG_VERBOSE_API ) { fprintf( stderr, "%s:\n", __FUNCTION__ ); } FLUSH_BATCH( rmesa ); /* The only state change we care about here is the RGBA colormask * We'll just update that state, if needed. If we do more then * there's some strange side-effects that the conformance tests find. */ if ( rmesa->new_state & R128_NEW_MASKS) { const GLuint save_state = rmesa->new_state; rmesa->new_state = R128_NEW_MASKS; r128DDUpdateHWState( ctx ); rmesa->new_state = save_state & ~R128_NEW_MASKS; } if ( mask & BUFFER_BIT_FRONT_LEFT ) { flags |= R128_FRONT; mask &= ~BUFFER_BIT_FRONT_LEFT; } if ( mask & BUFFER_BIT_BACK_LEFT ) { flags |= R128_BACK; mask &= ~BUFFER_BIT_BACK_LEFT; } if ( ( mask & BUFFER_BIT_DEPTH ) && ctx->Depth.Mask ) { flags |= R128_DEPTH; /* if we're at 16 bits, extra plane mask won't hurt */ depthmask |= 0x00ffffff; mask &= ~BUFFER_BIT_DEPTH; } if ( mask & BUFFER_BIT_STENCIL && (ctx->Visual.stencilBits > 0 && ctx->Visual.depthBits == 24) ) { flags |= R128_DEPTH; depthmask |= ctx->Stencil.WriteMask[0] << 24; mask &= ~BUFFER_BIT_STENCIL; } if ( flags ) { LOCK_HARDWARE( rmesa ); /* compute region after locking: */ cx = ctx->DrawBuffer->_Xmin; cy = ctx->DrawBuffer->_Ymin; cw = ctx->DrawBuffer->_Xmax - cx; ch = ctx->DrawBuffer->_Ymax - cy; /* Flip top to bottom */ cx += dPriv->x; cy = dPriv->y + dPriv->h - cy - ch; /* FIXME: Do we actually need this? */ if ( rmesa->dirty & ~R128_UPLOAD_CLIPRECTS ) { r128EmitHwStateLocked( rmesa ); } for ( i = 0 ; i < rmesa->numClipRects ; ) { GLint nr = MIN2( i + R128_NR_SAREA_CLIPRECTS , rmesa->numClipRects ); drm_clip_rect_t *box = rmesa->pClipRects; drm_clip_rect_t *b = rmesa->sarea->boxes; GLint n = 0; if (cw != dPriv->w || ch != dPriv->h) { /* clear subregion */ for ( ; i < nr ; i++ ) { GLint x = box[i].x1; GLint y = box[i].y1; GLint w = box[i].x2 - x; GLint h = box[i].y2 - y; if ( x < cx ) w -= cx - x, x = cx; if ( y < cy ) h -= cy - y, y = cy; if ( x + w > cx + cw ) w = cx + cw - x; if ( y + h > cy + ch ) h = cy + ch - y; if ( w <= 0 ) continue; if ( h <= 0 ) continue; b->x1 = x; b->y1 = y; b->x2 = x + w; b->y2 = y + h; b++; n++; } } else { /* clear whole window */ for ( ; i < nr ; i++ ) { *b++ = box[i]; n++; } } rmesa->sarea->nbox = n; if ( R128_DEBUG & DEBUG_VERBOSE_IOCTL ) { fprintf( stderr, "DRM_R128_CLEAR: flag 0x%x color %x depth %x nbox %d\n", flags, (GLuint)rmesa->ClearColor, (GLuint)rmesa->ClearDepth, rmesa->sarea->nbox ); } clear.flags = flags; clear.clear_color = rmesa->ClearColor; clear.clear_depth = rmesa->ClearDepth; clear.color_mask = rmesa->setup.plane_3d_mask_c; clear.depth_mask = depthmask; ret = drmCommandWrite( rmesa->driFd, DRM_R128_CLEAR, &clear, sizeof(clear) ); if ( ret ) { UNLOCK_HARDWARE( rmesa ); fprintf( stderr, "DRM_R128_CLEAR: return = %d\n", ret ); exit( 1 ); } } UNLOCK_HARDWARE( rmesa ); rmesa->dirty |= R128_UPLOAD_CLIPRECTS; } if ( mask ) _swrast_Clear( ctx, mask );}/* ================================================================ * Depth spans, pixels */void r128WriteDepthSpanLocked( r128ContextPtr rmesa, GLuint n, GLint x, GLint y, const GLuint depth[], const GLubyte mask[] ){ drm_clip_rect_t *pbox = rmesa->pClipRects; drm_r128_depth_t d; int nbox = rmesa->numClipRects; int fd = rmesa->driScreen->fd; int i; if ( !nbox || !n ) { return; } if ( nbox >= R128_NR_SAREA_CLIPRECTS ) { rmesa->dirty |= R128_UPLOAD_CLIPRECTS; } if ( !(rmesa->dirty & R128_UPLOAD_CLIPRECTS) ) { if ( nbox < 3 ) { rmesa->sarea->nbox = 0; } else { rmesa->sarea->nbox = nbox; } d.func = R128_WRITE_SPAN; d.n = n; d.x = (int*)&x; d.y = (int*)&y; d.buffer = (unsigned int *)depth; d.mask = (unsigned char *)mask; drmCommandWrite( fd, DRM_R128_DEPTH, &d, sizeof(d)); } else { for (i = 0 ; i < nbox ; ) { int nr = MIN2( i + R128_NR_SAREA_CLIPRECTS, nbox ); drm_clip_rect_t *b = rmesa->sarea->boxes; rmesa->sarea->nbox = nr - i; for ( ; i < nr ; i++) { *b++ = pbox[i]; } rmesa->sarea->dirty |= R128_UPLOAD_CLIPRECTS; d.func = R128_WRITE_SPAN; d.n = n; d.x = (int*)&x; d.y = (int*)&y; d.buffer = (unsigned int *)depth; d.mask = (unsigned char *)mask; drmCommandWrite( fd, DRM_R128_DEPTH, &d, sizeof(d)); } } rmesa->dirty &= ~R128_UPLOAD_CLIPRECTS;}void r128WriteDepthPixelsLocked( r128ContextPtr rmesa, GLuint n, const GLint x[], const GLint y[], const GLuint depth[], const GLubyte mask[] ){ drm_clip_rect_t *pbox = rmesa->pClipRects; drm_r128_depth_t d; int nbox = rmesa->numClipRects; int fd = rmesa->driScreen->fd; int i; if ( !nbox || !n ) { return; } if ( nbox >= R128_NR_SAREA_CLIPRECTS ) { rmesa->dirty |= R128_UPLOAD_CLIPRECTS; } if ( !(rmesa->dirty & R128_UPLOAD_CLIPRECTS) ) { if ( nbox < 3 ) { rmesa->sarea->nbox = 0; } else { rmesa->sarea->nbox = nbox; } d.func = R128_WRITE_PIXELS; d.n = n; d.x = (int*)&x; d.y = (int*)&y; d.buffer = (unsigned int *)depth; d.mask = (unsigned char *)mask; drmCommandWrite( fd, DRM_R128_DEPTH, &d, sizeof(d)); } else { for (i = 0 ; i < nbox ; ) { int nr = MIN2( i + R128_NR_SAREA_CLIPRECTS, nbox ); drm_clip_rect_t *b = rmesa->sarea->boxes; rmesa->sarea->nbox = nr - i; for ( ; i < nr ; i++) { *b++ = pbox[i]; } rmesa->sarea->dirty |= R128_UPLOAD_CLIPRECTS; d.func = R128_WRITE_PIXELS; d.n = n; d.x = (int*)&x; d.y = (int*)&y; d.buffer = (unsigned int *)depth; d.mask = (unsigned char *)mask; drmCommandWrite( fd, DRM_R128_DEPTH, &d, sizeof(d)); } } rmesa->dirty &= ~R128_UPLOAD_CLIPRECTS;}void r128ReadDepthSpanLocked( r128ContextPtr rmesa, GLuint n, GLint x, GLint y ){ drm_clip_rect_t *pbox = rmesa->pClipRects; drm_r128_depth_t d; int nbox = rmesa->numClipRects; int fd = rmesa->driScreen->fd; int i; if ( !nbox || !n ) { return; } if ( nbox >= R128_NR_SAREA_CLIPRECTS ) { rmesa->dirty |= R128_UPLOAD_CLIPRECTS; } if ( !(rmesa->dirty & R128_UPLOAD_CLIPRECTS) ) { if ( nbox < 3 ) { rmesa->sarea->nbox = 0; } else { rmesa->sarea->nbox = nbox; } d.func = R128_READ_SPAN; d.n = n; d.x = (int*)&x; d.y = (int*)&y; d.buffer = NULL; d.mask = NULL; drmCommandWrite( fd, DRM_R128_DEPTH, &d, sizeof(d)); } else { for (i = 0 ; i < nbox ; ) { int nr = MIN2( i + R128_NR_SAREA_CLIPRECTS, nbox ); drm_clip_rect_t *b = rmesa->sarea->boxes; rmesa->sarea->nbox = nr - i; for ( ; i < nr ; i++) { *b++ = pbox[i]; } rmesa->sarea->dirty |= R128_UPLOAD_CLIPRECTS; d.func = R128_READ_SPAN; d.n = n; d.x = (int*)&x; d.y = (int*)&y; d.buffer = NULL; d.mask = NULL; drmCommandWrite( fd, DRM_R128_DEPTH, &d, sizeof(d)); } } rmesa->dirty &= ~R128_UPLOAD_CLIPRECTS;}void r128ReadDepthPixelsLocked( r128ContextPtr rmesa, GLuint n, const GLint x[], const GLint y[] ){ drm_clip_rect_t *pbox = rmesa->pClipRects; drm_r128_depth_t d; int nbox = rmesa->numClipRects; int fd = rmesa->driScreen->fd; int i; if ( !nbox || !n ) { return; } if ( nbox >= R128_NR_SAREA_CLIPRECTS ) { rmesa->dirty |= R128_UPLOAD_CLIPRECTS; } if ( !(rmesa->dirty & R128_UPLOAD_CLIPRECTS) ) { if ( nbox < 3 ) { rmesa->sarea->nbox = 0; } else { rmesa->sarea->nbox = nbox; } d.func = R128_READ_PIXELS; d.n = n; d.x = (int*)&x; d.y = (int*)&y; d.buffer = NULL; d.mask = NULL; drmCommandWrite( fd, DRM_R128_DEPTH, &d, sizeof(d)); } else { for (i = 0 ; i < nbox ; ) { int nr = MIN2( i + R128_NR_SAREA_CLIPRECTS, nbox ); drm_clip_rect_t *b = rmesa->sarea->boxes; rmesa->sarea->nbox = nr - i; for ( ; i < nr ; i++) { *b++ = pbox[i]; } rmesa->sarea->dirty |= R128_UPLOAD_CLIPRECTS; d.func = R128_READ_PIXELS; d.n = n; d.x = (int*)&x; d.y = (int*)&y; d.buffer = NULL; d.mask = NULL; drmCommandWrite( fd, DRM_R128_DEPTH, &d, sizeof(d)); } } rmesa->dirty &= ~R128_UPLOAD_CLIPRECTS;}void r128WaitForIdleLocked( r128ContextPtr rmesa ){ int fd = rmesa->r128Screen->driScreen->fd; int to = 0; int ret, i; do { i = 0; do { ret = drmCommandNone( fd, DRM_R128_CCE_IDLE); } while ( ret && errno == EBUSY && i++ < R128_IDLE_RETRY ); } while ( ( ret == -EBUSY ) && ( to++ < R128_TIMEOUT ) ); if ( ret < 0 ) { drmCommandNone( fd, DRM_R128_CCE_RESET); UNLOCK_HARDWARE( rmesa ); fprintf( stderr, "Error: Rage 128 timed out... exiting\n" ); exit( -1 ); }}void r128InitIoctlFuncs( struct dd_function_table *functions ){ functions->Clear = r128Clear;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -