Refactors State to be a fully-qualified class

BUG=angle:685

Change-Id: I36cff2da985a12c7180fe2850ccd471f4cebbaad
Reviewed-on: https://chromium-review.googlesource.com/206634
Tested-by: Shannon Woods <shannonwoods@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libGLESv2/libGLESv2.cpp b/src/libGLESv2/libGLESv2.cpp
index 2eb2f2e..3c28fb3 100644
--- a/src/libGLESv2/libGLESv2.cpp
+++ b/src/libGLESv2/libGLESv2.cpp
@@ -51,7 +51,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            context->setActiveSampler(texture - GL_TEXTURE0);
+            context->getState().setActiveSampler(texture - GL_TEXTURE0);
         }
     }
     ANGLE_CATCH_ALL
@@ -345,7 +345,7 @@
 
         if (context)
         {
-            context->setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
+            context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
         }
     }
     ANGLE_CATCH_ALL
@@ -395,7 +395,7 @@
 
         if (context)
         {
-            context->setBlendEquation(modeRGB, modeAlpha);
+            context->getState().setBlendEquation(modeRGB, modeAlpha);
         }
     }
     ANGLE_CATCH_ALL
@@ -534,7 +534,7 @@
 
         if (context)
         {
-            context->setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
+            context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
         }
     }
     ANGLE_CATCH_ALL
@@ -587,7 +587,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (!buffer)
             {
@@ -629,7 +629,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (!buffer)
             {
@@ -676,7 +676,7 @@
 
         if (context)
         {
-            gl::Framebuffer *framebuffer = context->getTargetFramebuffer(target);
+            gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
             ASSERT(framebuffer);
             return framebuffer->completeness();
         }
@@ -699,7 +699,7 @@
 
         if (context)
         {
-            gl::Framebuffer *framebufferObject = context->getDrawFramebuffer();
+            gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
 
             if (!framebufferObject || framebufferObject->completeness() != GL_FRAMEBUFFER_COMPLETE)
             {
@@ -731,7 +731,7 @@
 
         if (context)
         {
-            context->setClearColor(red, green, blue, alpha);
+            context->getState().setClearColor(red, green, blue, alpha);
         }
     }
     ANGLE_CATCH_ALL
@@ -750,7 +750,7 @@
 
         if (context)
         {
-            context->setClearDepth(depth);
+            context->getState().setClearDepth(depth);
         }
     }
     ANGLE_CATCH_ALL
@@ -769,7 +769,7 @@
 
         if (context)
         {
-            context->setClearStencil(s);
+            context->getState().setClearStencil(s);
         }
     }
     ANGLE_CATCH_ALL
@@ -789,7 +789,7 @@
 
         if (context)
         {
-            context->setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
+            context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
         }
     }
     ANGLE_CATCH_ALL
@@ -986,7 +986,7 @@
                 return;
             }
 
-            gl::Framebuffer *framebuffer = context->getReadFramebuffer();
+            gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
 
             switch (target)
             {
@@ -1046,7 +1046,7 @@
                 return;
             }
 
-            gl::Framebuffer *framebuffer = context->getReadFramebuffer();
+            gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
 
             switch (target)
             {
@@ -1146,7 +1146,7 @@
 
                 if (context)
                 {
-                    context->setCullMode(mode);
+                    context->getState().setCullMode(mode);
                 }
             }
             break;
@@ -1425,7 +1425,7 @@
 
         if (context)
         {
-            context->setDepthFunc(func);
+            context->getState().setDepthFunc(func);
         }
     }
     ANGLE_CATCH_ALL
@@ -1444,7 +1444,7 @@
 
         if (context)
         {
-            context->setDepthMask(flag != GL_FALSE);
+            context->getState().setDepthMask(flag != GL_FALSE);
         }
     }
     ANGLE_CATCH_ALL
@@ -1463,7 +1463,7 @@
 
         if (context)
         {
-            context->setDepthRange(zNear, zFar);
+            context->getState().setDepthRange(zNear, zFar);
         }
     }
     ANGLE_CATCH_ALL
@@ -1540,7 +1540,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            context->setCap(cap, false);
+            context->getState().setEnableFeature(cap, false);
         }
     }
     ANGLE_CATCH_ALL
