diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-01 04:39:23 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-01 04:39:23 +0000 |
commit | ad627cde795ce0f294e37f8c83aa2d5101b43711 (patch) | |
tree | 0407f1ec19b178632fb9a25310e414130964a2ce /gpu | |
parent | 3b8ce3ec290af2f0e6a3b2d33f12ce23aec5cb3e (diff) | |
download | chromium_src-ad627cde795ce0f294e37f8c83aa2d5101b43711.zip chromium_src-ad627cde795ce0f294e37f8c83aa2d5101b43711.tar.gz chromium_src-ad627cde795ce0f294e37f8c83aa2d5101b43711.tar.bz2 |
Fixes client side of readpixels so it doesn't write
pad bytes.
Am working on framework for unit tests for the client
side but it still needs work so tested this in the
debugger by hand for now.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/1578006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/client/gles2_implementation.cc | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 99938d5..4eb6577 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -640,8 +640,6 @@ void GLES2Implementation::GetUniformiv( void GLES2Implementation::ReadPixels( GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels) { - // Note: Negative widths and heights are not handled here but are handled - // by the service side so the glGetError wrapping works. if (width < 0 || height < 0) { SetGLError(GL_INVALID_VALUE); return; @@ -649,6 +647,13 @@ void GLES2Implementation::ReadPixels( if (width == 0 || height == 0) { return; } + + // glReadPixel pads the size of each row of pixels by an ammount specified by + // glPixelStorei. So, we have to take that into account both in the fact that + // the pixels returned from the ReadPixel command will include that padding + // and that when we copy the results to the user's buffer we need to not + // write those padding bytes but leave them as they are. + typedef gles2::ReadPixels::Result Result; Result* result = static_cast<Result*>(result_buffer_); int8* dest = reinterpret_cast<int8*>(pixels); @@ -670,12 +675,18 @@ void GLES2Implementation::ReadPixels( SetGLError(GL_INVALID_VALUE); return; } + // Check if we have enough space to transfer at least an entire row. if (padded_row_size <= max_size) { // Transfer by rows. + // The max rows we can transfer. GLint max_rows = max_size / padded_row_size; while (height) { + // Compute how many rows to transfer. GLint num_rows = std::min(height, max_rows); - GLsizeiptr part_size = num_rows * padded_row_size; + // Compute how much space those rows will take. The last row will not + // include padding. + GLsizeiptr part_size = + unpadded_row_size + (padded_row_size * std::max(num_rows - 1, 0)); void* buffer = transfer_buffer_.Alloc(part_size); *result = 0; // mark as failed. helper_->ReadPixels( @@ -687,10 +698,15 @@ void GLES2Implementation::ReadPixels( if (*result == 0) { return; } - memcpy(dest, buffer, part_size); + // We have to copy 1 row at a time to avoid writing pad bytes. + const int8* src = static_cast<const int8*>(buffer); + for (GLint yy = 0; yy < num_rows; ++yy) { + memcpy(dest, src, unpadded_row_size); + dest += padded_row_size; + src += padded_row_size; + } transfer_buffer_.Free(buffer); yoffset += num_rows; - dest += part_size; height -= num_rows; } } else { |