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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 249 } |
250 | 250 |
251 GLES2CmdHelper* GLES2Implementation::helper() const { | 251 GLES2CmdHelper* GLES2Implementation::helper() const { |
252 return helper_; | 252 return helper_; |
253 } | 253 } |
254 | 254 |
255 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { | 255 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { |
256 return share_group_->GetIdHandler(namespace_id); | 256 return share_group_->GetIdHandler(namespace_id); |
257 } | 257 } |
258 | 258 |
| 259 RangeIdHandlerInterface* GLES2Implementation::GetRangeIdHandler( |
| 260 int namespace_id) const { |
| 261 return share_group_->GetRangeIdHandler(namespace_id); |
| 262 } |
| 263 |
259 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { | 264 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { |
260 if (namespace_id == id_namespaces::kQueries) | 265 if (namespace_id == id_namespaces::kQueries) |
261 return query_id_allocator_.get(); | 266 return query_id_allocator_.get(); |
262 NOTREACHED(); | 267 NOTREACHED(); |
263 return NULL; | 268 return NULL; |
264 } | 269 } |
265 | 270 |
266 void* GLES2Implementation::GetResultBuffer() { | 271 void* GLES2Implementation::GetResultBuffer() { |
267 return transfer_buffer_->GetResultBuffer(); | 272 return transfer_buffer_->GetResultBuffer(); |
268 } | 273 } |
(...skipping 5473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5742 if (buf_size >= result->GetNumResults()) { | 5747 if (buf_size >= result->GetNumResults()) { |
5743 buf_size = result->GetNumResults(); | 5748 buf_size = result->GetNumResults(); |
5744 } | 5749 } |
5745 for (GLsizei ii = 0; ii < buf_size; ++ii) { | 5750 for (GLsizei ii = 0; ii < buf_size; ++ii) { |
5746 params[ii] = data[ii]; | 5751 params[ii] = data[ii]; |
5747 } | 5752 } |
5748 } | 5753 } |
5749 CheckGLError(); | 5754 CheckGLError(); |
5750 } | 5755 } |
5751 | 5756 |
| 5757 GLuint GLES2Implementation::GenPathsCHROMIUM(GLsizei range) { |
| 5758 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGenPathsCHROMIUM(" << range |
| 5759 << ")"); |
| 5760 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 5761 static const char kFunctionName[] = "glGenPathsCHROMIUM"; |
| 5762 if (range < 0) { |
| 5763 SetGLError(GL_INVALID_VALUE, kFunctionName, "range < 0"); |
| 5764 return 0; |
| 5765 } |
| 5766 if (!base::IsValueInRangeForNumericType<int32_t>(range)) { |
| 5767 SetGLError(GL_INVALID_OPERATION, kFunctionName, "range more than 32-bit"); |
| 5768 return 0; |
| 5769 } |
| 5770 if (range == 0) |
| 5771 return 0; |
| 5772 |
| 5773 GLuint first_client_id = 0; |
| 5774 GetRangeIdHandler(id_namespaces::kPaths) |
| 5775 ->MakeIdRange(this, range, &first_client_id); |
| 5776 |
| 5777 if (first_client_id == 0) { |
| 5778 // Ran out of id space. Is not specified to raise any gl errors. |
| 5779 return 0; |
| 5780 } |
| 5781 |
| 5782 helper_->GenPathsCHROMIUM(first_client_id, range); |
| 5783 |
| 5784 GPU_CLIENT_LOG_CODE_BLOCK({ |
| 5785 for (GLsizei i = 0; i < range; ++i) { |
| 5786 GPU_CLIENT_LOG(" " << i << ": " << (first_client_id + i)); |
| 5787 } |
| 5788 }); |
| 5789 CheckGLError(); |
| 5790 return first_client_id; |
| 5791 } |
| 5792 |
| 5793 void GLES2Implementation::DeletePathsCHROMIUM(GLuint first_client_id, |
| 5794 GLsizei range) { |
| 5795 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 5796 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDeletePathsCHROMIUM(" |
| 5797 << first_client_id << ", " << range << ")"); |
| 5798 static const char kFunctionName[] = "glDeletePathsCHROMIUM"; |
| 5799 |
| 5800 if (range < 0) { |
| 5801 SetGLError(GL_INVALID_VALUE, kFunctionName, "range < 0"); |
| 5802 return; |
| 5803 } |
| 5804 if (!base::IsValueInRangeForNumericType<int32_t>(range)) { |
| 5805 SetGLError(GL_INVALID_OPERATION, kFunctionName, "range more than 32-bit"); |
| 5806 return; |
| 5807 } |
| 5808 if (range == 0) |
| 5809 return; |
| 5810 |
| 5811 GLuint last_client_id; |
| 5812 if (!SafeAddUint32(first_client_id, range - 1, &last_client_id)) { |
| 5813 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow"); |
| 5814 return; |
| 5815 } |
| 5816 |
| 5817 GetRangeIdHandler(id_namespaces::kPaths) |
| 5818 ->FreeIdRange(this, first_client_id, range, |
| 5819 &GLES2Implementation::DeletePathsCHROMIUMStub); |
| 5820 CheckGLError(); |
| 5821 } |
| 5822 |
| 5823 void GLES2Implementation::DeletePathsCHROMIUMStub(GLuint first_client_id, |
| 5824 GLsizei range) { |
| 5825 helper_->DeletePathsCHROMIUM(first_client_id, range); |
| 5826 } |
| 5827 |
| 5828 void GLES2Implementation::PathCommandsCHROMIUM(GLuint path, |
| 5829 GLsizei num_commands, |
| 5830 const GLubyte* commands, |
| 5831 GLsizei num_coords, |
| 5832 GLenum coord_type, |
| 5833 const void* coords) { |
| 5834 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 5835 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glPathCommandsCHROMIUM(" << path |
| 5836 << ", " << num_commands << ", " << commands << ", " |
| 5837 << num_coords << ", " << coords << ")"); |
| 5838 static const char kFunctionName[] = "glPathCommandsCHROMIUM"; |
| 5839 if (path == 0) { |
| 5840 SetGLError(GL_INVALID_VALUE, kFunctionName, "invalid path object"); |
| 5841 return; |
| 5842 } |
| 5843 if (num_commands < 0) { |
| 5844 SetGLError(GL_INVALID_VALUE, kFunctionName, "numCommands < 0"); |
| 5845 return; |
| 5846 } |
| 5847 if (num_commands != 0 && !commands) { |
| 5848 SetGLError(GL_INVALID_VALUE, kFunctionName, "missing commands"); |
| 5849 return; |
| 5850 } |
| 5851 if (num_coords < 0) { |
| 5852 SetGLError(GL_INVALID_VALUE, kFunctionName, "numCoords < 0"); |
| 5853 return; |
| 5854 } |
| 5855 if (num_coords != 0 && !coords) { |
| 5856 SetGLError(GL_INVALID_VALUE, kFunctionName, "missing coords"); |
| 5857 return; |
| 5858 } |
| 5859 uint32 coord_type_size = GLES2Util::GetGLTypeSizeForPathCoordType(coord_type); |
| 5860 if (coord_type_size == 0) { |
| 5861 SetGLError(GL_INVALID_ENUM, kFunctionName, "invalid coordType"); |
| 5862 return; |
| 5863 } |
| 5864 if (num_commands == 0) { |
| 5865 // No commands must mean no coords, thus nothing to memcpy. Let |
| 5866 // the service validate the call. Validate coord_type above, so |
| 5867 // that the parameters will be checked the in the same order |
| 5868 // regardless of num_commands. |
| 5869 helper_->PathCommandsCHROMIUM(path, num_commands, 0, 0, num_coords, |
| 5870 coord_type, 0, 0); |
| 5871 CheckGLError(); |
| 5872 return; |
| 5873 } |
| 5874 |
| 5875 uint32 coords_size; |
| 5876 if (!SafeMultiplyUint32(num_coords, coord_type_size, &coords_size)) { |
| 5877 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow"); |
| 5878 return; |
| 5879 } |
| 5880 |
| 5881 uint32 required_buffer_size; |
| 5882 if (!SafeAddUint32(coords_size, num_commands, &required_buffer_size)) { |
| 5883 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow"); |
| 5884 return; |
| 5885 } |
| 5886 |
| 5887 ScopedTransferBufferPtr buffer(required_buffer_size, helper_, |
| 5888 transfer_buffer_); |
| 5889 if (!buffer.valid() || buffer.size() < required_buffer_size) { |
| 5890 SetGLError(GL_OUT_OF_MEMORY, kFunctionName, "too large"); |
| 5891 return; |
| 5892 } |
| 5893 |
| 5894 uint32 coords_shm_id = 0; |
| 5895 uint32 coords_shm_offset = 0; |
| 5896 // Copy coords first because they need more strict alignment. |
| 5897 if (coords_size > 0) { |
| 5898 unsigned char* coords_addr = static_cast<unsigned char*>(buffer.address()); |
| 5899 memcpy(coords_addr, coords, coords_size); |
| 5900 coords_shm_id = buffer.shm_id(); |
| 5901 coords_shm_offset = buffer.offset(); |
| 5902 } |
| 5903 |
| 5904 DCHECK(num_commands > 0); |
| 5905 unsigned char* commands_addr = |
| 5906 static_cast<unsigned char*>(buffer.address()) + coords_size; |
| 5907 memcpy(commands_addr, commands, num_commands); |
| 5908 |
| 5909 helper_->PathCommandsCHROMIUM(path, num_commands, buffer.shm_id(), |
| 5910 buffer.offset() + coords_size, num_coords, |
| 5911 coord_type, coords_shm_id, coords_shm_offset); |
| 5912 CheckGLError(); |
| 5913 } |
| 5914 |
5752 // Include the auto-generated part of this file. We split this because it means | 5915 // Include the auto-generated part of this file. We split this because it means |
5753 // we can easily edit the non-auto generated parts right here in this file | 5916 // we can easily edit the non-auto generated parts right here in this file |
5754 // instead of having to edit some template or the code generator. | 5917 // instead of having to edit some template or the code generator. |
5755 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 5918 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
5756 | 5919 |
5757 } // namespace gles2 | 5920 } // namespace gles2 |
5758 } // namespace gpu | 5921 } // namespace gpu |
OLD | NEW |