From: David Steele Date: Wed, 14 Apr 2021 11:37:02 +0000 (+0100) Subject: Ensured GL calls are not made after EGL Shutdown X-Git-Tag: dali_2.0.26~6^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F98%2F258098%2F1;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Ensured GL calls are not made after EGL Shutdown Change-Id: I70005692526475ad2db02ae30f0fb88a13eb1c86 --- diff --git a/dali/internal/graphics/gles-impl/gles-graphics-program.cpp b/dali/internal/graphics/gles-impl/gles-graphics-program.cpp index 484f400..64de708 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-program.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-program.cpp @@ -82,8 +82,14 @@ bool ProgramImpl::Destroy() bool ProgramImpl::Create() { // Create and link new program - auto& gl = *mImpl->controller.GetGL(); - auto program = gl.CreateProgram(); + auto gl = mImpl->controller.GetGL(); + if(!gl) + { + // Do nothing during shutdown + return false; + } + + auto program = gl->CreateProgram(); const auto& info = mImpl->createInfo; for(const auto& state : *info.shaderState) @@ -93,23 +99,23 @@ bool ProgramImpl::Create() // Compile shader first (ignored when compiled) if(shader->Compile()) { - gl.AttachShader(program, shader->GetGLShader()); + gl->AttachShader(program, shader->GetGLShader()); } } - gl.LinkProgram(program); + gl->LinkProgram(program); GLint status{0}; - gl.GetProgramiv(program, GL_LINK_STATUS, &status); + gl->GetProgramiv(program, GL_LINK_STATUS, &status); if(status != GL_TRUE) { char output[4096]; GLsizei size{0u}; - gl.GetProgramInfoLog(program, 4096, &size, output); + gl->GetProgramInfoLog(program, 4096, &size, output); // log on error // TODO: un-printf-it printf("Log: %s\n", output); - gl.DeleteProgram(program); + gl->DeleteProgram(program); return false; } diff --git a/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp b/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp index 20be64f..86a26b7 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp @@ -16,6 +16,8 @@ */ #include "gles-graphics-reflection.h" + +#include #include #include @@ -114,6 +116,11 @@ void Reflection::BuildVertexAttributeReflection() char* name; auto gl = mController.GetGL(); + if(!gl) + { + // Do nothing during shutdown + return; + } gl->GetProgramiv(glProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxLength); gl->GetProgramiv(glProgram, GL_ACTIVE_ATTRIBUTES, &nAttribs); @@ -149,6 +156,11 @@ void Reflection::BuildUniformReflection() int numUniforms = 0; auto gl = mController.GetGL(); + if(!gl) + { + // Do nothing during shutdown + return; + } gl->GetProgramiv(glProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLen); gl->GetProgramiv(glProgram, GL_ACTIVE_UNIFORMS, &numUniforms); @@ -253,6 +265,13 @@ void Reflection::BuildUniformBlockReflection() auto gl = mController.GetGL(); auto glProgram = mProgram.GetGlProgram(); int numUniformBlocks = 0; + + if(!gl) + { + // Do nothing during shutdown + return; + } + gl->GetProgramiv(glProgram, GL_ACTIVE_UNIFORM_BLOCKS, &numUniformBlocks); mUniformBlocks.clear(); @@ -514,17 +533,24 @@ std::vector Reflection::GetSamplers() const Graphics::ShaderLanguage Reflection::GetLanguage() const { + auto version = Graphics::ShaderLanguage::GLSL_3_2; + auto gl = mController.GetGL(); + if(!gl) + { + // Do nothing during shutdown + return version; + } int majorVersion, minorVersion; gl->GetIntegerv(GL_MAJOR_VERSION, &majorVersion); gl->GetIntegerv(GL_MINOR_VERSION, &minorVersion); - printf("GL Version (integer) : %d.%d\n", majorVersion, minorVersion); - printf("GLSL Version : %s\n", gl->GetString(GL_SHADING_LANGUAGE_VERSION)); + DALI_LOG_RELEASE_INFO("GL Version (integer) : %d.%d\n", majorVersion, minorVersion); + DALI_LOG_RELEASE_INFO("GLSL Version : %s\n", gl->GetString(GL_SHADING_LANGUAGE_VERSION)); // TODO: the language version is hardcoded for now, but we may use what we get // from GL_SHADING_LANGUAGE_VERSION? - return Graphics::ShaderLanguage::GLSL_3_2; + return version; } } // namespace Dali::Graphics::GLES diff --git a/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp b/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp index 46a2968..60f9a34 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp @@ -19,6 +19,7 @@ #include "gles-graphics-shader.h" // INTERNAL INCLUDES +#include #include "egl-graphics-controller.h" namespace Dali::Graphics::GLES @@ -52,7 +53,13 @@ Shader::~Shader() = default; bool Shader::Compile() const { - auto& gl = *GetController().GetGL(); + auto gl = GetController().GetGL(); + + if(!gl) + { + return false; + } + if(!mImpl->glShader) { GLenum pipelineStage{0u}; @@ -96,22 +103,22 @@ bool Shader::Compile() const if(pipelineStage) { - auto shader = gl.CreateShader(pipelineStage); + auto shader = gl->CreateShader(pipelineStage); const auto src = reinterpret_cast(GetCreateInfo().sourceData); GLint size = GetCreateInfo().sourceSize; - gl.ShaderSource(shader, 1, const_cast(&src), &size); - gl.CompileShader(shader); + gl->ShaderSource(shader, 1, const_cast(&src), &size); + gl->CompileShader(shader); GLint status{0}; - gl.GetShaderiv(shader, GL_COMPILE_STATUS, &status); + gl->GetShaderiv(shader, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) { char output[4096]; GLsizei size{0u}; - gl.GetShaderInfoLog(shader, 4096, &size, output); - printf("Code: %s\n", reinterpret_cast(GetCreateInfo().sourceData)); - printf("Log: %s\n", output); - gl.DeleteShader(shader); + gl->GetShaderInfoLog(shader, 4096, &size, output); + DALI_LOG_RELEASE_INFO("Code: %s\n", reinterpret_cast(GetCreateInfo().sourceData)); + DALI_LOG_RELEASE_INFO("Log: %s\n", output); + gl->DeleteShader(shader); return false; } @@ -146,4 +153,4 @@ void Shader::DiscardResource() GetController().DiscardResource(this); } -} // namespace Dali::Graphics::GLES \ No newline at end of file +} // namespace Dali::Graphics::GLES diff --git a/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp b/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp index 738e02c..cf91080 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-texture.cpp @@ -73,6 +73,12 @@ bool Texture::InitializeNativeImage() auto gl = mController.GetGL(); GLuint texture{0}; + if(!gl) + { + // Do nothing during shutdown + return false; + } + NativeImageInterfacePtr nativeImage = mCreateInfo.nativeImagePtr; bool created = nativeImage->CreateResource(); mGlTarget = nativeImage->GetTextureTarget(); @@ -113,6 +119,11 @@ bool Texture::InitializeNativeImage() bool Texture::InitializeTexture() { auto gl = mController.GetGL(); + if(!gl) + { + // Do nothing during shutdown + return false; + } GLuint texture{0}; @@ -189,6 +200,11 @@ void Texture::DiscardResource() void Texture::Bind(const TextureBinding& binding) const { auto gl = mController.GetGL(); + if(!gl) + { + // Do nothing during shutdown + return; + } gl->ActiveTexture(GL_TEXTURE0 + binding.binding); gl->BindTexture(mGlTarget, mTextureId);