@@ -1564,7 +1564,7 @@
 
         if (context)
         {
-            context->setEnableVertexAttribArray(index, false);
+            context->getState().setEnableVertexAttribArray(index, false);
         }
     }
     ANGLE_CATCH_ALL
@@ -1686,7 +1686,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            context->setCap(cap, true);
+            context->getState().setEnableFeature(cap, true);
         }
     }
     ANGLE_CATCH_ALL
@@ -1710,7 +1710,7 @@
 
         if (context)
         {
-            context->setEnableVertexAttribArray(index, true);
+            context->getState().setEnableVertexAttribArray(index, true);
         }
     }
     ANGLE_CATCH_ALL
@@ -1833,7 +1833,7 @@
                 return;
             }
 
-            gl::Framebuffer *framebuffer = context->getTargetFramebuffer(target);
+            gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
             ASSERT(framebuffer);
 
             if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
@@ -1887,7 +1887,7 @@
                 textarget = GL_NONE;
             }
 
-            gl::Framebuffer *framebuffer = context->getTargetFramebuffer(target);
+            gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
 
             if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
             {
@@ -1926,7 +1926,7 @@
 
                 if (context)
                 {
-                    context->setFrontFace(mode);
+                    context->getState().setFrontFace(mode);
                 }
             }
             break;
@@ -2401,7 +2401,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (!buffer)
             {
@@ -2602,7 +2602,7 @@
                 break;
             }
 
-            GLuint framebufferHandle = context->getTargetFramebufferHandle(target);
+            GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
             gl::Framebuffer *framebuffer = context->getFramebuffer(framebufferHandle);
 
             if (framebufferHandle == 0)
@@ -3001,7 +3001,7 @@
             switch (pname)
             {
               case GL_CURRENT_QUERY_EXT:
-                params[0] = context->getActiveQueryId(target);
+                params[0] = context->getState().getActiveQueryId(target);
                 break;
 
               default:
@@ -3032,7 +3032,7 @@
                 return gl::error(GL_INVALID_OPERATION);
             }
 
-            if (context->getActiveQueryId(queryObject->getType()) == id)
+            if (context->getState().getActiveQueryId(queryObject->getType()) == id)
             {
                 return gl::error(GL_INVALID_OPERATION);
             }
@@ -3071,12 +3071,12 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            if (context->getRenderbufferHandle() == 0)
+            if (context->getState().getRenderbufferId() == 0)
             {
                 return gl::error(GL_INVALID_OPERATION);
             }
 
-            gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
+            gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
 
             switch (pname)
             {
@@ -3825,7 +3825,7 @@
                 return gl::error(GL_INVALID_VALUE);
             }
 
-            const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
+            const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
 
             if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
             {
@@ -3834,7 +3834,7 @@
 
             if (pname == GL_CURRENT_VERTEX_ATTRIB)
             {
-                const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
+                const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
                 for (int i = 0; i < 4; ++i)
                 {
                     params[i] = currentValueData.FloatValues[i];
@@ -3867,7 +3867,7 @@
                 return gl::error(GL_INVALID_VALUE);
             }
 
-            const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
+            const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
 
             if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
             {
@@ -3876,7 +3876,7 @@
 
             if (pname == GL_CURRENT_VERTEX_ATTRIB)
             {
-                const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
+                const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
                 for (int i = 0; i < 4; ++i)
                 {
                     float currentValue = currentValueData.FloatValues[i];
@@ -3915,7 +3915,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            *pointer = const_cast<GLvoid*>(context->getVertexAttribPointer(index));
+            *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
         }
     }
     ANGLE_CATCH_ALL
@@ -3944,10 +3944,10 @@
         switch (target)
         {
           case GL_GENERATE_MIPMAP_HINT:
-            if (context) context->setGenerateMipmapHint(mode);
+            if (context) context->getState().setGenerateMipmapHint(mode);
             break;
           case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
-            if (context) context->setFragmentShaderDerivativeHint(mode);
+            if (context) context->getState().setFragmentShaderDerivativeHint(mode);
             break;
           default:
             return gl::error(GL_INVALID_ENUM);
@@ -4000,7 +4000,7 @@
                 return gl::error(GL_INVALID_ENUM, false);
             }
 
-            return context->getCap(cap);
+            return context->getState().getEnableFeature(cap);
         }
     }
     ANGLE_CATCH_ALL
@@ -4205,7 +4205,7 @@
 
         if (context)
         {
-            context->setLineWidth(width);
+            context->getState().setLineWidth(width);
         }
     }
     ANGLE_CATCH_ALL
