Add tests for creation of EGLImages from one component textures.
authorTobias Sargeant <tobiasjs@google.com>
Wed, 26 Aug 2015 11:14:57 +0000 (12:14 +0100)
committerTobias Sargeant <tobiasjs@google.com>
Wed, 2 Sep 2015 11:39:26 +0000 (12:39 +0100)
One component textures are used by WebView for for passing YUV12
frames between threads.

Change-Id: I206bed24a2428e2289b468ec06b88ec1bb53af9d

framework/opengl/gluRenderContext.cpp
framework/opengl/gluRenderContext.hpp
modules/egl/teglCreateContextExtTests.cpp
modules/egl/teglImageFormatTests.cpp
modules/egl/teglImageTests.cpp
modules/egl/teglImageUtil.cpp
modules/egl/teglImageUtil.hpp

index 9e4f9ec..2580647 100644 (file)
@@ -33,6 +33,7 @@
 #include "tcuPlatform.hpp"
 #include "tcuCommandLine.hpp"
 #include "deStringUtil.hpp"
+#include "deSTLUtil.hpp"
 
 namespace glu
 {
@@ -223,6 +224,13 @@ static std::vector<std::string> getExtensions (const glw::Functions& gl, ApiType
        }
 }
 
+bool hasExtension (const glw::Functions& gl, ApiType apiType, const std::string& extension)
+{
+       std::vector<std::string> extensions(getExtensions(gl, apiType));
+
+       return de::contains(extensions.begin(), extensions.end(), extension);
+}
+
 void initCoreFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType)
 {
        static const struct
index ed067e4..d4731b0 100644 (file)
@@ -228,6 +228,8 @@ void                                initExtensionFunctions                  (glw::Functions* dst, const glw::FunctionLoader
 void                           initFunctions                                   (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType);
 void                           initExtensionFunctions                  (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType);
 
+bool                           hasExtension                                    (const glw::Functions& gl, ApiType apiType, const std::string& extension);
+
 } // glu
 
 #endif // _GLURENDERCONTEXT_HPP
index 17eb2aa..5253926 100644 (file)
@@ -438,20 +438,6 @@ void CreateContextExtCase::checkRequiredExtensions (void)
                TCU_THROW(NotSupportedError, "Required extensions not supported");
 }
 
