| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 emulate GLES2 over command buffers. |
| 6 | 6 |
| 7 #include "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
| 8 #include <GLES2/gles2_command_buffer.h> | 8 #include <GLES2/gles2_command_buffer.h> |
| 9 #include "../client/mapped_memory.h" | 9 #include "../client/mapped_memory.h" |
| 10 #include "../common/gles2_cmd_utils.h" | 10 #include "../common/gles2_cmd_utils.h" |
| 11 #include "../common/id_allocator.h" | 11 #include "../common/id_allocator.h" |
| 12 | 12 |
| 13 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 13 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
| 14 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS | 14 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS |
| 15 #endif | 15 #endif |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 pack_alignment_(4), | 439 pack_alignment_(4), |
| 440 unpack_alignment_(4), | 440 unpack_alignment_(4), |
| 441 bound_array_buffer_id_(0), | 441 bound_array_buffer_id_(0), |
| 442 bound_element_array_buffer_id_(0), | 442 bound_element_array_buffer_id_(0), |
| 443 client_side_array_id_(0), | 443 client_side_array_id_(0), |
| 444 client_side_element_array_id_(0), | 444 client_side_element_array_id_(0), |
| 445 error_bits_(0) { | 445 error_bits_(0) { |
| 446 // Allocate space for simple GL results. | 446 // Allocate space for simple GL results. |
| 447 result_buffer_ = transfer_buffer; | 447 result_buffer_ = transfer_buffer; |
| 448 result_shm_offset_ = 0; | 448 result_shm_offset_ = 0; |
| 449 memset(&reserved_ids_, 0, sizeof(reserved_ids_)); |
| 449 | 450 |
| 450 mapped_memory_.reset(new MappedMemoryManager(helper_)); | 451 mapped_memory_.reset(new MappedMemoryManager(helper_)); |
| 451 | 452 |
| 452 if (share_resources) { | 453 if (share_resources) { |
| 453 buffer_id_handler_.reset( | 454 buffer_id_handler_.reset( |
| 454 new SharedIdHandler(this, id_namespaces::kBuffers)); | 455 new SharedIdHandler(this, id_namespaces::kBuffers)); |
| 455 framebuffer_id_handler_.reset( | 456 framebuffer_id_handler_.reset( |
| 456 new SharedIdHandler(this, id_namespaces::kFramebuffers)); | 457 new SharedIdHandler(this, id_namespaces::kFramebuffers)); |
| 457 renderbuffer_id_handler_.reset( | 458 renderbuffer_id_handler_.reset( |
| 458 new SharedIdHandler(this, id_namespaces::kRenderbuffers)); | 459 new SharedIdHandler(this, id_namespaces::kRenderbuffers)); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 } | 658 } |
| 658 #else | 659 #else |
| 659 helper_->DrawElements(mode, count, type, ToGLuint(indices)); | 660 helper_->DrawElements(mode, count, type, ToGLuint(indices)); |
| 660 #endif | 661 #endif |
| 661 } | 662 } |
| 662 | 663 |
| 663 void GLES2Implementation::Flush() { | 664 void GLES2Implementation::Flush() { |
| 664 // Insert the cmd to call glFlush | 665 // Insert the cmd to call glFlush |
| 665 helper_->Flush(); | 666 helper_->Flush(); |
| 666 // Flush our command buffer | 667 // Flush our command buffer |
| 667 // (tell the service to execute upto the flush cmd.) | 668 // (tell the service to execute up to the flush cmd.) |
| 668 helper_->CommandBufferHelper::Flush(); | 669 helper_->CommandBufferHelper::Flush(); |
| 669 } | 670 } |
| 670 | 671 |
| 671 void GLES2Implementation::Finish() { | 672 void GLES2Implementation::Finish() { |
| 672 // Insert the cmd to call glFinish | 673 // Insert the cmd to call glFinish |
| 673 helper_->Finish(); | 674 helper_->Finish(); |
| 674 // Finish our command buffer | 675 // Finish our command buffer |
| 675 // (tell the service to execute upto the Finish cmd and wait for it to | 676 // (tell the service to execute up to the Finish cmd and wait for it to |
| 676 // execute.) | 677 // execute.) |
| 677 helper_->CommandBufferHelper::Finish(); | 678 helper_->CommandBufferHelper::Finish(); |
| 678 } | 679 } |
| 679 | 680 |
| 680 void GLES2Implementation::SwapBuffers() { | 681 void GLES2Implementation::SwapBuffers() { |
| 681 // Wait if this would add too many swap buffers. | 682 // Wait if this would add too many swap buffers. |
| 682 if (swap_buffers_tokens_.size() == kMaxSwapBuffers) { | 683 if (swap_buffers_tokens_.size() == kMaxSwapBuffers) { |
| 683 helper_->WaitForToken(swap_buffers_tokens_.front()); | 684 helper_->WaitForToken(swap_buffers_tokens_.front()); |
| 684 swap_buffers_tokens_.pop(); | 685 swap_buffers_tokens_.pop(); |
| 685 } | 686 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 memcpy(buffer, source, part_size); | 1031 memcpy(buffer, source, part_size); |
| 1031 helper_->TexSubImage2D( | 1032 helper_->TexSubImage2D( |
| 1032 target, level, xoffset, yoffset, width, num_rows, format, type, | 1033 target, level, xoffset, yoffset, width, num_rows, format, type, |
| 1033 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer)); | 1034 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer)); |
| 1034 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | 1035 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); |
| 1035 yoffset += num_rows; | 1036 yoffset += num_rows; |
| 1036 source += part_size; | 1037 source += part_size; |
| 1037 height -= num_rows; | 1038 height -= num_rows; |
| 1038 } | 1039 } |
| 1039 } else { | 1040 } else { |
| 1040 // Transfer by sub rows. Beacuse GL has no maximum texture dimensions. | 1041 // Transfer by sub rows. Because GL has no maximum texture dimensions. |
| 1041 uint32 temp; | 1042 uint32 temp; |
| 1042 GLES2Util::ComputeImageDataSize( | 1043 GLES2Util::ComputeImageDataSize( |
| 1043 1, 1, format, type, unpack_alignment_, &temp); | 1044 1, 1, format, type, unpack_alignment_, &temp); |
| 1044 GLsizeiptr element_size = temp; | 1045 GLsizeiptr element_size = temp; |
| 1045 max_size -= max_size % element_size; | 1046 max_size -= max_size % element_size; |
| 1046 GLint max_sub_row_pixels = max_size / element_size; | 1047 GLint max_sub_row_pixels = max_size / element_size; |
| 1047 for (; height; --height) { | 1048 for (; height; --height) { |
| 1048 GLint temp_width = width; | 1049 GLint temp_width = width; |
| 1049 GLint temp_xoffset = xoffset; | 1050 GLint temp_xoffset = xoffset; |
| 1050 const int8* row_source = source; | 1051 const int8* row_source = source; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, | 1249 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, |
| 1249 GLenum type, void* pixels) { | 1250 GLenum type, void* pixels) { |
| 1250 if (width < 0 || height < 0) { | 1251 if (width < 0 || height < 0) { |
| 1251 SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions < 0"); | 1252 SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions < 0"); |
| 1252 return; | 1253 return; |
| 1253 } | 1254 } |
| 1254 if (width == 0 || height == 0) { | 1255 if (width == 0 || height == 0) { |
| 1255 return; | 1256 return; |
| 1256 } | 1257 } |
| 1257 | 1258 |
| 1258 // glReadPixel pads the size of each row of pixels by an ammount specified by | 1259 // glReadPixel pads the size of each row of pixels by an amount specified by |
| 1259 // glPixelStorei. So, we have to take that into account both in the fact that | 1260 // glPixelStorei. So, we have to take that into account both in the fact that |
| 1260 // the pixels returned from the ReadPixel command will include that padding | 1261 // the pixels returned from the ReadPixel command will include that padding |
| 1261 // and that when we copy the results to the user's buffer we need to not | 1262 // and that when we copy the results to the user's buffer we need to not |
| 1262 // write those padding bytes but leave them as they are. | 1263 // write those padding bytes but leave them as they are. |
| 1263 | 1264 |
| 1264 typedef gles2::ReadPixels::Result Result; | 1265 typedef gles2::ReadPixels::Result Result; |
| 1265 Result* result = static_cast<Result*>(result_buffer_); | 1266 Result* result = static_cast<Result*>(result_buffer_); |
| 1266 int8* dest = reinterpret_cast<int8*>(pixels); | 1267 int8* dest = reinterpret_cast<int8*>(pixels); |
| 1267 GLsizeiptr max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); | 1268 GLsizeiptr max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); |
| 1268 uint32 temp_size; | 1269 uint32 temp_size; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 } | 1314 } |
| 1314 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); | 1315 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); |
| 1315 // If it was not marked as successful exit. | 1316 // If it was not marked as successful exit. |
| 1316 if (*result == 0) { | 1317 if (*result == 0) { |
| 1317 return; | 1318 return; |
| 1318 } | 1319 } |
| 1319 yoffset += num_rows; | 1320 yoffset += num_rows; |
| 1320 height -= num_rows; | 1321 height -= num_rows; |
| 1321 } | 1322 } |
| 1322 } else { | 1323 } else { |
| 1323 // Transfer by sub rows. Beacuse GL has no maximum texture dimensions. | 1324 // Transfer by sub rows. Because GL has no maximum texture dimensions. |
| 1324 GLES2Util::ComputeImageDataSize( | 1325 GLES2Util::ComputeImageDataSize( |
| 1325 1, 1, format, type, pack_alignment_, &temp_size); | 1326 1, 1, format, type, pack_alignment_, &temp_size); |
| 1326 GLsizeiptr element_size = temp_size; | 1327 GLsizeiptr element_size = temp_size; |
| 1327 max_size -= max_size % element_size; | 1328 max_size -= max_size % element_size; |
| 1328 GLint max_sub_row_pixels = max_size / element_size; | 1329 GLint max_sub_row_pixels = max_size / element_size; |
| 1329 for (; height; --height) { | 1330 for (; height; --height) { |
| 1330 GLint temp_width = width; | 1331 GLint temp_width = width; |
| 1331 GLint temp_xoffset = xoffset; | 1332 GLint temp_xoffset = xoffset; |
| 1332 int8* row_dest = dest; | 1333 int8* row_dest = dest; |
| 1333 while (temp_width) { | 1334 while (temp_width) { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 } | 1668 } |
| 1668 | 1669 |
| 1669 void GLES2Implementation::RequestExtensionCHROMIUM(const char* extension) { | 1670 void GLES2Implementation::RequestExtensionCHROMIUM(const char* extension) { |
| 1670 SetBucketAsCString(kResultBucketId, extension); | 1671 SetBucketAsCString(kResultBucketId, extension); |
| 1671 helper_->RequestExtensionCHROMIUM(kResultBucketId); | 1672 helper_->RequestExtensionCHROMIUM(kResultBucketId); |
| 1672 helper_->SetBucketSize(kResultBucketId, 0); | 1673 helper_->SetBucketSize(kResultBucketId, 0); |
| 1673 } | 1674 } |
| 1674 | 1675 |
| 1675 } // namespace gles2 | 1676 } // namespace gles2 |
| 1676 } // namespace gpu | 1677 } // namespace gpu |
| OLD | NEW |