@@ -4265,7 +4265,7 @@
                     return gl::error(GL_INVALID_VALUE);
                 }
 
-                context->setUnpackAlignment(param);
+                context->getState().setUnpackAlignment(param);
                 break;
 
               case GL_PACK_ALIGNMENT:
@@ -4274,11 +4274,11 @@
                     return gl::error(GL_INVALID_VALUE);
                 }
 
-                context->setPackAlignment(param);
+                context->getState().setPackAlignment(param);
                 break;
 
               case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
-                context->setPackReverseRowOrder(param != 0);
+                context->getState().setPackReverseRowOrder(param != 0);
                 break;
 
               case GL_UNPACK_IMAGE_HEIGHT:
@@ -4317,7 +4317,7 @@
 
         if (context)
         {
-            context->setPolygonOffsetParams(factor, units);
+            context->getState().setPolygonOffsetParams(factor, units);
         }
     }
     ANGLE_CATCH_ALL
@@ -4448,7 +4448,7 @@
 
         if (context)
         {
-            context->setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
+            context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
         }
     }
     ANGLE_CATCH_ALL
@@ -4503,7 +4503,7 @@
 
         if (context)
         {
-            context->setScissorParams(x, y, width, height);
+            context->getState().setScissorParams(x, y, width, height);
         }
     }
     ANGLE_CATCH_ALL
@@ -4610,12 +4610,12 @@
         {
             if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
             {
-                context->setStencilParams(func, ref, mask);
+                context->getState().setStencilParams(func, ref, mask);
             }
 
             if (face == GL_BACK || face == GL_FRONT_AND_BACK)
             {
-                context->setStencilBackParams(func, ref, mask);
+                context->getState().setStencilBackParams(func, ref, mask);
             }
         }
     }
@@ -4652,12 +4652,12 @@
         {
             if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
             {
-                context->setStencilWritemask(mask);
+                context->getState().setStencilWritemask(mask);
             }
 
             if (face == GL_BACK || face == GL_FRONT_AND_BACK)
             {
-                context->setStencilBackWritemask(mask);
+                context->getState().setStencilBackWritemask(mask);
             }
         }
     }
@@ -4740,12 +4740,12 @@
         {
             if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
             {
-                context->setStencilOperations(fail, zfail, zpass);
+                context->getState().setStencilOperations(fail, zfail, zpass);
             }
 
             if (face == GL_BACK || face == GL_FRONT_AND_BACK)
             {
-                context->setStencilBackOperations(fail, zfail, zpass);
+                context->getState().setStencilBackOperations(fail, zfail, zpass);
             }
         }
     }
