Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

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

Powered by Google App Engine
This is Rietveld 408576698