int r200FlushCmdBufLocked( r200ContextPtr rmesa, const char * caller ) { int ret, i; drm_radeon_cmd_buffer_t cmd; if (rmesa->lost_context) r200BackUpAndEmitLostStateLocked( rmesa ); if (R200_DEBUG & DEBUG_IOCTL) { fprintf(stderr, "%s from %s\n", __FUNCTION__, caller); if (0 & R200_DEBUG & DEBUG_VERBOSE) for (i = 0 ; i < rmesa->store.cmd_used ; i += 4 ) fprintf(stderr, "%d: %x\n", i/4, *(int *)(&rmesa->store.cmd_buf[i])); } if (R200_DEBUG & DEBUG_DMA) fprintf(stderr, "%s: Releasing %d buffers\n", __FUNCTION__, rmesa->dma.nr_released_bufs); if (R200_DEBUG & DEBUG_SANITY) { if (rmesa->state.scissor.enabled) ret = r200SanityCmdBuffer( rmesa, rmesa->state.scissor.numClipRects, rmesa->state.scissor.pClipRects); else ret = r200SanityCmdBuffer( rmesa, rmesa->numClipRects, rmesa->pClipRects); if (ret) { fprintf(stderr, "drmSanityCommandWrite: %d\n", ret); goto out; } } if (R200_DEBUG & DEBUG_MEMORY) { if (! driValidateTextureHeaps( rmesa->texture_heaps, rmesa->nr_heaps, & rmesa->swapped ) ) { fprintf( stderr, "%s: texture memory is inconsistent - expect " "mangled textures\n", __FUNCTION__ ); } } cmd.bufsz = rmesa->store.cmd_used; cmd.buf = rmesa->store.cmd_buf; if (rmesa->state.scissor.enabled) { cmd.nbox = rmesa->state.scissor.numClipRects; cmd.boxes = (drm_clip_rect_t *)rmesa->state.scissor.pClipRects; } else { cmd.nbox = rmesa->numClipRects; cmd.boxes = (drm_clip_rect_t *)rmesa->pClipRects; } ret = drmCommandWrite( rmesa->dri.fd, DRM_RADEON_CMDBUF, &cmd, sizeof(cmd) ); if (ret) fprintf(stderr, "drmCommandWrite: %d\n", ret); if (R200_DEBUG & DEBUG_SYNC) { fprintf(stderr, "\nSyncing in %s\n\n", __FUNCTION__); r200WaitForIdleLocked( rmesa ); } out: rmesa->store.primnr = 0; rmesa->store.statenr = 0; rmesa->store.cmd_used = 0; rmesa->dma.nr_released_bufs = 0; rmesa->save_on_next_emit = 1; return ret; }
static void do_draw_pix( GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLint pitch, const void *pixels, GLuint planemask) { r200ContextPtr rmesa = R200_CONTEXT(ctx); __DRIdrawablePrivate *dPriv = rmesa->dri.drawable; drm_clip_rect_t *box = dPriv->pClipRects; struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorDrawBuffers[0][0]; driRenderbuffer *drb = (driRenderbuffer *) rb; int nbox = dPriv->numClipRects; int i; int blit_format; int size; int src_offset = r200GartOffsetFromVirtual( rmesa, pixels ); int src_pitch = pitch * rmesa->r200Screen->cpp; if (R200_DEBUG & DEBUG_PIXEL) fprintf(stderr, "%s\n", __FUNCTION__); switch ( rmesa->r200Screen->cpp ) { case 2: blit_format = R200_CP_COLOR_FORMAT_RGB565; break; case 4: blit_format = R200_CP_COLOR_FORMAT_ARGB8888; break; default: return; } LOCK_HARDWARE( rmesa ); if (rmesa->store.cmd_used) r200FlushCmdBufLocked( rmesa, __FUNCTION__ ); y -= height; /* cope with pixel zoom */ if (!clip_pixelrect(ctx, ctx->DrawBuffer, &x, &y, &width, &height, &size)) { UNLOCK_HARDWARE( rmesa ); return; } y = dPriv->h - y - height; /* convert from gl to hardware coords */ x += dPriv->x; y += dPriv->y; r200EmitWait( rmesa, RADEON_WAIT_3D ); for (i = 0 ; i < nbox ; 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; r200EmitBlit( rmesa, blit_format, src_pitch, src_offset, drb->pitch * drb->cpp, drb->offset + rmesa->r200Screen->fbLocation, bx - x, by - y, bx, by, bw, bh ); } r200FlushCmdBufLocked( rmesa, __FUNCTION__ ); r200WaitForIdleLocked( rmesa ); /* required by GL */ UNLOCK_HARDWARE( rmesa ); }
static void r200WaitForIdle( r200ContextPtr rmesa ) { LOCK_HARDWARE(rmesa); r200WaitForIdleLocked( rmesa ); UNLOCK_HARDWARE(rmesa); }