@@ -4820,43 +4820,43 @@
               case GL_TEXTURE_2D:
                 {
                     gl::Texture2D *texture = context->getTexture2D();
-                    texture->setImage(level, width, height, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
               case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
                 {
                     gl::TextureCubeMap *texture = context->getTextureCubeMap();
-                    texture->setImagePosX(level, width, height, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImagePosX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
               case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
                 {
                     gl::TextureCubeMap *texture = context->getTextureCubeMap();
-                    texture->setImageNegX(level, width, height, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImageNegX(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
               case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
                 {
                     gl::TextureCubeMap *texture = context->getTextureCubeMap();
-                    texture->setImagePosY(level, width, height, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImagePosY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
               case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
                 {
                     gl::TextureCubeMap *texture = context->getTextureCubeMap();
-                    texture->setImageNegY(level, width, height, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImageNegY(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
               case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
                 {
                     gl::TextureCubeMap *texture = context->getTextureCubeMap();
-                    texture->setImagePosZ(level, width, height, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImagePosZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
               case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
                 {
                     gl::TextureCubeMap *texture = context->getTextureCubeMap();
-                    texture->setImageNegZ(level, width, height, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImageNegZ(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
               default: UNREACHABLE();
@@ -5075,7 +5075,7 @@
               case GL_TEXTURE_2D:
                 {
                     gl::Texture2D *texture = context->getTexture2D();
-                    texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackState(), pixels);
+                    texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
 
@@ -5087,7 +5087,7 @@
               case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
                 {
                     gl::TextureCubeMap *texture = context->getTextureCubeMap();
-                    texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getUnpackState(), pixels);
+                    texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
 
@@ -5122,7 +5122,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform1fv(location, count, v);
         }
     }
@@ -5152,7 +5152,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform1iv(location, count, v);
         }
     }
@@ -5184,7 +5184,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform2fv(location, count, v);
         }
     }
@@ -5216,7 +5216,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform2iv(location, count, v);
         }
     }
@@ -5248,7 +5248,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform3fv(location, count, v);
         }
     }
@@ -5280,7 +5280,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform3iv(location, count, v);
         }
     }
@@ -5312,7 +5312,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform4fv(location, count, v);
         }
     }
@@ -5344,7 +5344,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform4iv(location, count, v);
         }
     }
@@ -5370,7 +5370,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix2fv(location, count, transpose, value);
         }
     }
@@ -5396,7 +5396,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix3fv(location, count, transpose, value);
         }
     }
@@ -5422,7 +5422,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix4fv(location, count, transpose, value);
         }
     }
@@ -5519,7 +5519,7 @@
         if (context)
         {
             GLfloat vals[4] = { x, 0, 0, 1 };
-            context->setVertexAttribf(index, vals);
+            context->getState().setVertexAttribf(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -5544,7 +5544,7 @@
         if (context)
         {
             GLfloat vals[4] = { values[0], 0, 0, 1 };
-            context->setVertexAttribf(index, vals);
+            context->getState().setVertexAttribf(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -5569,7 +5569,7 @@
         if (context)
         {
             GLfloat vals[4] = { x, y, 0, 1 };
-            context->setVertexAttribf(index, vals);
+            context->getState().setVertexAttribf(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -5594,7 +5594,7 @@
         if (context)
         {
             GLfloat vals[4] = { values[0], values[1], 0, 1 };
-            context->setVertexAttribf(index, vals);
+            context->getState().setVertexAttribf(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -5619,7 +5619,7 @@
         if (context)
         {
             GLfloat vals[4] = { x, y, z, 1 };
-            context->setVertexAttribf(index, vals);
+            context->getState().setVertexAttribf(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -5644,7 +5644,7 @@
         if (context)
         {
             GLfloat vals[4] = { values[0], values[1], values[2], 1 };
-            context->setVertexAttribf(index, vals);
+            context->getState().setVertexAttribf(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -5669,7 +5669,7 @@
         if (context)
         {
             GLfloat vals[4] = { x, y, z, w };
-            context->setVertexAttribf(index, vals);
+            context->getState().setVertexAttribf(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -5693,7 +5693,7 @@
 
         if (context)
         {
-            context->setVertexAttribf(index, values);
+            context->getState().setVertexAttribf(index, values);
         }
     }
     ANGLE_CATCH_ALL
@@ -5788,13 +5788,13 @@
             // An INVALID_OPERATION error is generated when a non-zero vertex array object
             // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
             // and the pointer argument is not NULL.
-            if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && ptr != NULL)
+            if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
             {
                 return gl::error(GL_INVALID_OPERATION);
             }
 
-            context->setVertexAttribState(index, context->getArrayBuffer(), size, type,
-                                          normalized == GL_TRUE, false, stride, ptr);
+            context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
+                                                     normalized == GL_TRUE, false, stride, ptr);
         }
     }
     ANGLE_CATCH_ALL
@@ -5818,7 +5818,7 @@
 
         if (context)
         {
-            context->setViewportParams(x, y, width, height);
+            context->getState().setViewportParams(x, y, width, height);
         }
     }
     ANGLE_CATCH_ALL
@@ -5910,14 +5910,14 @@
               case GL_TEXTURE_3D:
                 {
                     gl::Texture3D *texture = context->getTexture3D();
-                    texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
 
               case GL_TEXTURE_2D_ARRAY:
                 {
                     gl::Texture2DArray *texture = context->getTexture2DArray();
-                    texture->setImage(level, width, height, depth, internalformat, format, type, context->getUnpackState(), pixels);
+                    texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
 
@@ -5969,14 +5969,14 @@
               case GL_TEXTURE_3D:
                 {
                     gl::Texture3D *texture = context->getTexture3D();
-                    texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackState(), pixels);
+                    texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
 
               case GL_TEXTURE_2D_ARRAY:
                 {
                     gl::Texture2DArray *texture = context->getTexture2DArray();
-                    texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackState(), pixels);
+                    texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
                 }
                 break;
 
@@ -6014,7 +6014,7 @@
                 return;
             }
 
-            gl::Framebuffer *framebuffer = context->getReadFramebuffer();
+            gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
             gl::Texture *texture = NULL;
             switch (target)
             {
@@ -6336,7 +6336,7 @@
             switch (pname)
             {
               case GL_CURRENT_QUERY:
-                params[0] = static_cast<GLint>(context->getActiveQueryId(target));
+                params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
                 break;
 
               default:
@@ -6372,7 +6372,7 @@
                 return gl::error(GL_INVALID_OPERATION);
             }
 
-            if (context->getActiveQueryId(queryObject->getType()) == id)
+            if (context->getState().getActiveQueryId(queryObject->getType()) == id)
             {
                 return gl::error(GL_INVALID_OPERATION);
             }
@@ -6484,7 +6484,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
         }
     }
@@ -6510,7 +6510,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
         }
     }
@@ -6536,7 +6536,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
         }
     }
@@ -6562,7 +6562,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
         }
     }
@@ -6588,7 +6588,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
         }
     }
