1 /* 2 * Copyright 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SHADER_PARSER_H 18 #define SHADER_PARSER_H 19 20 #include "ANGLEShaderParser.h" 21 #include "GLESv2Context.h" 22 #include <string> 23 #include <GLcommon/ShareGroup.h> 24 #include <unordered_set> 25 26 class ShaderParser : public ObjectData { 27 public: 28 ShaderParser(GLenum type, bool coreProfile); 29 ShaderParser(android::base::Stream* stream); 30 virtual void onSave(android::base::Stream* stream, unsigned int globalName) const override; 31 virtual void restore(ObjectLocalName localName, 32 const getGlobalName_t& getGlobalName) override; 33 void setSrc(GLsizei count, const GLchar* const* strings, 34 const GLint* length); 35 const std::string& getOriginalSrc() const; 36 const GLchar** parsedLines(); 37 void clear(); 38 GLenum getType(); 39 40 // Query whether the shader parsed is valid. 41 // Don't trust the value if we did not call setSrc 42 bool validShader() const; 43 44 const GLchar* getInfoLog() const; 45 void setInfoLog(GLchar * infoLog); 46 47 // If validation fails, add proper error messages 48 // to the parser's info log, which is treated 49 // as the actual info log from guest POV. 50 void setInvalidInfoLog(); 51 52 void setCompileStatus(bool val); getCompileStatus()53 bool getCompileStatus() const { return m_compileStatus; } 54 setDeleteStatus(bool val)55 void setDeleteStatus(bool val) { m_deleteStatus = val; } getDeleteStatus()56 bool getDeleteStatus() const { return m_deleteStatus; } 57 attachProgram(GLuint program)58 void attachProgram(GLuint program) {m_programs.insert(program);} detachProgram(GLuint program)59 void detachProgram(GLuint program) {m_programs.erase(program);} hasAttachedPrograms()60 bool hasAttachedPrograms() const {return m_programs.size()>0;} 61 getShaderLinkInfo()62 const ANGLEShaderParser::ShaderLinkInfo& getShaderLinkInfo() const { return m_shaderLinkInfo; } shaderLinkInfoPtr()63 ANGLEShaderParser::ShaderLinkInfo* shaderLinkInfoPtr() { return &m_shaderLinkInfo; } 64 65 virtual GenNameInfo getGenNameInfo() const override; getCompiledSrc()66 const char* getCompiledSrc() const { return m_compiledSrc.c_str(); } 67 68 private: 69 void convertESSLToGLSL(); 70 71 std::string m_originalSrc; 72 std::string m_src; 73 std::string m_parsedSrc; 74 GLchar* m_parsedLines = nullptr; 75 std::string m_compiledSrc; 76 std::basic_string<GLchar> m_infoLog; 77 std::unordered_set<GLuint> m_programs; 78 GLenum m_type = 0; 79 bool m_compileStatus = false; 80 bool m_deleteStatus = false; 81 bool m_valid = true; 82 ANGLEShaderParser::ShaderLinkInfo m_shaderLinkInfo; 83 bool m_coreProfile = false; 84 }; 85 #endif 86