-bool hasExtension (const glw::Functions& gl, const char* extension)
-{
-       std::istringstream      stream((const char*)gl.getString(GL_EXTENSIONS));
-       string                          ext;
-
-       while (std::getline(stream, ext, ' '))
-       {
-               if (ext == extension)
-                       return true;
-       }
-
-       return false;
-}
-
 bool checkVersionString (TestLog& log, const glw::Functions& gl, bool desktop, int major, int minor)
 {
        const char* const       versionStr      = (const char*)gl.getString(GL_VERSION);
@@ -568,7 +554,7 @@ bool checkVersionString (TestLog& log, const glw::Functions& gl, bool desktop, i
                {
                        if (majorVersion == 3 && minorVersion == 1)
                        {
-                               if (hasExtension(gl, "GL_ARB_compatibility"))
+                               if (glu::hasExtension(gl, glu::ApiType::core(3, 1), "GL_ARB_compatibility"))
                                        return true;
                                else
                                {
@@ -841,7 +827,7 @@ bool CreateContextExtCase::validateCurrentContext (const glw::Functions& gl)
        {
                if (m_api == EGL_OPENGL_API)
                {
-                       if (!hasExtension(gl, "GL_ARB_robustness"))
+                       if (!glu::hasExtension(gl, glu::ApiType::core(majorVersion, minorVersion), "GL_ARB_robustness"))
                        {
                                log << TestLog::Message << "Created robustness context but it doesn't support GL_ARB_robustness." << TestLog::EndMessage;
                                isOk = false;
@@ -849,7 +835,7 @@ bool CreateContextExtCase::validateCurrentContext (const glw::Functions& gl)
                }
                else if (m_api == EGL_OPENGL_ES_API)
                {
-                       if (!hasExtension(gl, "GL_EXT_robustness"))
+                       if (!glu::hasExtension(gl, glu::ApiType::es(majorVersion, minorVersion), "GL_EXT_robustness"))
                        {
                                log << TestLog::Message << "Created robustness context but it doesn't support GL_EXT_robustness." << TestLog::EndMessage;
                                isOk = false;
index fa6acca..5afd1ad 100644 (file)
@@ -1085,7 +1085,7 @@ protected:
 
 void ImageTests::addCreateTexture (const string& name, EGLenum source, GLenum format, GLenum type)
 {
-       m_createActions.add(name, MovePtr<Action>(new GLES2ImageApi::Create(createTextureImageSource(source, format, type))));
+       m_createActions.add(name, MovePtr<Action>(new GLES2ImageApi::Create(createTextureImageSource(source, format, format, type))));
 }
 
 void ImageTests::addCreateRenderbuffer (const string& name, GLenum format)
index 69575f4..d9e6f16 100644 (file)
@@ -171,6 +171,11 @@ public:
                m_display = EGL_NO_DISPLAY;
        }
 
+       bool            isGLRedSupported        (void)
+       {
+               return m_api.getMajorVersion() >= 3 || glu::hasExtension(m_gl, m_api, "GL_EXT_texture_rg");
+       }
+
 protected:
        glw::Functions  m_gl;
        ApiType                 m_api;
@@ -292,6 +297,10 @@ public:
        {
                switch (storage)
                {
+                       case GL_RED:                            return "red";
+                       case GL_RG:                                     return "rg";
+                       case GL_LUMINANCE:                      return "luminance";
+                       case GL_LUMINANCE_ALPHA:        return "luminance_alpha";
                        case GL_RGB:                            return "rgb";
                        case GL_RGBA:                           return "rgba";
                        case GL_DEPTH_COMPONENT16:      return "depth_component_16";
@@ -307,7 +316,7 @@ public:
                }
        }
 
-       MovePtr<ImageSource> getImageSource (EGLint target, GLenum format, bool useTexLevel0)
+       MovePtr<ImageSource> getImageSource (EGLint target, GLenum format, bool useTexLevel0, GLenum internalFormat)
        {
                switch (target)
                {
@@ -318,7 +327,7 @@ public:
                        case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
                        case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
                        case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
-                               return createTextureImageSource(target, format, GL_UNSIGNED_BYTE, useTexLevel0);
+                               return createTextureImageSource(target, internalFormat, format, GL_UNSIGNED_BYTE, useTexLevel0);
                        case EGL_GL_RENDERBUFFER_KHR:
                                return createRenderbufferImageSource(format);
                        case EGL_NATIVE_BUFFER_ANDROID:
@@ -329,9 +338,10 @@ public:
                }
        }
 
-       CreateImageGLES2 (EglTestContext& eglTestCtx, EGLint target, GLenum storage, bool useTexLevel0 = false)
-               : ImageTestCase         (eglTestCtx, ApiType::es(2, 0), string("create_image_gles2_") + getTargetName(target) + "_" + getStorageName(storage) + (useTexLevel0 ? "_level0_only" : ""), "Create EGLImage from GLES2 object")
-               , m_source                      (getImageSource(target, storage, useTexLevel0))
+       CreateImageGLES2 (EglTestContext& eglTestCtx, EGLint target, GLenum storage, bool useTexLevel0 = false, GLenum internalFormat = GLenum(0))
+               : ImageTestCase                 (eglTestCtx, ApiType::es(2, 0), string("create_image_gles2_") + getTargetName(target) + "_" + getStorageName(storage) + (useTexLevel0 ? "_level0_only" : ""), "Create EGLImage from GLES2 object")
+               , m_source                              (getImageSource(target, storage, useTexLevel0, internalFormat))
+               , m_format                              (target)
        {
        }
 
@@ -352,6 +362,9 @@ public:
                Context                                 context                 (m_eglTestCtx, dpy, contextType, 64, 64);
                const EGLContext                eglContext              = context.getEglContext();
 
+               if ((m_format == GL_RED || m_format == GL_RG) && !isGLRedSupported())
+                       TCU_THROW(NotSupportedError, "Unsupported extension: GL_EXT_texture_rg");
+
                log << TestLog::Message << "Using EGL config " << eglu::getConfigID(egl, dpy, context.getConfig()) << TestLog::EndMessage;
 
                UniquePtr<ClientBuffer> clientBuffer    (m_source->createBuffer(context.gl()));
@@ -373,6 +386,7 @@ public:
 
 private:
        UniquePtr<ImageSource>  m_source;
+       GLenum                                  m_format;
 };
 
 class ImageTargetGLES2 : public ImageTestCase
@@ -486,6 +500,12 @@ public:
        {
                addChild(new Image::InvalidCreateImage(m_eglTestCtx));
 
+               addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RED, false, GL_R8));
+               addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RG, false, GL_RG8));
+
+               addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_LUMINANCE));
+               addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_LUMINANCE_ALPHA));
+
                addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RGB));
                addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RGBA));
                addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RGBA, true));