@@ -6614,7 +6614,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
         }
     }
@@ -6705,7 +6705,7 @@
                 return;
             }
 
-            gl::Framebuffer *framebuffer = context->getTargetFramebuffer(target);
+            gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
             ASSERT(framebuffer);
 
             gl::Texture *textureObject = context->getTexture(texture);
@@ -7015,7 +7015,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            gl::TransformFeedback *transformFeedback = context->getCurrentTransformFeedback();
+            gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
             ASSERT(transformFeedback != NULL);
 
             if (transformFeedback->isStarted())
@@ -7054,7 +7054,7 @@
                 return gl::error(GL_INVALID_OPERATION);
             }
 
-            gl::TransformFeedback *transformFeedback = context->getCurrentTransformFeedback();
+            gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
             ASSERT(transformFeedback != NULL);
 
             if (!transformFeedback->isStarted())
@@ -7362,13 +7362,13 @@
             // An INVALID_OPERATION error is generated when a non-zero vertex array object
             // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
             // and the pointer argument is not NULL.
-            if (context->getVertexArrayHandle() != 0 && context->getArrayBufferHandle() == 0 && pointer != NULL)
+            if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
             {
                 return gl::error(GL_INVALID_OPERATION);
             }
 
-            context->setVertexAttribState(index, context->getArrayBuffer(), size, type, false, true,
-                                          stride, pointer);
+            context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
+                                                     stride, pointer);
         }
     }
     ANGLE_CATCH_ALL
@@ -7398,7 +7398,7 @@
                 return gl::error(GL_INVALID_VALUE);
             }
 
-            const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
+            const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
 
             if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
             {
@@ -7407,7 +7407,7 @@
 
             if (pname == GL_CURRENT_VERTEX_ATTRIB)
             {
-                const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
+                const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
                 for (int i = 0; i < 4; ++i)
                 {
                     params[i] = currentValueData.IntValues[i];
@@ -7446,7 +7446,7 @@
                 return gl::error(GL_INVALID_VALUE);
             }
 
-            const gl::VertexAttribute &attribState = context->getVertexAttribState(index);
+            const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
 
             if (!gl::ValidateGetVertexAttribParameters(pname, context->getClientVersion()))
             {
@@ -7455,7 +7455,7 @@
 
             if (pname == GL_CURRENT_VERTEX_ATTRIB)
             {
-                const gl::VertexAttribCurrentValueData &currentValueData = context->getVertexAttribCurrentValue(index);
+                const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
                 for (int i = 0; i < 4; ++i)
                 {
                     params[i] = currentValueData.UnsignedIntValues[i];
@@ -7495,7 +7495,7 @@
             }
 
             GLint vals[4] = { x, y, z, w };
-            context->setVertexAttribi(index, vals);
+            context->getState().setVertexAttribi(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -7526,7 +7526,7 @@
             }
 
             GLuint vals[4] = { x, y, z, w };
-            context->setVertexAttribu(index, vals);
+            context->getState().setVertexAttribu(index, vals);
         }
     }
     ANGLE_CATCH_ALL
@@ -7555,7 +7555,7 @@
                 return gl::error(GL_INVALID_VALUE);
             }
 
-            context->setVertexAttribi(index, v);
+            context->getState().setVertexAttribi(index, v);
         }
     }
     ANGLE_CATCH_ALL
