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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2082483002: Support line-continuation character in WebGL 2.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix line-continuation semantic Created 4 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
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 441
442 case InPreprocessorDirective: 442 case InPreprocessorDirective:
443 // No matter what the character is, just pass it 443 // No matter what the character is, just pass it
444 // through. Do not parse comments in this state. This 444 // through. Do not parse comments in this state. This
445 // might not be the right thing to do long term, but it 445 // might not be the right thing to do long term, but it
446 // should handle the #error preprocessor directive. 446 // should handle the #error preprocessor directive.
447 emit(c); 447 emit(c);
448 break; 448 break;
449 449
450 case InSingleLineComment: 450 case InSingleLineComment:
451 // Line-continuation characters are processed before comment processing.
452 // Advance string if a new line character is immediately behind
453 // line-continuation character.
454 if (c == '\\') {
455 if (peek(temp) && isNewline(temp))
Zhenyao Mo 2016/06/30 16:10:39 What if it's "\r\n"? Two characters but still one
Zhenyao Mo 2016/06/30 16:40:55 Never mind. It doesn't matter.
456 advance();
457 }
458
451 // The newline code at the top of this function takes care 459 // The newline code at the top of this function takes care
452 // of resetting our state when we get out of the 460 // of resetting our state when we get out of the
453 // single-line comment. Swallow all other characters. 461 // single-line comment. Swallow all other characters.
454 break; 462 break;
455 463
456 case InMultiLineComment: 464 case InMultiLineComment:
457 if (c == '*' && peek(temp) && temp == '/') { 465 if (c == '*' && peek(temp) && temp == '/') {
458 emit('*'); 466 emit('*');
459 emit('/'); 467 emit('/');
460 m_parseState = MiddleOfLine; 468 m_parseState = MiddleOfLine;
(...skipping 3388 matching lines...) Expand 10 before | Expand all | Expand 10 after
3849 if (isContextLost()) 3857 if (isContextLost())
3850 return; 3858 return;
3851 contextGL()->Scissor(x, y, width, height); 3859 contextGL()->Scissor(x, y, width, height);
3852 } 3860 }
3853 3861
3854 void WebGLRenderingContextBase::shaderSource(WebGLShader* shader, const String& string) 3862 void WebGLRenderingContextBase::shaderSource(WebGLShader* shader, const String& string)
3855 { 3863 {
3856 if (isContextLost() || !validateWebGLObject("shaderSource", shader)) 3864 if (isContextLost() || !validateWebGLObject("shaderSource", shader))
3857 return; 3865 return;
3858 String stringWithoutComments = StripComments(string).result(); 3866 String stringWithoutComments = StripComments(string).result();
3859 // TODO(danakj): Make validateString reject characters > 255 (or utf16 Strin gs) 3867 // TODO(danakj): Make validateShaderSource reject characters > 255 (or utf16 Strings)
3860 // so we don't need to use StringUTF8Adaptor. 3868 // so we don't need to use StringUTF8Adaptor.
3861 if (!validateString("shaderSource", stringWithoutComments)) 3869 if (!validateShaderSource(stringWithoutComments))
3862 return; 3870 return;
3863 shader->setSource(string); 3871 shader->setSource(string);
3864 WTF::StringUTF8Adaptor adaptor(stringWithoutComments); 3872 WTF::StringUTF8Adaptor adaptor(stringWithoutComments);
3865 const GLchar* shaderData = adaptor.data(); 3873 const GLchar* shaderData = adaptor.data();
3866 // TODO(danakj): Use base::saturated_cast<GLint>. 3874 // TODO(danakj): Use base::saturated_cast<GLint>.
3867 const GLint shaderLength = adaptor.length(); 3875 const GLint shaderLength = adaptor.length();
3868 contextGL()->ShaderSource(objectOrZero(shader), 1, &shaderData, &shaderLengt h); 3876 contextGL()->ShaderSource(objectOrZero(shader), 1, &shaderData, &shaderLengt h);
3869 } 3877 }
3870 3878
3871 void WebGLRenderingContextBase::stencilFunc(GLenum func, GLint ref, GLuint mask) 3879 void WebGLRenderingContextBase::stencilFunc(GLenum func, GLint ref, GLuint mask)
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
5462 { 5470 {
5463 for (size_t i = 0; i < string.length(); ++i) { 5471 for (size_t i = 0; i < string.length(); ++i) {
5464 if (!validateCharacter(string[i])) { 5472 if (!validateCharacter(string[i])) {
5465 synthesizeGLError(GL_INVALID_VALUE, functionName, "string not ASCII" ); 5473 synthesizeGLError(GL_INVALID_VALUE, functionName, "string not ASCII" );
5466 return false; 5474 return false;
5467 } 5475 }
5468 } 5476 }
5469 return true; 5477 return true;
5470 } 5478 }
5471 5479
5480 bool WebGLRenderingContextBase::validateShaderSource(const String& string)
5481 {
5482 for (size_t i = 0; i < string.length(); ++i) {
5483 // line-continuation character \ is supported in WebGL 2.0.
5484 if (isWebGL2OrHigher() && string[i] == '\\') {
5485 if (i + 1 >= string.length() || (string[i + 1] != '\n' && string[i + 1] != '\r')) {
5486 synthesizeGLError(GL_INVALID_VALUE, "shaderSource", "line-contin uation character is not immediately preceding a new-line");
Zhenyao Mo 2016/06/30 16:10:39 From reading the spec, I am not sure if it's an er
Ken Russell (switch to Gerrit) 2016/07/01 00:42:30 From my reading of the spec, the continuation char
qiankun 2016/07/01 10:32:01 Comments have already been removed before doing va
Zhenyao Mo 2016/07/01 16:53:50 Is this behavior (generating INVALID_VALUE if '\\'
5487 return false;
5488 }
5489 continue;
5490 }
5491 if (!validateCharacter(string[i])) {
5492 synthesizeGLError(GL_INVALID_VALUE, "shaderSource", "string not ASCI I");
5493 return false;
5494 }
5495 }
5496 return true;
5497 }
5498
5472 bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functio nName, TexImageFunctionType functionType, GLenum internalformat, GLenum format, GLenum type, GLint level) 5499 bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functio nName, TexImageFunctionType functionType, GLenum internalformat, GLenum format, GLenum type, GLint level)
5473 { 5500 {
5474 if (!m_isWebGL2FormatsTypesAdded && isWebGL2OrHigher()) { 5501 if (!m_isWebGL2FormatsTypesAdded && isWebGL2OrHigher()) {
5475 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsE S3); 5502 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsE S3);
5476 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsT exImageES3); 5503 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsT exImageES3);
5477 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES3); 5504 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES3);
5478 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES3); 5505 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES3);
5479 m_isWebGL2FormatsTypesAdded = true; 5506 m_isWebGL2FormatsTypesAdded = true;
5480 } 5507 }
5481 5508
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
6444 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); 6471 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
6445 } 6472 }
6446 6473
6447 void WebGLRenderingContextBase::restoreUnpackParameters() 6474 void WebGLRenderingContextBase::restoreUnpackParameters()
6448 { 6475 {
6449 if (m_unpackAlignment != 1) 6476 if (m_unpackAlignment != 1)
6450 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 6477 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
6451 } 6478 }
6452 6479
6453 } // namespace blink 6480 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698