Context: Remove mutable gl::State getter.

This will preserve layering - the API layer doesn't mutate the state
directly, it passes the API call through to the Context. Is also
removes the possiblity of any shenanigans of the Validation layer
changing the GL state.

Also, this CL refactors a few validation entry points to take
ValidationContext instead of Context. ValidationContext will be the
correct way to interact with the gl::Context in the Validation code.

Finally, additional refactorings make ContextState a proper class with
private data. This allows the ContextState itself to keep a mutable
pointer to the gl::State, so ValidationContext can modify it if
necessary (and it will be necessary for Framebuffer completeness
caching).

BUG=angleproject:1388

Change-Id: I86ab3561573caa9535c8d1b8aad4ab3d0e7cd470
Reviewed-on: https://chromium-review.googlesource.com/348954
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES3.cpp b/src/libANGLE/validationES3.cpp
index 39bd20e..cb2d53d 100644
--- a/src/libANGLE/validationES3.cpp
+++ b/src/libANGLE/validationES3.cpp
@@ -467,7 +467,7 @@
     }
 
     // Check for pixel unpack buffer related API errors
-    gl::Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER);
+    gl::Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER);
     if (pixelUnpackBuffer != NULL)
     {
         // ...the data would be unpacked from the buffer object such that the memory reads required
@@ -475,7 +475,7 @@
         GLenum sizedFormat = GetSizedInternalFormat(actualInternalFormat, type);
         const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat);
         const gl::Extents size(width, height, depth);
-        const auto &unpack = context->getState().getUnpackState();
+        const auto &unpack = context->getGLState().getUnpackState();
 
         auto copyBytesOrErr = formatInfo.computeUnpackSize(type, size, unpack);
         if (copyBytesOrErr.isError())
@@ -891,17 +891,17 @@
         return false;
     }
 
-    const auto &state                  = context->getState();
+    const auto &state                  = context->getGLState();
     const gl::Framebuffer *framebuffer = state.getReadFramebuffer();
     GLuint readFramebufferID           = framebuffer->id();
 
-    if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE)
+    if (framebuffer->checkStatus(context->getContextState()) != GL_FRAMEBUFFER_COMPLETE)
     {
         context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
         return false;
     }
 
-    if (readFramebufferID != 0 && framebuffer->getSamples(context->getData()) != 0)
+    if (readFramebufferID != 0 && framebuffer->getSamples(context->getContextState()) != 0)
     {
         context->handleError(Error(GL_INVALID_OPERATION));
         return false;
@@ -1254,7 +1254,10 @@
     return true;
 }
 
-bool ValidES3ReadFormatType(Context *context, GLenum internalFormat, GLenum format, GLenum type)
+bool ValidES3ReadFormatType(ValidationContext *context,
+                            GLenum internalFormat,
+                            GLenum format,
+                            GLenum type)
 {
     const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat);
 
@@ -1390,11 +1393,11 @@
     {
       case GL_DRAW_FRAMEBUFFER:
       case GL_FRAMEBUFFER:
-        defaultFramebuffer = context->getState().getDrawFramebuffer()->id() == 0;
-        break;
+          defaultFramebuffer = context->getGLState().getDrawFramebuffer()->id() == 0;
+          break;
       case GL_READ_FRAMEBUFFER:
-        defaultFramebuffer = context->getState().getReadFramebuffer()->id() == 0;
-        break;
+          defaultFramebuffer = context->getGLState().getReadFramebuffer()->id() == 0;
+          break;
       default:
           context->handleError(Error(GL_INVALID_ENUM, "Invalid framebuffer target"));
         return false;
@@ -1411,8 +1414,8 @@
         return false;
     }
 
-    const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer();
-    if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE)
+    const gl::Framebuffer *fbo = context->getGLState().getDrawFramebuffer();
+    if (!fbo || fbo->checkStatus(context->getContextState()) != GL_FRAMEBUFFER_COMPLETE)
     {
         context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
         return false;
@@ -1476,7 +1479,7 @@
         return false;
     }
 
-    Framebuffer *readFBO = context->getState().getReadFramebuffer();
+    const Framebuffer *readFBO = context->getGLState().getReadFramebuffer();
 
     if (readFBO == nullptr)
     {
@@ -2027,7 +2030,7 @@
             return false;
     }
 
-    TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
+    TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback();
     ASSERT(transformFeedback != nullptr);
 
     if (transformFeedback->isActive())