Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Unified Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 1320093002: Command Buffer: read pixels into pixel pack buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed zmo@'s feedback Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1104675680d041555534b934c984b3c8902b89e7 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -9175,23 +9175,48 @@ 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,
Zhenyao Mo 2015/12/16 23:09:21 Sorry just realized this is incorrect. You should
yunchao 2015/12/17 08:12:59 Done.
+ params, &pixels_size, nullptr, nullptr, nullptr)) {
return error::kOutOfBounds;
}
- void* pixels = GetSharedMemoryAs<void*>(
- c.pixels_shm_id, c.pixels_shm_offset, pixels_size);
- if (!pixels) {
- return error::kOutOfBounds;
+
+ void* pixels = nullptr;
+ 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;
+ }
+ uint32 size = 0;
+ if (!SafeAddUint32(pixels_size, c.pixels_shm_offset, &size)) {
+ LOCAL_SET_GL_ERROR(
+ GL_INVALID_VALUE, "glReadPixels", "size + offset overflow");
+ return error::kNoError;
+ }
+ if (buffer->size() < static_cast<int>(size)) {
Zhenyao Mo 2015/12/16 18:12:34 You should cast int to uint32 for comparison here.
yunchao 2015/12/17 08:12:59 Done.
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels",
+ "pixel pack buffer is not large enough");
+ return error::kNoError;
+ }
+ pixels = reinterpret_cast<void *>(c.pixels_shm_offset);
+ } else {
+ return error::kInvalidArguments;
+ }
+ } else {
+ if (buffer) {
+ return error::kInvalidArguments;
+ } 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*>(
@@ -9327,6 +9352,13 @@ 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()) {
+ // TODO(yunchao): need to handle the out-of-bounds case for reading pixels
+ // into PIXEL_PACK buffer.
+ if (c.pixels_shm_id == 0) {
+ LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels",
+ "read pixels out of bounds into PIXEL_PACK buffer");
+ return error::kNoError;
+ }
// The user requested an out of range area. Get the results 1 line
// at a time.
uint32 temp_size;
@@ -9402,12 +9434,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;
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698