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 5508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5777 if (buf_size >= result->GetNumResults()) { | 5782 if (buf_size >= result->GetNumResults()) { |
5778 buf_size = result->GetNumResults(); | 5783 buf_size = result->GetNumResults(); |
5779 } | 5784 } |
5780 for (GLsizei ii = 0; ii < buf_size; ++ii) { | 5785 for (GLsizei ii = 0; ii < buf_size; ++ii) { |
5781 params[ii] = data[ii]; | 5786 params[ii] = data[ii]; |
5782 } | 5787 } |
5783 } | 5788 } |
5784 CheckGLError(); | 5789 CheckGLError(); |
5785 } | 5790 } |
5786 | 5791 |
| 5792 GLuint GLES2Implementation::GenPathsCHROMIUM(GLsizei range) { |
| 5793 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGenPathsCHROMIUM(" << range |
| 5794 << ")"); |
| 5795 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 5796 static const char kFunctionName[] = "glGenPathsCHROMIUM"; |
| 5797 if (range < 0) { |
| 5798 SetGLError(GL_INVALID_VALUE, kFunctionName, "range < 0"); |
| 5799 return 0; |
| 5800 } |
| 5801 if (!base::IsValueInRangeForNumericType<int32_t>(range)) { |
| 5802 SetGLError(GL_INVALID_OPERATION, kFunctionName, "range more than 32-bit"); |
| 5803 return 0; |
| 5804 } |
| 5805 if (range == 0) |
| 5806 return 0; |
| 5807 |
| 5808 GLuint first_client_id = 0; |
| 5809 GetRangeIdHandler(id_namespaces::kPaths) |
| 5810 ->MakeIdRange(this, range, &first_client_id); |
| 5811 |
| 5812 if (first_client_id == 0) { |
| 5813 // Ran out of id space. Is not specified to raise any gl errors. |
| 5814 return 0; |
| 5815 } |
| 5816 |
| 5817 helper_->GenPathsCHROMIUM(first_client_id, range); |
| 5818 |
| 5819 GPU_CLIENT_LOG_CODE_BLOCK({ |
| 5820 for (GLsizei i = 0; i < range; ++i) { |
| 5821 GPU_CLIENT_LOG(" " << i << ": " << (first_client_id + i)); |
| 5822 } |
| 5823 }); |
| 5824 CheckGLError(); |
| 5825 return first_client_id; |
| 5826 } |
| 5827 |
| 5828 void GLES2Implementation::DeletePathsCHROMIUM(GLuint first_client_id, |
| 5829 GLsizei range) { |
| 5830 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 5831 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDeletePathsCHROMIUM(" |
| 5832 << first_client_id << ", " << range << ")"); |
| 5833 static const char kFunctionName[] = "glDeletePathsCHROMIUM"; |
| 5834 |
| 5835 if (range < 0) { |
| 5836 SetGLError(GL_INVALID_VALUE, kFunctionName, "range < 0"); |
| 5837 return; |
| 5838 } |
| 5839 if (!base::IsValueInRangeForNumericType<int32_t>(range)) { |
| 5840 SetGLError(GL_INVALID_OPERATION, kFunctionName, "range more than 32-bit"); |
| 5841 return; |
| 5842 } |
| 5843 if (range == 0) |
| 5844 return; |
| 5845 |
| 5846 GLuint last_client_id; |
| 5847 if (!SafeAddUint32(first_client_id, range - 1, &last_client_id)) { |
| 5848 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow"); |
| 5849 return; |
| 5850 } |
| 5851 |
| 5852 GetRangeIdHandler(id_namespaces::kPaths) |
| 5853 ->FreeIdRange(this, first_client_id, range, |
| 5854 &GLES2Implementation::DeletePathsCHROMIUMStub); |
| 5855 CheckGLError(); |
| 5856 } |
| 5857 |
| 5858 void GLES2Implementation::DeletePathsCHROMIUMStub(GLuint first_client_id, |
| 5859 GLsizei range) { |
| 5860 helper_->DeletePathsCHROMIUM(first_client_id, range); |
| 5861 } |
| 5862 |
| 5863 void GLES2Implementation::PathCommandsCHROMIUM(GLuint path, |
| 5864 GLsizei num_commands, |
| 5865 const GLubyte* commands, |
| 5866 GLsizei num_coords, |
| 5867 GLenum coord_type, |
| 5868 const void* coords) { |
| 5869 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 5870 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glPathCommandsCHROMIUM(" << path |
| 5871 << ", " << num_commands << ", " << commands << ", " |
| 5872 << num_coords << ", " << coords << ")"); |
| 5873 static const char kFunctionName[] = "glPathCommandsCHROMIUM"; |
| 5874 if (path == 0) { |
| 5875 SetGLError(GL_INVALID_VALUE, kFunctionName, "invalid path object"); |
| 5876 return; |
| 5877 } |
| 5878 if (num_commands < 0) { |
| 5879 SetGLError(GL_INVALID_VALUE, kFunctionName, "numCommands < 0"); |
| 5880 return; |
| 5881 } |
| 5882 if (num_commands != 0 && !commands) { |
| 5883 SetGLError(GL_INVALID_VALUE, kFunctionName, "missing commands"); |
| 5884 return; |
| 5885 } |
| 5886 if (num_coords < 0) { |
| 5887 SetGLError(GL_INVALID_VALUE, kFunctionName, "numCoords < 0"); |
| 5888 return; |
| 5889 } |
| 5890 if (num_coords != 0 && !coords) { |
| 5891 SetGLError(GL_INVALID_VALUE, kFunctionName, "missing coords"); |
| 5892 return; |
| 5893 } |
| 5894 uint32 coord_type_size = GLES2Util::GetGLTypeSizeForPathCoordType(coord_type); |
| 5895 if (coord_type_size == 0) { |
| 5896 SetGLError(GL_INVALID_ENUM, kFunctionName, "invalid coordType"); |
| 5897 return; |
| 5898 } |
| 5899 if (num_commands == 0) { |
| 5900 // No commands must mean no coords, thus nothing to memcpy. Let |
| 5901 // the service validate the call. Validate coord_type above, so |
| 5902 // that the parameters will be checked the in the same order |
| 5903 // regardless of num_commands. |
| 5904 helper_->PathCommandsCHROMIUM(path, num_commands, 0, 0, num_coords, |
| 5905 coord_type, 0, 0); |
| 5906 CheckGLError(); |
| 5907 return; |
| 5908 } |
| 5909 |
| 5910 uint32 coords_size; |
| 5911 if (!SafeMultiplyUint32(num_coords, coord_type_size, &coords_size)) { |
| 5912 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow"); |
| 5913 return; |
| 5914 } |
| 5915 |
| 5916 uint32 required_buffer_size; |
| 5917 if (!SafeAddUint32(coords_size, num_commands, &required_buffer_size)) { |
| 5918 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow"); |
| 5919 return; |
| 5920 } |
| 5921 |
| 5922 ScopedTransferBufferPtr buffer(required_buffer_size, helper_, |
| 5923 transfer_buffer_); |
| 5924 if (!buffer.valid() || buffer.size() < required_buffer_size) { |
| 5925 SetGLError(GL_OUT_OF_MEMORY, kFunctionName, "too large"); |
| 5926 return; |
| 5927 } |
| 5928 |
| 5929 uint32 coords_shm_id = 0; |
| 5930 uint32 coords_shm_offset = 0; |
| 5931 // Copy coords first because they need more strict alignment. |
| 5932 if (coords_size > 0) { |
| 5933 unsigned char* coords_addr = static_cast<unsigned char*>(buffer.address()); |
| 5934 memcpy(coords_addr, coords, coords_size); |
| 5935 coords_shm_id = buffer.shm_id(); |
| 5936 coords_shm_offset = buffer.offset(); |
| 5937 } |
| 5938 |
| 5939 DCHECK(num_commands > 0); |
| 5940 unsigned char* commands_addr = |
| 5941 static_cast<unsigned char*>(buffer.address()) + coords_size; |
| 5942 memcpy(commands_addr, commands, num_commands); |
| 5943 |
| 5944 helper_->PathCommandsCHROMIUM(path, num_commands, buffer.shm_id(), |
| 5945 buffer.offset() + coords_size, num_coords, |
| 5946 coord_type, coords_shm_id, coords_shm_offset); |
| 5947 CheckGLError(); |
| 5948 } |
| 5949 |
5787 // Include the auto-generated part of this file. We split this because it means | 5950 // Include the auto-generated part of this file. We split this because it means |
5788 // we can easily edit the non-auto generated parts right here in this file | 5951 // we can easily edit the non-auto generated parts right here in this file |
5789 // instead of having to edit some template or the code generator. | 5952 // instead of having to edit some template or the code generator. |
5790 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 5953 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
5791 | 5954 |
5792 } // namespace gles2 | 5955 } // namespace gles2 |
5793 } // namespace gpu | 5956 } // namespace gpu |
OLD | NEW |