Chromium Code Reviews| 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 9157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; |
| 9178 if (state_.bound_pixel_pack_buffer.get()) { | 9178 PixelStoreParams params = state_.GetPackParams(); |
| 9179 // TODO(zmo): Need to handle the case of reading into a PIXEL_PACK_BUFFER | 9179 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.
| |
| 9180 // in ES3, including more pack parameters. For now, generate a GL error. | 9180 params, &pixels_size, nullptr, nullptr, nullptr)) { |
| 9181 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 9182 "ReadPixels to a pixel pack buffer isn't implemented"); | |
| 9183 return error::kNoError; | |
| 9184 } | |
| 9185 if (!GLES2Util::ComputeImageDataSizes( | |
| 9186 width, height, 1, format, type, state_.pack_alignment, &pixels_size, | |
| 9187 NULL, NULL)) { | |
| 9188 return error::kOutOfBounds; | 9181 return error::kOutOfBounds; |
| 9189 } | 9182 } |
| 9190 void* pixels = GetSharedMemoryAs<void*>( | 9183 |
| 9191 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); | 9184 void* pixels = nullptr; |
| 9192 if (!pixels) { | 9185 Buffer* buffer = state_.bound_pixel_pack_buffer.get(); |
| 9193 return error::kOutOfBounds; | 9186 if (c.pixels_shm_id == 0) { |
| 9187 if (buffer) { | |
| 9188 if (buffer->GetMappedRange()) { | |
| 9189 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 9190 "pixel pack buffer should not be mapped to client memory"); | |
| 9191 return error::kNoError; | |
| 9192 } | |
| 9193 uint32 size = 0; | |
| 9194 if (!SafeAddUint32(pixels_size, c.pixels_shm_offset, &size)) { | |
| 9195 LOCAL_SET_GL_ERROR( | |
| 9196 GL_INVALID_VALUE, "glReadPixels", "size + offset overflow"); | |
| 9197 return error::kNoError; | |
| 9198 } | |
| 9199 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.
| |
| 9200 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 9201 "pixel pack buffer is not large enough"); | |
| 9202 return error::kNoError; | |
| 9203 } | |
| 9204 pixels = reinterpret_cast<void *>(c.pixels_shm_offset); | |
| 9205 } else { | |
| 9206 return error::kInvalidArguments; | |
| 9207 } | |
| 9208 } else { | |
| 9209 if (buffer) { | |
| 9210 return error::kInvalidArguments; | |
| 9211 } else { | |
| 9212 pixels = GetSharedMemoryAs<void*>( | |
| 9213 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); | |
| 9214 if (!pixels) { | |
| 9215 return error::kOutOfBounds; | |
| 9216 } | |
| 9217 } | |
| 9194 } | 9218 } |
| 9219 | |
| 9195 Result* result = NULL; | 9220 Result* result = NULL; |
| 9196 if (c.result_shm_id != 0) { | 9221 if (c.result_shm_id != 0) { |
| 9197 result = GetSharedMemoryAs<Result*>( | 9222 result = GetSharedMemoryAs<Result*>( |
| 9198 c.result_shm_id, c.result_shm_offset, sizeof(*result)); | 9223 c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9199 if (!result) { | 9224 if (!result) { |
| 9200 return error::kOutOfBounds; | 9225 return error::kOutOfBounds; |
| 9201 } | 9226 } |
| 9202 } | 9227 } |
| 9203 | 9228 |
| 9204 if (!validators_->read_pixel_format.IsValid(format)) { | 9229 if (!validators_->read_pixel_format.IsValid(format)) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9320 | 9345 |
| 9321 if (!CheckBoundFramebuffersValid("glReadPixels")) { | 9346 if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 9322 return error::kNoError; | 9347 return error::kNoError; |
| 9323 } | 9348 } |
| 9324 | 9349 |
| 9325 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); | 9350 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); |
| 9326 | 9351 |
| 9327 ScopedResolvedFrameBufferBinder binder(this, false, true); | 9352 ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 9328 | 9353 |
| 9329 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { | 9354 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { |
| 9355 // TODO(yunchao): need to handle the out-of-bounds case for reading pixels | |
| 9356 // into PIXEL_PACK buffer. | |
| 9357 if (c.pixels_shm_id == 0) { | |
| 9358 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 9359 "read pixels out of bounds into PIXEL_PACK buffer"); | |
| 9360 return error::kNoError; | |
| 9361 } | |
| 9330 // The user requested an out of range area. Get the results 1 line | 9362 // The user requested an out of range area. Get the results 1 line |
| 9331 // at a time. | 9363 // at a time. |
| 9332 uint32 temp_size; | 9364 uint32 temp_size; |
| 9333 uint32 unpadded_row_size; | 9365 uint32 unpadded_row_size; |
| 9334 uint32 padded_row_size; | 9366 uint32 padded_row_size; |
| 9335 if (!GLES2Util::ComputeImageDataSizes( | 9367 if (!GLES2Util::ComputeImageDataSizes( |
| 9336 width, 2, 1, format, type, state_.pack_alignment, &temp_size, | 9368 width, 2, 1, format, type, state_.pack_alignment, &temp_size, |
| 9337 &unpadded_row_size, &padded_row_size)) { | 9369 &unpadded_row_size, &padded_row_size)) { |
| 9338 LOCAL_SET_GL_ERROR( | 9370 LOCAL_SET_GL_ERROR( |
| 9339 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); | 9371 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); | 9427 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 9396 return error::kNoError; | 9428 return error::kNoError; |
| 9397 } else { | 9429 } else { |
| 9398 // On error, unbind pack buffer and fall through to sync readpixels | 9430 // On error, unbind pack buffer and fall through to sync readpixels |
| 9399 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 9431 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 9400 glDeleteBuffersARB(1, &buffer); | 9432 glDeleteBuffersARB(1, &buffer); |
| 9401 } | 9433 } |
| 9402 } | 9434 } |
| 9403 glReadPixels(x, y, width, height, format, type, pixels); | 9435 glReadPixels(x, y, width, height, format, type, pixels); |
| 9404 } | 9436 } |
| 9405 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); | 9437 if (c.pixels_shm_id != 0) { |
| 9406 if (error == GL_NO_ERROR) { | 9438 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
| 9407 if (result != NULL) { | 9439 if (error == GL_NO_ERROR) { |
| 9408 *result = true; | 9440 if (result != NULL) { |
| 9441 *result = true; | |
| 9442 } | |
| 9443 FinishReadPixels(c, 0); | |
| 9409 } | 9444 } |
| 9410 FinishReadPixels(c, 0); | |
| 9411 } | 9445 } |
| 9412 | 9446 |
| 9413 return error::kNoError; | 9447 return error::kNoError; |
| 9414 } | 9448 } |
| 9415 | 9449 |
| 9416 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, | 9450 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, |
| 9417 const void* cmd_data) { | 9451 const void* cmd_data) { |
| 9418 const gles2::cmds::PixelStorei& c = | 9452 const gles2::cmds::PixelStorei& c = |
| 9419 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); | 9453 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); |
| 9420 GLenum pname = c.pname; | 9454 GLenum pname = c.pname; |
| (...skipping 6364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15785 return error::kNoError; | 15819 return error::kNoError; |
| 15786 } | 15820 } |
| 15787 | 15821 |
| 15788 // Include the auto-generated part of this file. We split this because it means | 15822 // 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 | 15823 // 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. | 15824 // instead of having to edit some template or the code generator. |
| 15791 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 15825 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 15792 | 15826 |
| 15793 } // namespace gles2 | 15827 } // namespace gles2 |
| 15794 } // namespace gpu | 15828 } // namespace gpu |
| OLD | NEW |