Chromium Code Reviews| Index: gpu/command_buffer/service/gles2_cmd_decoder.cc |
| diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| index e8bbe5885459434f3dff96c195f981ae1b6ee30d..8c74b02f61ca5ff19c83d816986ee3ec7e3e5e61 100644 |
| --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| @@ -9175,23 +9175,49 @@ error::Error GLES2DecoderImpl::HandleReadPixels(uint32 immediate_data_size, |
| } |
| typedef cmds::ReadPixels::Result Result; |
| uint32 pixels_size; |
| - if (state_.bound_pixel_pack_buffer.get()) { |
| - // TODO(zmo): Need to handle the case of reading into a PIXEL_PACK_BUFFER |
| - // in ES3, including more pack parameters. For now, generate a GL error. |
| - LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", |
| - "ReadPixels to a pixel pack buffer isn't implemented"); |
| - return error::kNoError; |
| - } |
| - if (!GLES2Util::ComputeImageDataSizes( |
| - width, height, 1, format, type, state_.pack_alignment, &pixels_size, |
| - NULL, NULL)) { |
| + PixelStoreParams params = state_.GetPackParams(); |
| + if (!GLES2Util::ComputeImageDataSizesES3( |
| + width, height, 1, format, type, params, &pixels_size, NULL, NULL, NULL)) { |
|
Zhenyao Mo
2015/12/15 23:50:56
nit: use nullptr instead.
yunchao
2015/12/16 11:04:25
Done.
|
| return error::kOutOfBounds; |
| } |
| - void* pixels = GetSharedMemoryAs<void*>( |
| - c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| - if (!pixels) { |
| - return error::kOutOfBounds; |
| + |
| + void* pixels = NULL; |
|
Zhenyao Mo
2015/12/15 23:50:56
nit: use nullptr instead.
yunchao
2015/12/16 11:04:25
Done.
|
| + Buffer* buffer = state_.bound_pixel_pack_buffer.get(); |
| + if (c.pixels_shm_id == 0) { |
| + if (buffer) { |
| + if (buffer->GetMappedRange()) { |
| + LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", |
| + "pixel pack buffer should not be mapped to client memory"); |
| + return error::kNoError; |
| + } |
| + if (buffer->size() < pixels_size) { |
| + LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", |
| + "pixel pack buffer is not large enough"); |
| + return error::kNoError; |
| + } |
| + if (c.pixels_shm_offset != 0) { |
| + return error::kInvalidArguments; |
| + } |
| + pixels = reinterpret_cast<void *>(0); |
|
Zhenyao Mo
2015/12/15 23:50:56
Here you will need to consider the offset paramete
yunchao
2015/12/16 11:04:25
Done.
|
| + } else { |
| + LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", |
|
Zhenyao Mo
2015/12/15 23:50:56
Here you should return error::kInvalidArguments. N
yunchao
2015/12/16 11:04:25
Done.
|
| + "no pixel pack buffer bound"); |
| + return error::kNoError; |
| + } |
| + } else { |
| + if (buffer) { |
| + LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", |
| + "pixel pack buffer should not bound"); |
|
Zhenyao Mo
2015/12/15 23:50:56
Here you should return error::kInvalidArguments. N
yunchao
2015/12/16 11:04:25
Done.
|
| + return error::kNoError; |
| + } else { |
| + pixels = GetSharedMemoryAs<void*>( |
| + c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| + if (!pixels) { |
| + return error::kOutOfBounds; |
| + } |
| + } |
| } |
| + |
| Result* result = NULL; |
| if (c.result_shm_id != 0) { |
| result = GetSharedMemoryAs<Result*>( |
| @@ -9326,7 +9352,8 @@ error::Error GLES2DecoderImpl::HandleReadPixels(uint32 immediate_data_size, |
| ScopedResolvedFrameBufferBinder binder(this, false, true); |
| - if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { |
| + if ((x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) |
| + && c.pixels_shm_id != 0) { |
|
Zhenyao Mo
2015/12/15 23:50:56
We do want to handle the out-of-bounds readPixels
yunchao
2015/12/16 11:04:25
Done.
|
| // The user requested an out of range area. Get the results 1 line |
| // at a time. |
| uint32 temp_size; |
| @@ -9402,12 +9429,14 @@ error::Error GLES2DecoderImpl::HandleReadPixels(uint32 immediate_data_size, |
| } |
| glReadPixels(x, y, width, height, format, type, pixels); |
| } |
| - GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
| - if (error == GL_NO_ERROR) { |
| - if (result != NULL) { |
| - *result = true; |
| + if (c.pixels_shm_id != 0) { |
| + GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
| + if (error == GL_NO_ERROR) { |
| + if (result != NULL) { |
| + *result = true; |
| + } |
| + FinishReadPixels(c, 0); |
| } |
| - FinishReadPixels(c, 0); |
| } |
| return error::kNoError; |