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 // A class to emulate GLES2 over command buffers. | 5 // A class to emulate GLES2 over command buffers. |
6 | 6 |
7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 | 8 |
9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
10 #include <GLES2/gl2extchromium.h> | 10 #include <GLES2/gl2extchromium.h> |
(...skipping 4503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4514 // TODO(zmo): Implement client side caching. | 4514 // TODO(zmo): Implement client side caching. |
4515 return false; | 4515 return false; |
4516 } | 4516 } |
4517 | 4517 |
4518 bool GLES2Implementation::GetSamplerParameterivHelper( | 4518 bool GLES2Implementation::GetSamplerParameterivHelper( |
4519 GLuint /* sampler */, GLenum /* pname */, GLint* /* params */) { | 4519 GLuint /* sampler */, GLenum /* pname */, GLint* /* params */) { |
4520 // TODO(zmo): Implement client side caching. | 4520 // TODO(zmo): Implement client side caching. |
4521 return false; | 4521 return false; |
4522 } | 4522 } |
4523 | 4523 |
| 4524 bool GLES2Implementation::PackStringsToBucket(GLsizei count, |
| 4525 const char* const* str, |
| 4526 const GLint* length, |
| 4527 const char* func_name) { |
| 4528 DCHECK_LE(0, count); |
| 4529 // Compute the total size. |
| 4530 base::CheckedNumeric<size_t> total_size = count; |
| 4531 total_size += 1; |
| 4532 total_size *= sizeof(GLint); |
| 4533 if (!total_size.IsValid()) { |
| 4534 SetGLError(GL_INVALID_VALUE, func_name, "overflow"); |
| 4535 return false; |
| 4536 } |
| 4537 size_t header_size = total_size.ValueOrDefault(0); |
| 4538 std::vector<GLint> header(count + 1); |
| 4539 header[0] = static_cast<GLint>(count); |
| 4540 for (GLsizei ii = 0; ii < count; ++ii) { |
| 4541 GLint len = 0; |
| 4542 if (str[ii]) { |
| 4543 len = (length && length[ii] >= 0) |
| 4544 ? length[ii] |
| 4545 : base::checked_cast<GLint>(strlen(str[ii])); |
| 4546 } |
| 4547 total_size += len; |
| 4548 total_size += 1; // NULL at the end of each char array. |
| 4549 if (!total_size.IsValid()) { |
| 4550 SetGLError(GL_INVALID_VALUE, func_name, "overflow"); |
| 4551 return false; |
| 4552 } |
| 4553 header[ii + 1] = len; |
| 4554 } |
| 4555 // Pack data into a bucket on the service. |
| 4556 helper_->SetBucketSize(kResultBucketId, total_size.ValueOrDefault(0)); |
| 4557 size_t offset = 0; |
| 4558 for (GLsizei ii = 0; ii <= count; ++ii) { |
| 4559 const char* src = |
| 4560 (ii == 0) ? reinterpret_cast<const char*>(&header[0]) : str[ii - 1]; |
| 4561 base::CheckedNumeric<size_t> checked_size = |
| 4562 (ii == 0) ? header_size : static_cast<size_t>(header[ii]); |
| 4563 if (ii > 0) { |
| 4564 checked_size += 1; // NULL in the end. |
| 4565 } |
| 4566 if (!checked_size.IsValid()) { |
| 4567 SetGLError(GL_INVALID_VALUE, func_name, "overflow"); |
| 4568 return false; |
| 4569 } |
| 4570 size_t size = checked_size.ValueOrDefault(0); |
| 4571 while (size) { |
| 4572 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); |
| 4573 if (!buffer.valid() || buffer.size() == 0) { |
| 4574 SetGLError(GL_OUT_OF_MEMORY, func_name, "too large"); |
| 4575 return false; |
| 4576 } |
| 4577 size_t copy_size = buffer.size(); |
| 4578 if (ii > 0 && buffer.size() == size) |
| 4579 --copy_size; |
| 4580 if (copy_size) |
| 4581 memcpy(buffer.address(), src, copy_size); |
| 4582 if (copy_size < buffer.size()) { |
| 4583 // Append NULL in the end. |
| 4584 DCHECK(copy_size + 1 == buffer.size()); |
| 4585 char* str = reinterpret_cast<char*>(buffer.address()); |
| 4586 str[copy_size] = 0; |
| 4587 } |
| 4588 helper_->SetBucketData(kResultBucketId, offset, buffer.size(), |
| 4589 buffer.shm_id(), buffer.offset()); |
| 4590 offset += buffer.size(); |
| 4591 src += buffer.size(); |
| 4592 size -= buffer.size(); |
| 4593 } |
| 4594 } |
| 4595 DCHECK_EQ(total_size.ValueOrDefault(0), offset); |
| 4596 return true; |
| 4597 } |
| 4598 |
4524 // Include the auto-generated part of this file. We split this because it means | 4599 // Include the auto-generated part of this file. We split this because it means |
4525 // we can easily edit the non-auto generated parts right here in this file | 4600 // we can easily edit the non-auto generated parts right here in this file |
4526 // instead of having to edit some template or the code generator. | 4601 // instead of having to edit some template or the code generator. |
4527 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 4602 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
4528 | 4603 |
4529 } // namespace gles2 | 4604 } // namespace gles2 |
4530 } // namespace gpu | 4605 } // namespace gpu |
OLD | NEW |