Validate compressed texture dimensions based on the per-format compressed block sizes rather than hard-coded values.

TRAC #23630

Signed-off-by: Jamie Madill
Signed-off-by: Shannon Woods
diff --git a/src/libGLESv2/validationES2.cpp b/src/libGLESv2/validationES2.cpp
index 1f16924..a9a11e2 100644
--- a/src/libGLESv2/validationES2.cpp
+++ b/src/libGLESv2/validationES2.cpp
@@ -22,21 +22,6 @@
 namespace gl
 {
 
-static bool validCompressedImageSize(GLsizei width, GLsizei height)
-{
-    if (width != 1 && width != 2 && width % 4 != 0)
-    {
-        return false;
-    }
-
-    if (height != 1 && height != 2 && height % 4 != 0)
-    {
-        return false;
-    }
-
-    return true;
-}
-
 static bool validateSubImageParams2D(bool compressed, GLsizei width, GLsizei height,
                                      GLint xoffset, GLint yoffset, GLint level, GLenum format, GLenum type,
                                      gl::Texture2D *texture)
@@ -128,11 +113,6 @@
         return gl::error(GL_INVALID_VALUE, false);
     }
 
-    if (isCompressed && !validCompressedImageSize(width, height))
-    {
-        return gl::error(GL_INVALID_OPERATION, false);
-    }
-
     if (level < 0 || xoffset < 0 ||
         std::numeric_limits<GLsizei>::max() - xoffset < width ||
         std::numeric_limits<GLsizei>::max() - yoffset < height)
@@ -239,6 +219,11 @@
     GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
     if (isCompressed)
     {
+        if (!ValidCompressedImageSize(context, actualInternalFormat, width, height))
+        {
+            return gl::error(GL_INVALID_OPERATION, false);
+        }
+
         switch (actualInternalFormat)
         {
           case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: