OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 9156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9167 GLsizei width = c.width; | 9167 GLsizei width = c.width; |
9168 GLsizei height = c.height; | 9168 GLsizei height = c.height; |
9169 GLenum format = c.format; | 9169 GLenum format = c.format; |
9170 GLenum type = c.type; | 9170 GLenum type = c.type; |
9171 GLboolean async = static_cast<GLboolean>(c.async); | 9171 GLboolean async = static_cast<GLboolean>(c.async); |
9172 if (width < 0 || height < 0) { | 9172 if (width < 0 || height < 0) { |
9173 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); | 9173 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
9174 return error::kNoError; | 9174 return error::kNoError; |
9175 } | 9175 } |
9176 typedef cmds::ReadPixels::Result Result; | 9176 typedef cmds::ReadPixels::Result Result; |
9177 uint32 pixels_size; | 9177 uint32 pixels_size = 0; |
9178 if (state_.bound_pixel_pack_buffer.get()) { | 9178 if (c.pixels_shm_id == 0) { |
9179 // TODO(zmo): Need to handle the case of reading into a PIXEL_PACK_BUFFER | 9179 PixelStoreParams params = state_.GetPackParams(); |
9180 // in ES3, including more pack parameters. For now, generate a GL error. | 9180 if (!GLES2Util::ComputeImageDataSizesES3(width, height, 1, format, type, |
9181 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | 9181 params, &pixels_size, nullptr, nullptr, nullptr)) { |
9182 "ReadPixels to a pixel pack buffer isn't implemented"); | 9182 return error::kOutOfBounds; |
9183 return error::kNoError; | 9183 } |
| 9184 } else { |
| 9185 // When reading into client buffer, we actually set pack parameters to 0 |
| 9186 // (except for alignment) before calling glReadPixels. This makes sure we |
| 9187 // only send back meaningful pixel data to the command buffer client side, |
| 9188 // and the client side will take the responsibility to take the pixels and |
| 9189 // write to the client buffer according to the full ES3 pack parameters. |
| 9190 if (!GLES2Util::ComputeImageDataSizes(width, height, 1, format, type, |
| 9191 state_.pack_alignment, &pixels_size, nullptr, nullptr)) { |
| 9192 return error::kOutOfBounds; |
| 9193 } |
9184 } | 9194 } |
9185 if (!GLES2Util::ComputeImageDataSizes( | 9195 |
9186 width, height, 1, format, type, state_.pack_alignment, &pixels_size, | 9196 void* pixels = nullptr; |
9187 NULL, NULL)) { | 9197 Buffer* buffer = state_.bound_pixel_pack_buffer.get(); |
9188 return error::kOutOfBounds; | 9198 if (c.pixels_shm_id == 0) { |
| 9199 if (buffer) { |
| 9200 if (buffer->GetMappedRange()) { |
| 9201 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", |
| 9202 "pixel pack buffer should not be mapped to client memory"); |
| 9203 return error::kNoError; |
| 9204 } |
| 9205 uint32 size = 0; |
| 9206 if (!SafeAddUint32(pixels_size, c.pixels_shm_offset, &size)) { |
| 9207 LOCAL_SET_GL_ERROR( |
| 9208 GL_INVALID_VALUE, "glReadPixels", "size + offset overflow"); |
| 9209 return error::kNoError; |
| 9210 } |
| 9211 if (static_cast<uint32>(buffer->size()) < size) { |
| 9212 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", |
| 9213 "pixel pack buffer is not large enough"); |
| 9214 return error::kNoError; |
| 9215 } |
| 9216 pixels = reinterpret_cast<void *>(c.pixels_shm_offset); |
| 9217 } else { |
| 9218 return error::kInvalidArguments; |
| 9219 } |
| 9220 } else { |
| 9221 if (buffer) { |
| 9222 return error::kInvalidArguments; |
| 9223 } else { |
| 9224 pixels = GetSharedMemoryAs<void*>( |
| 9225 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| 9226 if (!pixels) { |
| 9227 return error::kOutOfBounds; |
| 9228 } |
| 9229 } |
9189 } | 9230 } |
9190 void* pixels = GetSharedMemoryAs<void*>( | 9231 |
9191 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); | |
9192 if (!pixels) { | |
9193 return error::kOutOfBounds; | |
9194 } | |
9195 Result* result = NULL; | 9232 Result* result = NULL; |
9196 if (c.result_shm_id != 0) { | 9233 if (c.result_shm_id != 0) { |
9197 result = GetSharedMemoryAs<Result*>( | 9234 result = GetSharedMemoryAs<Result*>( |
9198 c.result_shm_id, c.result_shm_offset, sizeof(*result)); | 9235 c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
9199 if (!result) { | 9236 if (!result) { |
9200 return error::kOutOfBounds; | 9237 return error::kOutOfBounds; |
9201 } | 9238 } |
9202 } | 9239 } |
9203 | 9240 |
9204 if (!validators_->read_pixel_format.IsValid(format)) { | 9241 if (!validators_->read_pixel_format.IsValid(format)) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9320 | 9357 |
9321 if (!CheckBoundFramebuffersValid("glReadPixels")) { | 9358 if (!CheckBoundFramebuffersValid("glReadPixels")) { |
9322 return error::kNoError; | 9359 return error::kNoError; |
9323 } | 9360 } |
9324 | 9361 |
9325 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); | 9362 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); |
9326 | 9363 |
9327 ScopedResolvedFrameBufferBinder binder(this, false, true); | 9364 ScopedResolvedFrameBufferBinder binder(this, false, true); |
9328 | 9365 |
9329 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { | 9366 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { |
| 9367 // TODO(yunchao): need to handle the out-of-bounds case for reading pixels |
| 9368 // into PIXEL_PACK buffer. |
| 9369 if (c.pixels_shm_id == 0) { |
| 9370 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", |
| 9371 "read pixels out of bounds into PIXEL_PACK buffer"); |
| 9372 return error::kNoError; |
| 9373 } |
9330 // The user requested an out of range area. Get the results 1 line | 9374 // The user requested an out of range area. Get the results 1 line |
9331 // at a time. | 9375 // at a time. |
9332 uint32 temp_size; | 9376 uint32 temp_size; |
9333 uint32 unpadded_row_size; | 9377 uint32 unpadded_row_size; |
9334 uint32 padded_row_size; | 9378 uint32 padded_row_size; |
9335 if (!GLES2Util::ComputeImageDataSizes( | 9379 if (!GLES2Util::ComputeImageDataSizes( |
9336 width, 2, 1, format, type, state_.pack_alignment, &temp_size, | 9380 width, 2, 1, format, type, state_.pack_alignment, &temp_size, |
9337 &unpadded_row_size, &padded_row_size)) { | 9381 &unpadded_row_size, &padded_row_size)) { |
9338 LOCAL_SET_GL_ERROR( | 9382 LOCAL_SET_GL_ERROR( |
9339 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); | 9383 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9395 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 9439 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
9396 return error::kNoError; | 9440 return error::kNoError; |
9397 } else { | 9441 } else { |
9398 // On error, unbind pack buffer and fall through to sync readpixels | 9442 // On error, unbind pack buffer and fall through to sync readpixels |
9399 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 9443 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
9400 glDeleteBuffersARB(1, &buffer); | 9444 glDeleteBuffersARB(1, &buffer); |
9401 } | 9445 } |
9402 } | 9446 } |
9403 glReadPixels(x, y, width, height, format, type, pixels); | 9447 glReadPixels(x, y, width, height, format, type, pixels); |
9404 } | 9448 } |
9405 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); | 9449 if (c.pixels_shm_id != 0) { |
9406 if (error == GL_NO_ERROR) { | 9450 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
9407 if (result != NULL) { | 9451 if (error == GL_NO_ERROR) { |
9408 *result = true; | 9452 if (result != NULL) { |
| 9453 *result = true; |
| 9454 } |
| 9455 FinishReadPixels(c, 0); |
9409 } | 9456 } |
9410 FinishReadPixels(c, 0); | |
9411 } | 9457 } |
9412 | 9458 |
9413 return error::kNoError; | 9459 return error::kNoError; |
9414 } | 9460 } |
9415 | 9461 |
9416 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, | 9462 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, |
9417 const void* cmd_data) { | 9463 const void* cmd_data) { |
9418 const gles2::cmds::PixelStorei& c = | 9464 const gles2::cmds::PixelStorei& c = |
9419 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); | 9465 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); |
9420 GLenum pname = c.pname; | 9466 GLenum pname = c.pname; |
(...skipping 6364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15785 return error::kNoError; | 15831 return error::kNoError; |
15786 } | 15832 } |
15787 | 15833 |
15788 // Include the auto-generated part of this file. We split this because it means | 15834 // Include the auto-generated part of this file. We split this because it means |
15789 // we can easily edit the non-auto generated parts right here in this file | 15835 // we can easily edit the non-auto generated parts right here in this file |
15790 // instead of having to edit some template or the code generator. | 15836 // instead of having to edit some template or the code generator. |
15791 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 15837 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
15792 | 15838 |
15793 } // namespace gles2 | 15839 } // namespace gles2 |
15794 } // namespace gpu | 15840 } // namespace gpu |
OLD | NEW |