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

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: fix windows build Created 5 years, 5 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/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 248 }
249 249
250 GLES2CmdHelper* GLES2Implementation::helper() const { 250 GLES2CmdHelper* GLES2Implementation::helper() const {
251 return helper_; 251 return helper_;
252 } 252 }
253 253
254 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { 254 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const {
255 return share_group_->GetIdHandler(namespace_id); 255 return share_group_->GetIdHandler(namespace_id);
256 } 256 }
257 257
258 RangeIdHandlerInterface* GLES2Implementation::GetRangeIdHandler(
259 int namespace_id) const {
260 return share_group_->GetRangeIdHandler(namespace_id);
261 }
262
258 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { 263 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const {
259 if (namespace_id == id_namespaces::kQueries) 264 if (namespace_id == id_namespaces::kQueries)
260 return query_id_allocator_.get(); 265 return query_id_allocator_.get();
261 NOTREACHED(); 266 NOTREACHED();
262 return NULL; 267 return NULL;
263 } 268 }
264 269
265 void* GLES2Implementation::GetResultBuffer() { 270 void* GLES2Implementation::GetResultBuffer() {
266 return transfer_buffer_->GetResultBuffer(); 271 return transfer_buffer_->GetResultBuffer();
267 } 272 }
(...skipping 5549 matching lines...) Expand 10 before | Expand all | Expand 10 after
5817 if (buf_size >= result->GetNumResults()) { 5822 if (buf_size >= result->GetNumResults()) {
5818 buf_size = result->GetNumResults(); 5823 buf_size = result->GetNumResults();
5819 } 5824 }
5820 for (GLsizei ii = 0; ii < buf_size; ++ii) { 5825 for (GLsizei ii = 0; ii < buf_size; ++ii) {
5821 params[ii] = data[ii]; 5826 params[ii] = data[ii];
5822 } 5827 }
5823 } 5828 }
5824 CheckGLError(); 5829 CheckGLError();
5825 } 5830 }
5826 5831
5832 GLuint GLES2Implementation::GenPathsCHROMIUM(GLsizei range) {
5833 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGenPathsCHROMIUM(" << range
5834 << ")");
5835 GPU_CLIENT_SINGLE_THREAD_CHECK();
5836 static const char kFunctionName[] = "glGenPathsCHROMIUM";
5837 if (range < 0) {
5838 SetGLError(GL_INVALID_VALUE, kFunctionName, "range < 0");
5839 return 0;
5840 }
5841 if (!base::IsValueInRangeForNumericType<int32_t>(range)) {
5842 SetGLError(GL_INVALID_OPERATION, kFunctionName, "range more than 32-bit");
5843 return 0;
5844 }
5845 if (range == 0)
5846 return 0;
5847
5848 GLuint first_client_id = 0;
5849 GetRangeIdHandler(id_namespaces::kPaths)
5850 ->MakeIdRange(this, range, &first_client_id);
5851
5852 if (first_client_id == 0) {
5853 // Ran out of id space. Is not specified to raise any gl errors.
5854 return 0;
5855 }
5856
5857 helper_->GenPathsCHROMIUM(first_client_id, range);
5858
5859 GPU_CLIENT_LOG_CODE_BLOCK({
5860 for (GLsizei i = 0; i < range; ++i) {
5861 GPU_CLIENT_LOG(" " << i << ": " << (first_client_id + i));
5862 }
5863 });
5864 CheckGLError();
5865 return first_client_id;
5866 }
5867
5868 void GLES2Implementation::DeletePathsCHROMIUM(GLuint first_client_id,
5869 GLsizei range) {
5870 GPU_CLIENT_SINGLE_THREAD_CHECK();
5871 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDeletePathsCHROMIUM("
5872 << first_client_id << ", " << range << ")");
5873 static const char kFunctionName[] = "glDeletePathsCHROMIUM";
5874
5875 if (range < 0) {
5876 SetGLError(GL_INVALID_VALUE, kFunctionName, "range < 0");
5877 return;
5878 }
5879 if (!base::IsValueInRangeForNumericType<int32_t>(range)) {
5880 SetGLError(GL_INVALID_OPERATION, kFunctionName, "range more than 32-bit");
5881 return;
5882 }
5883 if (range == 0)
5884 return;
5885
5886 GLuint last_client_id;
5887 if (!SafeAddUint32(first_client_id, range - 1, &last_client_id)) {
5888 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow");
5889 return;
5890 }
5891
5892 GetRangeIdHandler(id_namespaces::kPaths)
5893 ->FreeIdRange(this, first_client_id, range,
5894 &GLES2Implementation::DeletePathsCHROMIUMStub);
5895 CheckGLError();
5896 }
5897
5898 void GLES2Implementation::DeletePathsCHROMIUMStub(GLuint first_client_id,
5899 GLsizei range) {
5900 helper_->DeletePathsCHROMIUM(first_client_id, range);
5901 }
5902
5903 void GLES2Implementation::PathCommandsCHROMIUM(GLuint path,
5904 GLsizei num_commands,
5905 const GLubyte* commands,
5906 GLsizei num_coords,
5907 GLenum coord_type,
5908 const void* coords) {
5909 GPU_CLIENT_SINGLE_THREAD_CHECK();
5910 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glPathCommandsCHROMIUM(" << path
5911 << ", " << num_commands << ", " << commands << ", "
5912 << num_coords << ", " << coords << ")");
5913 static const char kFunctionName[] = "glPathCommandsCHROMIUM";
5914 if (path == 0) {
5915 SetGLError(GL_INVALID_VALUE, kFunctionName, "invalid path object");
5916 return;
5917 }
5918 if (num_commands < 0) {
5919 SetGLError(GL_INVALID_VALUE, kFunctionName, "numCommands < 0");
5920 return;
5921 }
5922 if (num_commands != 0 && !commands) {
5923 SetGLError(GL_INVALID_VALUE, kFunctionName, "missing commands");
5924 return;
5925 }
5926 if (num_coords < 0) {
5927 SetGLError(GL_INVALID_VALUE, kFunctionName, "numCoords < 0");
5928 return;
5929 }
5930 if (num_coords != 0 && !coords) {
5931 SetGLError(GL_INVALID_VALUE, kFunctionName, "missing coords");
5932 return;
5933 }
5934 uint32 coord_type_size = GLES2Util::GetGLTypeSizeForPathCoordType(coord_type);
5935 if (coord_type_size == 0) {
5936 SetGLError(GL_INVALID_ENUM, kFunctionName, "invalid coordType");
5937 return;
5938 }
5939 if (num_commands == 0) {
5940 // No commands must mean no coords, thus nothing to memcpy. Let
5941 // the service validate the call. Validate coord_type above, so
5942 // that the parameters will be checked the in the same order
5943 // regardless of num_commands.
5944 helper_->PathCommandsCHROMIUM(path, num_commands, 0, 0, num_coords,
5945 coord_type, 0, 0);
5946 CheckGLError();
5947 return;
5948 }
5949
5950 uint32 coords_size;
5951 if (!SafeMultiplyUint32(num_coords, coord_type_size, &coords_size)) {
5952 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow");
5953 return;
5954 }
5955
5956 uint32 required_buffer_size;
5957 if (!SafeAddUint32(coords_size, num_commands, &required_buffer_size)) {
5958 SetGLError(GL_INVALID_OPERATION, kFunctionName, "overflow");
5959 return;
5960 }
5961
5962 ScopedTransferBufferPtr buffer(required_buffer_size, helper_,
5963 transfer_buffer_);
5964 if (!buffer.valid() || buffer.size() < required_buffer_size) {
5965 SetGLError(GL_OUT_OF_MEMORY, kFunctionName, "too large");
5966 return;
5967 }
5968
5969 uint32 coords_shm_id = 0;
5970 uint32 coords_shm_offset = 0;
5971 // Copy coords first because they need more strict alignment.
5972 if (coords_size > 0) {
5973 unsigned char* coords_addr = static_cast<unsigned char*>(buffer.address());
5974 memcpy(coords_addr, coords, coords_size);
5975 coords_shm_id = buffer.shm_id();
5976 coords_shm_offset = buffer.offset();
5977 }
5978
5979 DCHECK(num_commands > 0);
5980 unsigned char* commands_addr =
5981 static_cast<unsigned char*>(buffer.address()) + coords_size;
5982 memcpy(commands_addr, commands, num_commands);
5983
5984 helper_->PathCommandsCHROMIUM(path, num_commands, buffer.shm_id(),
5985 buffer.offset() + coords_size, num_coords,
5986 coord_type, coords_shm_id, coords_shm_offset);
5987 CheckGLError();
5988 }
5989
5827 // Include the auto-generated part of this file. We split this because it means 5990 // Include the auto-generated part of this file. We split this because it means
5828 // we can easily edit the non-auto generated parts right here in this file 5991 // we can easily edit the non-auto generated parts right here in this file
5829 // instead of having to edit some template or the code generator. 5992 // instead of having to edit some template or the code generator.
5830 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" 5993 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h"
5831 5994
5832 } // namespace gles2 5995 } // namespace gles2
5833 } // namespace gpu 5996 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.h ('k') | gpu/command_buffer/client/gles2_implementation_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698