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

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

Powered by Google App Engine
This is Rietveld 408576698