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/validationES2.cpp b/src/libANGLE/validationES2.cpp
index 4d2449f..540ed1a 100644
--- a/src/libANGLE/validationES2.cpp
+++ b/src/libANGLE/validationES2.cpp
@@ -280,7 +280,8 @@
     {
         if (format != GL_NONE)
         {
-            if (gl::GetSizedInternalFormat(format, type) != texture->getInternalFormat(target, level))
+            if (gl::GetSizedInternalFormat(format, type) !=
+                texture->getFormat(target, level).asSized())
             {
                 context->handleError(Error(GL_INVALID_OPERATION));
                 return false;
@@ -313,7 +314,7 @@
     if (isCompressed)
     {
         GLenum actualInternalFormat =
-            isSubImage ? texture->getInternalFormat(target, level) : internalformat;
+            isSubImage ? texture->getFormat(target, level).asSized() : internalformat;
         switch (actualInternalFormat)
         {
           case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
@@ -644,7 +645,7 @@
     }
 
     const gl::Framebuffer *framebuffer = context->getGLState().getReadFramebuffer();
-    GLenum colorbufferFormat = framebuffer->getReadColorbuffer()->getInternalFormat();
+    GLenum colorbufferFormat           = framebuffer->getReadColorbuffer()->getFormat().asSized();
     const auto &internalFormatInfo = gl::GetInternalFormatInfo(textureInternalFormat);
     GLenum textureFormat = internalFormatInfo.format;
 
@@ -1832,7 +1833,8 @@
                     }
 
                     // Return an error if the destination formats do not match
-                    if (attachment->getInternalFormat() != readColorAttachment->getInternalFormat())
+                    if (!Format::SameSized(attachment->getFormat(),
+                                           readColorAttachment->getFormat()))
                     {
                         context->handleError(Error(GL_INVALID_OPERATION));
                         return false;