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 8878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8889 GLsizei height = c.height; | 8889 GLsizei height = c.height; |
| 8890 GLenum format = c.format; | 8890 GLenum format = c.format; |
| 8891 GLenum type = c.type; | 8891 GLenum type = c.type; |
| 8892 GLboolean async = static_cast<GLboolean>(c.async); | 8892 GLboolean async = static_cast<GLboolean>(c.async); |
| 8893 if (width < 0 || height < 0) { | 8893 if (width < 0 || height < 0) { |
| 8894 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); | 8894 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
| 8895 return error::kNoError; | 8895 return error::kNoError; |
| 8896 } | 8896 } |
| 8897 typedef cmds::ReadPixels::Result Result; | 8897 typedef cmds::ReadPixels::Result Result; |
| 8898 uint32 pixels_size; | 8898 uint32 pixels_size; |
| 8899 if (state_.bound_pixel_pack_buffer.get()) { | |
| 8900 // TODO(zmo): Need to handle the case of reading into a PIXEL_PACK_BUFFER | |
| 8901 // in ES3, including more pack parameters. For now, generate a GL error. | |
| 8902 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 8903 "ReadPixels to a pixel pack buffer isn't implemented"); | |
| 8904 return error::kNoError; | |
| 8905 } | |
| 8906 if (!GLES2Util::ComputeImageDataSizes( | 8899 if (!GLES2Util::ComputeImageDataSizes( |
| 8907 width, height, 1, format, type, state_.pack_alignment, &pixels_size, | 8900 width, height, 1, format, type, state_.pack_alignment, &pixels_size, |
| 8908 NULL, NULL)) { | 8901 NULL, NULL)) { |
| 8909 return error::kOutOfBounds; | 8902 return error::kOutOfBounds; |
| 8910 } | 8903 } |
| 8911 void* pixels = GetSharedMemoryAs<void*>( | 8904 |
| 8912 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); | 8905 void* pixels = NULL; |
| 8913 if (!pixels) { | 8906 Buffer* buffer = state_.bound_pixel_pack_buffer.get(); |
| 8914 return error::kOutOfBounds; | 8907 if (c.pixels_shm_id == 0) { |
| 8908 if (buffer) { | |
| 8909 if (buffer->GetMappedRange()) { | |
| 8910 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 8911 "pixel pack buffer should not be mapped to client memory"); | |
| 8912 return error::kNoError; | |
| 8913 } | |
| 8914 if (buffer->size() < pixels_size) { | |
|
Zhenyao Mo
2015/12/02 19:36:41
Right now the pixels_size we compute could be smal
yunchao
2015/12/03 17:39:14
Acknowledged.
| |
| 8915 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 8916 "pixel pack buffer is not large enough"); | |
| 8917 return error::kNoError; | |
| 8918 } | |
|
Zhenyao Mo
2015/12/02 19:36:41
It's worth checking the result_shm_id and result_s
yunchao
2015/12/03 17:39:14
Done.
| |
| 8919 pixels = reinterpret_cast<void *>(c.pixels_shm_offset); | |
| 8920 } else { | |
| 8921 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 8922 "no pixel pack buffer bound"); | |
| 8923 return error::kNoError; | |
| 8924 } | |
| 8925 } else { | |
| 8926 if (buffer) { | |
| 8927 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadPixels", | |
| 8928 "pixel pack buffer should not bound"); | |
| 8929 return error::kNoError; | |
| 8930 } else { | |
| 8931 pixels = GetSharedMemoryAs<void*>( | |
| 8932 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); | |
| 8933 if (!pixels) { | |
| 8934 return error::kOutOfBounds; | |
| 8935 } | |
| 8936 } | |
| 8915 } | 8937 } |
| 8938 | |
| 8916 Result* result = NULL; | 8939 Result* result = NULL; |
| 8917 if (c.result_shm_id != 0) { | 8940 if (c.result_shm_id != 0) { |
| 8918 result = GetSharedMemoryAs<Result*>( | 8941 result = GetSharedMemoryAs<Result*>( |
| 8919 c.result_shm_id, c.result_shm_offset, sizeof(*result)); | 8942 c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8920 if (!result) { | 8943 if (!result) { |
| 8921 return error::kOutOfBounds; | 8944 return error::kOutOfBounds; |
| 8922 } | 8945 } |
| 8923 } | 8946 } |
| 8924 | 8947 |
| 8925 if (!validators_->read_pixel_format.IsValid(format)) { | 8948 if (!validators_->read_pixel_format.IsValid(format)) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9040 } | 9063 } |
| 9041 | 9064 |
| 9042 if (!CheckBoundFramebuffersValid("glReadPixels")) { | 9065 if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 9043 return error::kNoError; | 9066 return error::kNoError; |
| 9044 } | 9067 } |
| 9045 | 9068 |
| 9046 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); | 9069 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); |
| 9047 | 9070 |
| 9048 ScopedResolvedFrameBufferBinder binder(this, false, true); | 9071 ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 9049 | 9072 |
| 9050 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { | 9073 if ((x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) |
| 9074 && c.pixels_shm_id != 0) { | |
| 9051 // The user requested an out of range area. Get the results 1 line | 9075 // The user requested an out of range area. Get the results 1 line |
| 9052 // at a time. | 9076 // at a time. |
| 9053 uint32 temp_size; | 9077 uint32 temp_size; |
| 9054 uint32 unpadded_row_size; | 9078 uint32 unpadded_row_size; |
| 9055 uint32 padded_row_size; | 9079 uint32 padded_row_size; |
| 9056 if (!GLES2Util::ComputeImageDataSizes( | 9080 if (!GLES2Util::ComputeImageDataSizes( |
| 9057 width, 2, 1, format, type, state_.pack_alignment, &temp_size, | 9081 width, 2, 1, format, type, state_.pack_alignment, &temp_size, |
| 9058 &unpadded_row_size, &padded_row_size)) { | 9082 &unpadded_row_size, &padded_row_size)) { |
| 9059 LOCAL_SET_GL_ERROR( | 9083 LOCAL_SET_GL_ERROR( |
| 9060 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); | 9084 GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9121 glDeleteBuffersARB(1, &buffer); | 9145 glDeleteBuffersARB(1, &buffer); |
| 9122 } | 9146 } |
| 9123 } | 9147 } |
| 9124 glReadPixels(x, y, width, height, format, type, pixels); | 9148 glReadPixels(x, y, width, height, format, type, pixels); |
| 9125 } | 9149 } |
| 9126 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); | 9150 GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
| 9127 if (error == GL_NO_ERROR) { | 9151 if (error == GL_NO_ERROR) { |
| 9128 if (result != NULL) { | 9152 if (result != NULL) { |
| 9129 *result = true; | 9153 *result = true; |
| 9130 } | 9154 } |
| 9131 FinishReadPixels(c, 0); | 9155 if (c.pixels_shm_id != 0) { |
|
Zhenyao Mo
2015/12/02 19:36:41
I think we should also avoid glGetError() if we re
yunchao
2015/12/03 17:39:14
Done.
| |
| 9156 FinishReadPixels(c, 0); | |
| 9157 } | |
| 9132 } | 9158 } |
| 9133 | 9159 |
| 9134 return error::kNoError; | 9160 return error::kNoError; |
| 9135 } | 9161 } |
| 9136 | 9162 |
| 9137 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, | 9163 error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, |
| 9138 const void* cmd_data) { | 9164 const void* cmd_data) { |
| 9139 const gles2::cmds::PixelStorei& c = | 9165 const gles2::cmds::PixelStorei& c = |
| 9140 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); | 9166 *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); |
| 9141 GLenum pname = c.pname; | 9167 GLenum pname = c.pname; |
| (...skipping 6274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15416 return error::kNoError; | 15442 return error::kNoError; |
| 15417 } | 15443 } |
| 15418 | 15444 |
| 15419 // Include the auto-generated part of this file. We split this because it means | 15445 // Include the auto-generated part of this file. We split this because it means |
| 15420 // we can easily edit the non-auto generated parts right here in this file | 15446 // we can easily edit the non-auto generated parts right here in this file |
| 15421 // instead of having to edit some template or the code generator. | 15447 // instead of having to edit some template or the code generator. |
| 15422 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 15448 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 15423 | 15449 |
| 15424 } // namespace gles2 | 15450 } // namespace gles2 |
| 15425 } // namespace gpu | 15451 } // namespace gpu |
| OLD | NEW |