index 0fecb60..d58e418 100644 (file)
@@ -178,15 +178,17 @@ EGLImageKHR GLImageSource::createImage (const Library& egl, EGLDisplay dpy, EGLC
 class TextureImageSource : public GLImageSource
 {
 public:
-                                                       TextureImageSource      (GLenum format, GLenum type, bool useTexLevel0) : m_format(format), m_type(type), m_useTexLevel0(useTexLevel0) {}
+                                                       TextureImageSource      (GLenum internalFormat, GLenum format, GLenum type, bool useTexLevel0) : m_internalFormat(internalFormat), m_format(format), m_type(type), m_useTexLevel0(useTexLevel0) {}
        MovePtr<ClientBuffer>   createBuffer            (const glw::Functions& gl, Texture2D* reference) const;
        GLenum                                  getFormat                       (void) const { return m_format; }
+       GLenum                                  getInternalFormat       (void) const { return m_internalFormat; }
 
 protected:
        AttribMap                               getCreateAttribs        (void) const;
        virtual void                    initTexture                     (const glw::Functions& gl) const = 0;
        virtual GLenum                  getGLTarget                     (void) const = 0;
 
+       GLenum                                  m_internalFormat;
        GLenum                                  m_format;
        GLenum                                  m_type;
        bool                                    m_useTexLevel0;
@@ -231,7 +233,7 @@ MovePtr<ClientBuffer> TextureImageSource::createBuffer (const glw::Functions& gl
                GLU_CHECK_GLW_CALL(gl, texParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
                GLU_CHECK_GLW_CALL(gl, texParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
 
-               GLU_CHECK_GLW_CALL(gl, texImage2D(imgTarget, 0, m_format, IMAGE_WIDTH, IMAGE_HEIGHT,
+               GLU_CHECK_GLW_CALL(gl, texImage2D(imgTarget, 0, m_internalFormat, IMAGE_WIDTH, IMAGE_HEIGHT,
                                                                                  0, m_format, m_type, ref->getLevel(0).getDataPtr()));
        }
        GLU_CHECK_GLW_CALL(gl, bindTexture(target, 0));
@@ -241,7 +243,7 @@ MovePtr<ClientBuffer> TextureImageSource::createBuffer (const glw::Functions& gl
 class Texture2DImageSource : public TextureImageSource
 {
 public:
-                                       Texture2DImageSource    (GLenum format, GLenum type, bool useTexLevel0) : TextureImageSource(format, type, useTexLevel0) {}
+                                       Texture2DImageSource    (GLenum internalFormat, GLenum format, GLenum type, bool useTexLevel0) : TextureImageSource(internalFormat, format, type, useTexLevel0) {}
        EGLenum                 getSource                               (void) const { return EGL_GL_TEXTURE_2D_KHR; }
        string                  getRequiredExtension    (void) const { return "EGL_KHR_gl_texture_2D_image"; }
        GLenum                  getGLTarget                             (void) const { return GL_TEXTURE_2D; }
@@ -253,14 +255,14 @@ protected:
 void Texture2DImageSource::initTexture (const glw::Functions& gl) const
 {
        // Specify mipmap level 0
-       GLU_CHECK_CALL_ERROR(gl.texImage2D(GL_TEXTURE_2D, 0, m_format, IMAGE_WIDTH, IMAGE_HEIGHT, 0, m_format, m_type, DE_NULL),
+       GLU_CHECK_CALL_ERROR(gl.texImage2D(GL_TEXTURE_2D, 0, m_internalFormat, IMAGE_WIDTH, IMAGE_HEIGHT, 0, m_format, m_type, DE_NULL),
                                                 gl.getError());
 }
 
 class TextureCubeMapImageSource : public TextureImageSource
 {
 public:
-                                       TextureCubeMapImageSource       (EGLenum source, GLenum format, GLenum type, bool useTexLevel0) : TextureImageSource(format, type, useTexLevel0), m_source(source) {}
+                                       TextureCubeMapImageSource       (GLenum internalFormat, EGLenum source, GLenum format, GLenum type, bool useTexLevel0) : TextureImageSource(internalFormat, format, type, useTexLevel0), m_source(source) {}
        EGLenum                 getSource                                       (void) const { return m_source; }
        string                  getRequiredExtension            (void) const { return "EGL_KHR_gl_texture_cubemap_image"; }
        GLenum                  getGLTarget                                     (void) const { return GL_TEXTURE_CUBE_MAP; }
@@ -285,7 +287,7 @@ void TextureCubeMapImageSource::initTexture (const glw::Functions& gl) const
        };
 
        for (int faceNdx = 0; faceNdx < DE_LENGTH_OF_ARRAY(faces); faceNdx++)
-               GLU_CHECK_GLW_CALL(gl, texImage2D(faces[faceNdx], 0, m_format, IMAGE_WIDTH, IMAGE_HEIGHT, 0, m_format, m_type, DE_NULL));
+               GLU_CHECK_GLW_CALL(gl, texImage2D(faces[faceNdx], 0, m_internalFormat, IMAGE_WIDTH, IMAGE_HEIGHT, 0, m_format, m_type, DE_NULL));
 }
 
 class RenderbufferClientBuffer : public GLClientBuffer
@@ -505,12 +507,12 @@ EGLImageKHR       UnsupportedImageSource::createImage (const Library&, EGLDisplay, EGL
        return EGL_NO_IMAGE_KHR;
 }
 
-MovePtr<ImageSource> createTextureImageSource (EGLenum source, GLenum format, GLenum type, bool useTexLevel0)
+MovePtr<ImageSource> createTextureImageSource (EGLenum source, GLenum internalFormat, GLenum format, GLenum type, bool useTexLevel0)
 {
        if (source == EGL_GL_TEXTURE_2D_KHR)
-               return MovePtr<ImageSource>(new Texture2DImageSource(format, type, useTexLevel0));
+               return MovePtr<ImageSource>(new Texture2DImageSource(internalFormat, format, type, useTexLevel0));
        else
-               return MovePtr<ImageSource>(new TextureCubeMapImageSource(source, format, type, useTexLevel0));
+               return MovePtr<ImageSource>(new TextureCubeMapImageSource(source, internalFormat, format, type, useTexLevel0));
 }
 
 MovePtr<ImageSource> createRenderbufferImageSource (GLenum format)
index aeb6669..d3c3747 100644 (file)
@@ -77,7 +77,7 @@ public:
        virtual glw::GLenum                                     getFormat                       (void) const = 0;
 };
 
-de::MovePtr<ImageSource> createTextureImageSource                      (eglw::EGLenum source, glw::GLenum format, glw::GLenum type, bool useTexLevel0 = false);
+de::MovePtr<ImageSource> createTextureImageSource                      (eglw::EGLenum source, glw::GLenum internalFormat, glw::GLenum format, glw::GLenum type, bool useTexLevel0 = false);
 de::MovePtr<ImageSource> createRenderbufferImageSource         (glw::GLenum format);
 de::MovePtr<ImageSource> createUnsupportedImageSource          (const std::string& message, glw::GLenum format);