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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 } | 250 } |
251 | 251 |
252 GLES2CmdHelper* GLES2Implementation::helper() const { | 252 GLES2CmdHelper* GLES2Implementation::helper() const { |
253 return helper_; | 253 return helper_; |
254 } | 254 } |
255 | 255 |
256 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { | 256 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { |
257 return share_group_->GetIdHandler(namespace_id); | 257 return share_group_->GetIdHandler(namespace_id); |
258 } | 258 } |
259 | 259 |
260 RangeIdHandlerInterface* GLES2Implementation::GetRangeIdHandler( | |
261 int namespace_id) const { | |
262 return share_group_->GetRangeIdHandler(namespace_id); | |
263 } | |
264 | |
260 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { | 265 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { |
261 if (namespace_id == id_namespaces::kQueries) | 266 if (namespace_id == id_namespaces::kQueries) |
262 return query_id_allocator_.get(); | 267 return query_id_allocator_.get(); |
263 NOTREACHED(); | 268 NOTREACHED(); |
264 return NULL; | 269 return NULL; |
265 } | 270 } |
266 | 271 |
267 void* GLES2Implementation::GetResultBuffer() { | 272 void* GLES2Implementation::GetResultBuffer() { |
268 return transfer_buffer_->GetResultBuffer(); | 273 return transfer_buffer_->GetResultBuffer(); |
269 } | 274 } |
(...skipping 5515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5785 if (buf_size >= result->GetNumResults()) { | 5790 if (buf_size >= result->GetNumResults()) { |
5786 buf_size = result->GetNumResults(); | 5791 buf_size = result->GetNumResults(); |
5787 } | 5792 } |
5788 for (GLsizei ii = 0; ii < buf_size; ++ii) { | 5793 for (GLsizei ii = 0; ii < buf_size; ++ii) { |
5789 params[ii] = data[ii]; | 5794 params[ii] = data[ii]; |
5790 } | 5795 } |
5791 } | 5796 } |
5792 CheckGLError(); | 5797 CheckGLError(); |
5793 } | 5798 } |
5794 | 5799 |
5800 GLuint GLES2Implementation::GenPathsCHROMIUM(GLsizei range) { | |
5801 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGenPathsCHROMIUM(" << range | |
5802 << ")"); | |
5803 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
5804 | |
5805 if (range < 0) { | |
5806 SetGLError(GL_INVALID_VALUE, "glGenPathsCHROMIUM", "range < 0"); | |
5807 return 0; | |
5808 } | |
5809 if (!base::IsValueInRangeForNumericType<int32_t>(range)) { | |
5810 SetGLError(GL_INVALID_VALUE, "glGenPathsCHROMIUM", | |
5811 "range more than 32-bit"); | |
5812 return 0; | |
5813 } | |
5814 | |
5815 if (range == 0) { | |
5816 return 0; | |
5817 } | |
5818 | |
5819 GLuint first_client_id = 0; | |
5820 GetRangeIdHandler(id_namespaces::kPaths) | |
5821 ->MakeIdRange(this, range, &first_client_id); | |
5822 | |
5823 if (first_client_id == 0) { | |
5824 // Ran out of id space. Is not specified to raise any gl errors. | |
5825 return 0; | |
5826 } | |
5827 | |
5828 helper_->GenPathsCHROMIUM(first_client_id, range); | |
5829 | |
5830 GPU_CLIENT_LOG_CODE_BLOCK({ | |
5831 for (GLsizei i = 0; i < range; ++i) { | |
5832 GPU_CLIENT_LOG(" " << i << ": " << (first_client_id + i)); | |
5833 } | |
5834 }); | |
5835 CheckGLError(); | |
5836 return first_client_id; | |
5837 } | |
5838 | |
5839 void GLES2Implementation::DeletePathsCHROMIUM(GLuint first_client_id, | |
5840 GLsizei range) { | |
5841 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
5842 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDeletePathsCHROMIUM(" | |
5843 << first_client_id << ", " << range << ")"); | |
5844 | |
5845 if (range < 0) { | |
5846 SetGLError(GL_INVALID_VALUE, "glDeletePathsCHROMIUM", "range < 0"); | |
5847 return; | |
5848 } | |
5849 | |
5850 if (!base::IsValueInRangeForNumericType<int32_t>(range)) { | |
vmiura
2015/06/19 21:55:21
Should there be an error if (first_client_id + ran
Kimmo Kinnunen
2015/06/23 12:03:10
Done.
| |
5851 SetGLError(GL_INVALID_VALUE, "glGenPathsCHROMIUM", | |
5852 "range more than 32-bit"); | |
5853 return; | |
5854 } | |
5855 | |
5856 if (range == 0) { | |
5857 return; | |
5858 } | |
5859 | |
5860 GetRangeIdHandler(id_namespaces::kPaths) | |
5861 ->FreeIdRange(this, first_client_id, range, | |
5862 &GLES2Implementation::DeletePathsCHROMIUMStub); | |
5863 // Deleting non-existing paths does not produce errors in the extension. | |
5864 } | |
5865 | |
5866 void GLES2Implementation::DeletePathsCHROMIUMStub(GLuint first_client_id, | |
5867 GLsizei range) { | |
5868 helper_->DeletePathsCHROMIUM(first_client_id, range); | |
5869 } | |
5870 | |
5871 void GLES2Implementation::PathCommandsCHROMIUM(GLuint path, | |
5872 GLsizei num_commands, | |
5873 const GLubyte* commands, | |
5874 GLsizei num_coords, | |
5875 GLenum coord_type, | |
5876 const void* coords) { | |
5877 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
5878 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glPathCommandsCHROMIUM(" << path | |
5879 << ", " << num_commands << ", " << commands << ", " | |
5880 << num_coords << ", " << coords << ")"); | |
5881 if (path == 0) { | |
5882 SetGLError(GL_INVALID_VALUE, "glPathCommandsCHROMIUM", | |
5883 "invalid path object"); | |
5884 return; | |
5885 } | |
5886 if (num_commands < 0) { | |
5887 SetGLError(GL_INVALID_VALUE, "glPathCommandsCHROMIUM", "numCommands < 0"); | |
5888 return; | |
5889 } | |
5890 if (num_commands != 0 && !commands) { | |
5891 SetGLError(GL_INVALID_VALUE, "glPathCommandsCHROMIUM", "missing commands"); | |
5892 return; | |
5893 } | |
5894 if (num_coords < 0) { | |
5895 SetGLError(GL_INVALID_VALUE, "glPathCommandsCHROMIUM", "numCoords < 0"); | |
5896 return; | |
5897 } | |
5898 uint32 coord_type_size = GLES2Util::GetGLTypeSizeForPathCoordType(coord_type); | |
5899 if (coord_type_size == 0) { | |
5900 SetGLError(GL_INVALID_ENUM, "glPathCommandsCHROMIUM", "invalid coordType"); | |
5901 return; | |
5902 } | |
5903 if (num_coords != 0 && !coords) { | |
5904 SetGLError(GL_INVALID_VALUE, "glPathCommandsCHROMIUM", "missing coords"); | |
5905 return; | |
5906 } | |
5907 if (num_commands == 0 && num_coords == 0) { | |
5908 helper_->PathCommandsCHROMIUM(path, 0, 0, 0, 0, GL_FLOAT, 0, 0); | |
5909 return; | |
5910 } | |
5911 | |
5912 uint32 coords_size = coord_type_size * num_coords; | |
vmiura
2015/06/19 21:55:21
if (!SafeMultiplyUint32(width, bytes_per_group, &c
Kimmo Kinnunen
2015/06/23 12:03:10
Done.
| |
5913 | |
5914 ScopedTransferBufferPtr buffer(coords_size + num_commands, helper_, | |
vmiura
2015/06/19 21:55:22
SafeAddUInt32 for "coords_size + num_commands".
Kimmo Kinnunen
2015/06/23 12:03:10
Done.
| |
5915 transfer_buffer_); | |
5916 if (!buffer.valid() || buffer.size() < coords_size + num_commands) { | |
5917 SetGLError(GL_INVALID_VALUE, "glPathCommandsCHROMIUM", | |
5918 "no room in transfer buffer for coords and commands"); | |
5919 return; | |
5920 } | |
5921 | |
5922 // Copy coords first because they need more strict alignment. | |
5923 unsigned char* coords_addr = static_cast<unsigned char*>(buffer.address()); | |
5924 memcpy(coords_addr, coords, coords_size); | |
vmiura
2015/06/19 21:55:22
Memcpy from NULL pointer is undefined behavior I b
Kimmo Kinnunen
2015/06/23 12:03:10
Done.
| |
5925 | |
5926 unsigned char* commands_addr = | |
5927 static_cast<unsigned char*>(buffer.address()) + coords_size; | |
5928 memcpy(commands_addr, commands, num_commands); | |
vmiura
2015/06/19 21:55:21
Same here
if (num_commands > 0)
memcpy(...)
Kimmo Kinnunen
2015/06/23 12:03:10
Done.
| |
5929 helper_->PathCommandsCHROMIUM(path, num_commands, buffer.shm_id(), | |
5930 buffer.offset() + coords_size, num_coords, | |
5931 coord_type, buffer.shm_id(), buffer.offset()); | |
5932 CheckGLError(); | |
5933 } | |
5934 | |
5795 // Include the auto-generated part of this file. We split this because it means | 5935 // Include the auto-generated part of this file. We split this because it means |
5796 // we can easily edit the non-auto generated parts right here in this file | 5936 // we can easily edit the non-auto generated parts right here in this file |
5797 // instead of having to edit some template or the code generator. | 5937 // instead of having to edit some template or the code generator. |
5798 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 5938 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
5799 | 5939 |
5800 } // namespace gles2 | 5940 } // namespace gles2 |
5801 } // namespace gpu | 5941 } // namespace gpu |
OLD | NEW |