Add gl::Format to represent a texture/rb/surface format.

This has a few advantages: it preserves all the information of the
internal format, such as if it is sized or unsized. It also saves
looking up the format multiple times in the table, which should
improve speed in some cases.

The extra sized-ness information will allow us to perform the
correct validation in CopyTexSubImage calls.

BUG=angleproject:1228

Change-Id: I42954771b0a9a968f5d787b8cf6e0af721791855
Reviewed-on: https://chromium-review.googlesource.com/362626
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES3.cpp b/src/libANGLE/validationES3.cpp
index aab10df..a1e11cd 100644
--- a/src/libANGLE/validationES3.cpp
+++ b/src/libANGLE/validationES3.cpp
@@ -387,7 +387,8 @@
     }
 
     // Validate texture formats
-    GLenum actualInternalFormat = isSubImage ? texture->getInternalFormat(target, level) : internalformat;
+    GLenum actualInternalFormat =
+        isSubImage ? texture->getFormat(target, level).asSized() : internalformat;
     const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualInternalFormat);
     if (isCompressed)
     {
@@ -911,13 +912,14 @@
                                            GLsizei height,
                                            GLint border)
 {
-    GLenum textureInternalFormat;
+    GLenum textureInternalFormat = GL_NONE;
     if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
                                             xoffset, yoffset, zoffset, x, y, width, height,
                                             border, &textureInternalFormat))
     {
         return false;
     }
+    ASSERT(textureInternalFormat != GL_NONE || !isSubImage);
 
     const auto &state            = context->getGLState();
     gl::Framebuffer *framebuffer = state.getReadFramebuffer();
@@ -936,7 +938,7 @@
     }
 
     const gl::FramebufferAttachment *source = framebuffer->getReadColorbuffer();
-    GLenum colorbufferInternalFormat = source->getInternalFormat();
+    GLenum colorbufferInternalFormat        = source->getFormat().asSized();
 
     if (isSubImage)
     {
@@ -1271,8 +1273,8 @@
             return false;
         }
 
-        const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(tex->getTarget(), level));
-        if (internalFormatInfo.compressed)
+        const auto &format = tex->getFormat(tex->getTarget(), level);
+        if (format.info->compressed)
         {
             context->handleError(Error(GL_INVALID_OPERATION));
             return false;