OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // A class to emluate GLES2 over command buffers. | 5 // A class to emluate GLES2 over command buffers. |
6 | 6 |
7 #include "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
8 #include "../common/gles2_cmd_utils.h" | 8 #include "../common/gles2_cmd_utils.h" |
9 | 9 |
10 namespace gpu { | 10 namespace gpu { |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 GLsizei length) { | 637 GLsizei length) { |
638 if (n < 0) { | 638 if (n < 0) { |
639 SetGLError(GL_INVALID_VALUE, "glShaderBinary n < 0."); | 639 SetGLError(GL_INVALID_VALUE, "glShaderBinary n < 0."); |
640 return; | 640 return; |
641 } | 641 } |
642 if (length < 0) { | 642 if (length < 0) { |
643 SetGLError(GL_INVALID_VALUE, "glShaderBinary length < 0."); | 643 SetGLError(GL_INVALID_VALUE, "glShaderBinary length < 0."); |
644 return; | 644 return; |
645 } | 645 } |
646 GLsizei shader_id_size = n * sizeof(*shaders); | 646 GLsizei shader_id_size = n * sizeof(*shaders); |
647 void* shader_ids = transfer_buffer_.Alloc(shader_id_size); | 647 char* buffer = transfer_buffer_.AllocTyped<char>(shader_id_size + length); |
apatrick_chromium
2010/04/29 22:26:51
char -> int8
| |
648 void* shader_data = transfer_buffer_.Alloc(length); | 648 void* shader_ids = buffer; |
649 void* shader_data = buffer + shader_id_size; | |
649 memcpy(shader_ids, shaders, shader_id_size); | 650 memcpy(shader_ids, shaders, shader_id_size); |
650 memcpy(shader_data, binary, length); | 651 memcpy(shader_data, binary, length); |
651 helper_->ShaderBinary( | 652 helper_->ShaderBinary( |
652 n, | 653 n, |
653 transfer_buffer_id_, transfer_buffer_.GetOffset(shader_ids), | 654 transfer_buffer_id_, transfer_buffer_.GetOffset(shader_ids), |
654 binaryformat, | 655 binaryformat, |
655 transfer_buffer_id_, transfer_buffer_.GetOffset(shader_data), | 656 transfer_buffer_id_, transfer_buffer_.GetOffset(shader_data), |
656 length); | 657 length); |
657 int32 token = helper_->InsertToken(); | 658 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); |
658 transfer_buffer_.FreePendingToken(shader_ids, token); | |
659 transfer_buffer_.FreePendingToken(shader_data, token); | |
660 } | 659 } |
661 | 660 |
662 void GLES2Implementation::PixelStorei(GLenum pname, GLint param) { | 661 void GLES2Implementation::PixelStorei(GLenum pname, GLint param) { |
663 switch (pname) { | 662 switch (pname) { |
664 case GL_PACK_ALIGNMENT: | 663 case GL_PACK_ALIGNMENT: |
665 pack_alignment_ = param; | 664 pack_alignment_ = param; |
666 break; | 665 break; |
667 case GL_UNPACK_ALIGNMENT: | 666 case GL_UNPACK_ALIGNMENT: |
668 unpack_alignment_ = param; | 667 unpack_alignment_ = param; |
669 break; | 668 break; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 // include padding. | 1137 // include padding. |
1139 GLsizeiptr part_size = | 1138 GLsizeiptr part_size = |
1140 unpadded_row_size + (padded_row_size * std::max(num_rows - 1, 0)); | 1139 unpadded_row_size + (padded_row_size * std::max(num_rows - 1, 0)); |
1141 void* buffer = transfer_buffer_.Alloc(part_size); | 1140 void* buffer = transfer_buffer_.Alloc(part_size); |
1142 *result = 0; // mark as failed. | 1141 *result = 0; // mark as failed. |
1143 helper_->ReadPixels( | 1142 helper_->ReadPixels( |
1144 xoffset, yoffset, width, num_rows, format, type, | 1143 xoffset, yoffset, width, num_rows, format, type, |
1145 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), | 1144 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), |
1146 result_shm_id(), result_shm_offset()); | 1145 result_shm_id(), result_shm_offset()); |
1147 WaitForCmd(); | 1146 WaitForCmd(); |
1147 if (*result != 0) { | |
1148 // We have to copy 1 row at a time to avoid writing pad bytes. | |
1149 const int8* src = static_cast<const int8*>(buffer); | |
1150 for (GLint yy = 0; yy < num_rows; ++yy) { | |
1151 memcpy(dest, src, unpadded_row_size); | |
1152 dest += padded_row_size; | |
1153 src += padded_row_size; | |
1154 } | |
1155 } | |
1156 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | |
1148 // If it was not marked as successful exit. | 1157 // If it was not marked as successful exit. |
1149 if (*result == 0) { | 1158 if (*result == 0) { |
1150 return; | 1159 return; |
1151 } | 1160 } |
1152 // We have to copy 1 row at a time to avoid writing pad bytes. | |
1153 const int8* src = static_cast<const int8*>(buffer); | |
1154 for (GLint yy = 0; yy < num_rows; ++yy) { | |
1155 memcpy(dest, src, unpadded_row_size); | |
1156 dest += padded_row_size; | |
1157 src += padded_row_size; | |
1158 } | |
1159 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | |
1160 yoffset += num_rows; | 1161 yoffset += num_rows; |
1161 height -= num_rows; | 1162 height -= num_rows; |
1162 } | 1163 } |
1163 } else { | 1164 } else { |
1164 // Transfer by sub rows. Beacuse GL has no maximum texture dimensions. | 1165 // Transfer by sub rows. Beacuse GL has no maximum texture dimensions. |
1165 GLES2Util::ComputeImageDataSize( | 1166 GLES2Util::ComputeImageDataSize( |
1166 1, 1, format, type, pack_alignment_, &temp_size); | 1167 1, 1, format, type, pack_alignment_, &temp_size); |
1167 GLsizeiptr element_size = temp_size; | 1168 GLsizeiptr element_size = temp_size; |
1168 max_size -= max_size % element_size; | 1169 max_size -= max_size % element_size; |
1169 GLint max_sub_row_pixels = max_size / element_size; | 1170 GLint max_sub_row_pixels = max_size / element_size; |
1170 for (; height; --height) { | 1171 for (; height; --height) { |
1171 GLint temp_width = width; | 1172 GLint temp_width = width; |
1172 GLint temp_xoffset = xoffset; | 1173 GLint temp_xoffset = xoffset; |
1173 int8* row_dest = dest; | 1174 int8* row_dest = dest; |
1174 while (temp_width) { | 1175 while (temp_width) { |
1175 GLint num_pixels = std::min(width, max_sub_row_pixels); | 1176 GLint num_pixels = std::min(width, max_sub_row_pixels); |
1176 GLsizeiptr part_size = num_pixels * element_size; | 1177 GLsizeiptr part_size = num_pixels * element_size; |
1177 void* buffer = transfer_buffer_.Alloc(part_size); | 1178 void* buffer = transfer_buffer_.Alloc(part_size); |
1178 *result = 0; // mark as failed. | 1179 *result = 0; // mark as failed. |
1179 helper_->ReadPixels( | 1180 helper_->ReadPixels( |
1180 temp_xoffset, yoffset, temp_width, 1, format, type, | 1181 temp_xoffset, yoffset, temp_width, 1, format, type, |
1181 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), | 1182 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), |
1182 result_shm_id(), result_shm_offset()); | 1183 result_shm_id(), result_shm_offset()); |
1183 WaitForCmd(); | 1184 WaitForCmd(); |
1185 if (*result != 0) { | |
1186 memcpy(row_dest, buffer, part_size); | |
1187 } | |
1188 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | |
1184 // If it was not marked as successful exit. | 1189 // If it was not marked as successful exit. |
1185 if (*result == 0) { | 1190 if (*result == 0) { |
1186 return; | 1191 return; |
1187 } | 1192 } |
1188 memcpy(row_dest, buffer, part_size); | |
1189 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | |
1190 row_dest += part_size; | 1193 row_dest += part_size; |
1191 temp_xoffset += num_pixels; | 1194 temp_xoffset += num_pixels; |
1192 temp_width -= num_pixels; | 1195 temp_width -= num_pixels; |
1193 } | 1196 } |
1194 ++yoffset; | 1197 ++yoffset; |
1195 dest += padded_row_size; | 1198 dest += padded_row_size; |
1196 } | 1199 } |
1197 } | 1200 } |
1198 } | 1201 } |
1199 | 1202 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1345 helper_->GetVertexAttribiv( | 1348 helper_->GetVertexAttribiv( |
1346 index, pname, result_shm_id(), result_shm_offset()); | 1349 index, pname, result_shm_id(), result_shm_offset()); |
1347 WaitForCmd(); | 1350 WaitForCmd(); |
1348 result->CopyResult(params); | 1351 result->CopyResult(params); |
1349 } | 1352 } |
1350 | 1353 |
1351 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) | 1354 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) |
1352 | 1355 |
1353 } // namespace gles2 | 1356 } // namespace gles2 |
1354 } // namespace gpu | 1357 } // namespace gpu |
OLD | NEW |