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 "aemu/base/synchronization/Lock.h" 21 #include "ANGLEShaderParser.h" 22 #include "GLESv2Context.h" 23 #include <string> 24 #include <GLcommon/ShareGroup.h> 25 #include <unordered_set> 26 27 class ShaderParser : public ObjectData { 28 public: 29 ShaderParser(GLenum type, bool coreProfile); 30 ShaderParser(android::base::Stream* stream); 31 virtual void onSave(android::base::Stream* stream, unsigned int globalName) const override; 32 virtual void restore(ObjectLocalName localName, 33 const getGlobalName_t& getGlobalName) override; 34 void setSrc(GLsizei count, const GLchar* const* strings, 35 const GLint* length); 36 const std::string& getOriginalSrc() const; 37 const GLchar** parsedLines(); 38 void clear(); 39 GLenum getType(); 40 41 // Query whether the shader parsed is valid. 42 // Don't trust the value if we did not call setSrc 43 bool validShader() const; 44 45 const GLchar* getInfoLog() const; 46 void setInfoLog(GLchar * infoLog); 47 48 // If validation fails, add proper error messages 49 // to the parser's info log, which is treated 50 // as the actual info log from guest POV. 51 void setInvalidInfoLog(); 52 53 void setCompileStatus(bool val); getCompileStatus()54 bool getCompileStatus() const { return m_compileStatus; } 55 setDeleteStatus(bool val)56 void setDeleteStatus(bool val) { m_deleteStatus = val; } getDeleteStatus()57 bool getDeleteStatus() const { return m_deleteStatus; } 58 59 void attachProgram(GLuint program); 60 void detachProgram(GLuint program); 61 bool hasAttachedPrograms() const; 62 63 #ifdef USE_ANGLE_SHADER_PARSER getShaderLinkInfo()64 const ANGLEShaderParser::ShaderLinkInfo& getShaderLinkInfo() const { return m_shaderLinkInfo; } shaderLinkInfoPtr()65 ANGLEShaderParser::ShaderLinkInfo* shaderLinkInfoPtr() { return &m_shaderLinkInfo; } 66 #endif 67 68 virtual GenNameInfo getGenNameInfo() const override; getCompiledSrc()69 const char* getCompiledSrc() const { return m_compiledSrc.c_str(); } 70 71 private: 72 void convertESSLToGLSL(); 73 74 std::string m_originalSrc; 75 std::string m_src; 76 std::string m_parsedSrc; 77 GLchar* m_parsedLines = nullptr; 78 std::string m_compiledSrc; 79 std::basic_string<GLchar> m_infoLog; 80 mutable android::base::Lock m_programsLock; 81 std::unordered_set<GLuint> m_programs; 82 GLenum m_type = 0; 83 bool m_compileStatus = false; 84 bool m_deleteStatus = false; 85 bool m_valid = true; 86 #ifdef USE_ANGLE_SHADER_PARSER 87 ANGLEShaderParser::ShaderLinkInfo m_shaderLinkInfo; 88 #endif 89 bool m_coreProfile = false; 90 }; 91 #endif 92