diff options
author | marha <marha@users.sourceforge.net> | 2011-12-25 17:27:22 +0100 |
---|---|---|
committer | Marc Haesen <marc@hc-consult.be> | 2011-12-25 17:27:22 +0100 |
commit | 0fd2d56b0fc0ce74c5f3e5e23cb26b0d1a075ba1 (patch) | |
tree | d449668fac922e358f442aeb82d0936ca786ed72 /mesalib/src/mesa/swrast/s_copypix.c | |
parent | 0b3f475361d87764004432f541e34bb86af1b9f3 (diff) | |
download | vcxsrv-0fd2d56b0fc0ce74c5f3e5e23cb26b0d1a075ba1.tar.gz vcxsrv-0fd2d56b0fc0ce74c5f3e5e23cb26b0d1a075ba1.tar.bz2 vcxsrv-0fd2d56b0fc0ce74c5f3e5e23cb26b0d1a075ba1.zip |
mesa xkeyboard-config xserver git update 25 dec 2011
Diffstat (limited to 'mesalib/src/mesa/swrast/s_copypix.c')
-rw-r--r-- | mesalib/src/mesa/swrast/s_copypix.c | 338 |
1 files changed, 111 insertions, 227 deletions
diff --git a/mesalib/src/mesa/swrast/s_copypix.c b/mesalib/src/mesa/swrast/s_copypix.c index 3bdf48b25..1dc4286a3 100644 --- a/mesalib/src/mesa/swrast/s_copypix.c +++ b/mesalib/src/mesa/swrast/s_copypix.c @@ -245,7 +245,7 @@ copy_depth_pixels( struct gl_context *ctx, GLint srcx, GLint srcy, GLint destx, GLint desty ) { struct gl_framebuffer *fb = ctx->ReadBuffer; - struct gl_renderbuffer *readRb = fb->_DepthBuffer; + struct gl_renderbuffer *readRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; GLfloat *p, *tmpImage; GLint sy, dy, stepy; GLint j; @@ -339,7 +339,7 @@ copy_stencil_pixels( struct gl_context *ctx, GLint srcx, GLint srcy, GLint destx, GLint desty ) { struct gl_framebuffer *fb = ctx->ReadBuffer; - struct gl_renderbuffer *rb = fb->_StencilBuffer; + struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; GLint sy, dy, stepy; GLint j; GLubyte *p, *tmpImage; @@ -422,184 +422,8 @@ copy_stencil_pixels( struct gl_context *ctx, GLint srcx, GLint srcy, /** - * This isn't terribly efficient. If a driver really has combined - * depth/stencil buffers the driver should implement an optimized - * CopyPixels function. - */ -static void -copy_depth_stencil_pixels(struct gl_context *ctx, - const GLint srcX, const GLint srcY, - const GLint width, const GLint height, - const GLint destX, const GLint destY) -{ - struct gl_renderbuffer *stencilReadRb, *depthReadRb, *depthDrawRb; - GLint sy, dy, stepy; - GLint j; - GLubyte *tempStencilImage = NULL, *stencilPtr = NULL; - GLfloat *tempDepthImage = NULL, *depthPtr = NULL; - const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF; - const GLuint stencilMask = ctx->Stencil.WriteMask[0]; - const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F; - const GLboolean scaleOrBias - = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0; - GLint overlapping; - - depthDrawRb = ctx->DrawBuffer->_DepthBuffer; - depthReadRb = ctx->ReadBuffer->_DepthBuffer; - stencilReadRb = ctx->ReadBuffer->_StencilBuffer; - - ASSERT(depthDrawRb); - ASSERT(depthReadRb); - ASSERT(stencilReadRb); - - if (ctx->DrawBuffer == ctx->ReadBuffer) { - overlapping = regions_overlap(srcX, srcY, destX, destY, width, height, - ctx->Pixel.ZoomX, ctx->Pixel.ZoomY); - } - else { - overlapping = GL_FALSE; - } - - /* Determine if copy should be bottom-to-top or top-to-bottom */ - if (!overlapping && srcY < destY) { - /* top-down max-to-min */ - sy = srcY + height - 1; - dy = destY + height - 1; - stepy = -1; - } - else { - /* bottom-up min-to-max */ - sy = srcY; - dy = destY; - stepy = 1; - } - - if (overlapping) { - GLint ssy = sy; - - if (stencilMask != 0x0) { - tempStencilImage - = (GLubyte *) malloc(width * height * sizeof(GLubyte)); - if (!tempStencilImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels"); - return; - } - - /* get copy of stencil pixels */ - stencilPtr = tempStencilImage; - for (j = 0; j < height; j++, ssy += stepy) { - _swrast_read_stencil_span(ctx, stencilReadRb, - width, srcX, ssy, stencilPtr); - stencilPtr += width; - } - stencilPtr = tempStencilImage; - } - - if (ctx->Depth.Mask) { - tempDepthImage - = (GLfloat *) malloc(width * height * sizeof(GLfloat)); - if (!tempDepthImage) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels"); - free(tempStencilImage); - return; - } - - /* get copy of depth pixels */ - depthPtr = tempDepthImage; - for (j = 0; j < height; j++, ssy += stepy) { - _swrast_read_depth_span_float(ctx, depthReadRb, - width, srcX, ssy, depthPtr); - depthPtr += width; - } - depthPtr = tempDepthImage; - } - } - - for (j = 0; j < height; j++, sy += stepy, dy += stepy) { - if (stencilMask != 0x0) { - GLubyte stencil[MAX_WIDTH]; - - /* Get stencil values */ - if (overlapping) { - memcpy(stencil, stencilPtr, width * sizeof(GLubyte)); - stencilPtr += width; - } - else { - _swrast_read_stencil_span(ctx, stencilReadRb, - width, srcX, sy, stencil); - } - - _mesa_apply_stencil_transfer_ops(ctx, width, stencil); - - /* Write values */ - if (zoom) { - _swrast_write_zoomed_stencil_span(ctx, destX, destY, width, - destX, dy, stencil); - } - else { - _swrast_write_stencil_span( ctx, width, destX, dy, stencil ); - } - } - - if (ctx->Depth.Mask) { - GLfloat depth[MAX_WIDTH]; - GLuint zVals32[MAX_WIDTH]; - GLushort zVals16[MAX_WIDTH]; - GLvoid *zVals; - GLuint zBytes; - - /* get depth values */ - if (overlapping) { - memcpy(depth, depthPtr, width * sizeof(GLfloat)); - depthPtr += width; - } - else { - _swrast_read_depth_span_float(ctx, depthReadRb, - width, srcX, sy, depth); - } - - /* scale & bias */ - if (scaleOrBias) { - _mesa_scale_and_bias_depth(ctx, width, depth); - } - /* convert to integer Z values */ - if (depthDrawRb->DataType == GL_UNSIGNED_SHORT) { - GLint k; - for (k = 0; k < width; k++) - zVals16[k] = (GLushort) (depth[k] * depthScale); - zVals = zVals16; - zBytes = 2; - } - else { - GLint k; - for (k = 0; k < width; k++) - zVals32[k] = (GLuint) (depth[k] * depthScale); - zVals = zVals32; - zBytes = 4; - } - - /* Write values */ - if (zoom) { - _swrast_write_zoomed_z_span(ctx, destX, destY, width, - destX, dy, zVals); - } - else { - _swrast_put_row(ctx, depthDrawRb, width, destX, dy, zVals, zBytes); - } - } - } - - if (tempStencilImage) - free(tempStencilImage); - - if (tempDepthImage) - free(tempDepthImage); -} - - - -/** - * Try to do a fast copy pixels. + * Try to do a fast copy pixels with memcpy. + * \return GL_TRUE if successful, GL_FALSE otherwise. */ static GLboolean fast_copy_pixels(struct gl_context *ctx, @@ -609,8 +433,10 @@ fast_copy_pixels(struct gl_context *ctx, struct gl_framebuffer *srcFb = ctx->ReadBuffer; struct gl_framebuffer *dstFb = ctx->DrawBuffer; struct gl_renderbuffer *srcRb, *dstRb; - GLint row, yStep; - void *temp; + GLint row; + GLuint pixelBytes, widthInBytes; + GLubyte *srcMap, *dstMap; + GLint srcRowStride, dstRowStride; if (SWRAST_CONTEXT(ctx)->_RasterMask != 0x0 || ctx->Pixel.ZoomX != 1.0F || @@ -627,12 +453,12 @@ fast_copy_pixels(struct gl_context *ctx, dstRb = dstFb->_ColorDrawBuffers[0]; } else if (type == GL_STENCIL) { - srcRb = srcFb->_StencilBuffer; - dstRb = dstFb->_StencilBuffer; + srcRb = srcFb->Attachment[BUFFER_STENCIL].Renderbuffer; + dstRb = dstFb->Attachment[BUFFER_STENCIL].Renderbuffer; } else if (type == GL_DEPTH) { - srcRb = srcFb->_DepthBuffer; - dstRb = dstFb->_DepthBuffer; + srcRb = srcFb->Attachment[BUFFER_DEPTH].Renderbuffer; + dstRb = dstFb->Attachment[BUFFER_DEPTH].Renderbuffer; } else { ASSERT(type == GL_DEPTH_STENCIL_EXT); @@ -641,13 +467,24 @@ fast_copy_pixels(struct gl_context *ctx, dstRb = dstFb->Attachment[BUFFER_DEPTH].Renderbuffer; } - /* src and dst renderbuffers must be same format and type */ - if (!srcRb || !dstRb || - srcRb->DataType != dstRb->DataType || - srcRb->_BaseFormat != dstRb->_BaseFormat) { + /* src and dst renderbuffers must be same format */ + if (!srcRb || !dstRb || srcRb->Format != dstRb->Format) { return GL_FALSE; } + if (type == GL_STENCIL || type == GL_DEPTH_COMPONENT) { + /* can't handle packed depth+stencil here */ + if (_mesa_is_format_packed_depth_stencil(srcRb->Format) || + _mesa_is_format_packed_depth_stencil(dstRb->Format)) + return GL_FALSE; + } + else if (type == GL_DEPTH_STENCIL) { + /* can't handle separate depth/stencil buffers */ + if (srcRb != srcFb->Attachment[BUFFER_STENCIL].Renderbuffer || + dstRb != dstFb->Attachment[BUFFER_STENCIL].Renderbuffer) + return GL_FALSE; + } + /* clipping not supported */ if (srcX < 0 || srcX + width > (GLint) srcFb->Width || srcY < 0 || srcY + height > (GLint) srcFb->Height || @@ -656,32 +493,73 @@ fast_copy_pixels(struct gl_context *ctx, return GL_FALSE; } - /* overlapping src/dst doesn't matter, just determine Y direction */ - if (srcY < dstY) { - /* top-down max-to-min */ - srcY = srcY + height - 1; - dstY = dstY + height - 1; - yStep = -1; + pixelBytes = _mesa_get_format_bytes(srcRb->Format); + widthInBytes = width * pixelBytes; + + if (srcRb == dstRb) { + /* map whole buffer for read/write */ + /* XXX we could be clever and just map the union region of the + * source and dest rects. + */ + GLubyte *map; + GLint rowStride; + + ctx->Driver.MapRenderbuffer(ctx, srcRb, 0, 0, + srcRb->Width, srcRb->Height, + GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, + &map, &rowStride); + if (!srcMap) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels"); + return GL_TRUE; /* don't retry with slow path */ + } + + srcMap = map + srcY * rowStride + srcX * pixelBytes; + dstMap = map + dstY * rowStride + dstX * pixelBytes; + + /* this handles overlapping copies */ + if (srcY < dstY) { + /* copy in reverse (top->down) order */ + srcMap += rowStride * (height - 1); + dstMap += rowStride * (height - 1); + srcRowStride = -rowStride; + dstRowStride = -rowStride; + } + else { + /* copy in normal (bottom->up) order */ + srcRowStride = rowStride; + dstRowStride = rowStride; + } } else { - /* bottom-up min-to-max */ - yStep = 1; - } - - temp = malloc(width * MAX_PIXEL_BYTES); - if (!temp) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels"); - return GL_FALSE; + /* different src/dst buffers */ + ctx->Driver.MapRenderbuffer(ctx, srcRb, srcX, srcY, + width, height, + GL_MAP_READ_BIT, &srcMap, &srcRowStride); + if (!srcMap) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels"); + return GL_TRUE; /* don't retry with slow path */ + } + ctx->Driver.MapRenderbuffer(ctx, dstRb, dstX, dstY, + width, height, + GL_MAP_WRITE_BIT, &dstMap, &dstRowStride); + if (!dstMap) { + ctx->Driver.UnmapRenderbuffer(ctx, srcRb); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels"); + return GL_TRUE; /* don't retry with slow path */ + } } for (row = 0; row < height; row++) { - srcRb->GetRow(ctx, srcRb, width, srcX, srcY, temp); - dstRb->PutRow(ctx, dstRb, width, dstX, dstY, temp, NULL); - srcY += yStep; - dstY += yStep; + /* memmove() in case of overlap */ + memmove(dstMap, srcMap, widthInBytes); + dstMap += dstRowStride; + srcMap += srcRowStride; } - free(temp); + ctx->Driver.UnmapRenderbuffer(ctx, srcRb); + if (dstRb != srcRb) { + ctx->Driver.UnmapRenderbuffer(ctx, dstRb); + } return GL_TRUE; } @@ -697,7 +575,6 @@ _swrast_CopyPixels( struct gl_context *ctx, GLint destx, GLint desty, GLenum type ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); - swrast_render_start(ctx); if (!_mesa_check_conditional_render(ctx)) return; /* don't copy */ @@ -705,23 +582,30 @@ _swrast_CopyPixels( struct gl_context *ctx, if (swrast->NewState) _swrast_validate_derived( ctx ); - if (!fast_copy_pixels(ctx, srcx, srcy, width, height, destx, desty, type)) { - switch (type) { - case GL_COLOR: - copy_rgba_pixels( ctx, srcx, srcy, width, height, destx, desty ); - break; - case GL_DEPTH: - copy_depth_pixels( ctx, srcx, srcy, width, height, destx, desty ); - break; - case GL_STENCIL: - copy_stencil_pixels( ctx, srcx, srcy, width, height, destx, desty ); - break; - case GL_DEPTH_STENCIL_EXT: - copy_depth_stencil_pixels(ctx, srcx, srcy, width, height, destx, desty); - break; - default: - _mesa_problem(ctx, "unexpected type in _swrast_CopyPixels"); - } + if (fast_copy_pixels(ctx, srcx, srcy, width, height, destx, desty, type)) { + /* all done */ + return; + } + + swrast_render_start(ctx); + + switch (type) { + case GL_COLOR: + copy_rgba_pixels( ctx, srcx, srcy, width, height, destx, desty ); + break; + case GL_DEPTH: + copy_depth_pixels( ctx, srcx, srcy, width, height, destx, desty ); + break; + case GL_STENCIL: + copy_stencil_pixels( ctx, srcx, srcy, width, height, destx, desty ); + break; + case GL_DEPTH_STENCIL_EXT: + /* Copy buffers separately (if the fast copy path wasn't taken) */ + copy_depth_pixels(ctx, srcx, srcy, width, height, destx, desty); + copy_stencil_pixels(ctx, srcx, srcy, width, height, destx, desty); + break; + default: + _mesa_problem(ctx, "unexpected type in _swrast_CopyPixels"); } swrast_render_finish(ctx); |