@@ -7584,7 +7584,7 @@
                 return gl::error(GL_INVALID_VALUE);
             }
 
-            context->setVertexAttribu(index, v);
+            context->getState().setVertexAttribu(index, v);
         }
     }
     ANGLE_CATCH_ALL
@@ -7723,7 +7723,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform1uiv(location, count, value);
         }
     }
@@ -7749,7 +7749,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform2uiv(location, count, value);
         }
     }
@@ -7775,7 +7775,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform3uiv(location, count, value);
         }
     }
@@ -7801,7 +7801,7 @@
                 return;
             }
 
-            gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+            gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
             programBinary->setUniform4uiv(location, count, value);
         }
     }
@@ -8028,8 +8028,8 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            gl::Buffer *readBuffer = context->getTargetBuffer(readTarget);
-            gl::Buffer *writeBuffer = context->getTargetBuffer(writeTarget);
+            gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
+            gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
 
             if (!readBuffer || !writeBuffer)
             {
@@ -8817,7 +8817,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (!buffer)
             {
@@ -9184,7 +9184,7 @@
               case GL_TRANSFORM_FEEDBACK:
                 {
                     // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
-                    gl::TransformFeedback *curTransformFeedback = context->getCurrentTransformFeedback();
+                    gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
                     if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
                     {
                         return gl::error(GL_INVALID_OPERATION);
@@ -9306,7 +9306,7 @@
                 return gl::error(GL_INVALID_OPERATION);
             }
 
-            gl::TransformFeedback *transformFeedback = context->getCurrentTransformFeedback();
+            gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
             ASSERT(transformFeedback != NULL);
 
             // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
@@ -9339,7 +9339,7 @@
                 return gl::error(GL_INVALID_OPERATION);
             }
 
-            gl::TransformFeedback *transformFeedback = context->getCurrentTransformFeedback();
+            gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
             ASSERT(transformFeedback != NULL);
 
             // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
@@ -9786,7 +9786,7 @@
                 return gl::error(GL_INVALID_VALUE);
             }
 
-            if (context->getDrawFramebufferHandle() == 0)
+            if (context->getState().getDrawFramebuffer()->id() == 0)
             {
                 if (n != 1)
                 {
@@ -9810,7 +9810,7 @@
                 }
             }
 
-            gl::Framebuffer *framebuffer = context->getDrawFramebuffer();
+            gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
 
             for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
             {
@@ -9849,7 +9849,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (!buffer || !buffer->isMapped())
             {
@@ -9882,7 +9882,7 @@
                 return gl::error(GL_INVALID_ENUM, reinterpret_cast<GLvoid*>(NULL));
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (buffer == NULL)
             {
@@ -9925,7 +9925,7 @@
                 return gl::error(GL_INVALID_ENUM, GL_FALSE);
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (buffer == NULL || !buffer->isMapped())
             {
@@ -9968,7 +9968,7 @@
                 return gl::error(GL_INVALID_VALUE, reinterpret_cast<GLvoid*>(NULL));
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (buffer == NULL)
             {
@@ -10054,7 +10054,7 @@
                 return gl::error(GL_INVALID_ENUM);
             }
 
-            gl::Buffer *buffer = context->getTargetBuffer(target);
+            gl::Buffer *buffer = context->getState().getTargetBuffer(target);
 
             if (buffer == NULL)
             {