ES31: Implement multisampled Textures.

Implement TexStorage2DMultisample and getMultisamplefv entry point.
Also modify sample state for Textures and Framebuffers.

BUG=angleproject:1590
TEST=angle_unittests
TEST=angle_end2end_tests
TEST=dEQP-GLES31.functional.texture.multisample.samples_*.sample_position
TEST=dEQP-GLES31.functional.texture.multisample.samples_*.use_texture_color_2d
TEST=dEQP-GLES31.functional.texture.multisample.samples_*.use_texture_depth_2d
TEST=dEQP-GLES31.functional.texture.multisample.negative.fbo_attach_different_sample_count_tex_tex
TEST=dEQP-GLES31.functional.texture.multisample.negative.fbo_attach_different_sample_count_tex_rbo
TEST=dEQP-GLES31.functional.texture.multisample.negative.fbo_attach_non_zero_level
TEST=dEQP-GLES31.functional.texture.multisample.negative.texture_high_sample_count
TEST=dEQP-GLES31.functional.texture.multisample.negative.texture_zero_sample_count
TEST=dEQP-GLES31.functional.shaders.builtin_functions.texture_size.samples_1_texture_2d
TEST=dEQP-GLES31.functional.shaders.builtin_functions.texture_size.samples_4_texture_2d

Change-Id: I8fa7bd4e73b95745858a3e16b1b92004b4a18712
Reviewed-on: https://chromium-review.googlesource.com/414309
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Yunchao He <yunchao.he@intel.com>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index aceddb5..3ccbeb4 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -2725,6 +2725,11 @@
         {
             index = ImageIndex::Make2D(level);
         }
+        else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
+        {
+            ASSERT(level == 0);
+            index = ImageIndex::Make2DMultisample();
+        }
         else
         {
             ASSERT(IsCubeMapTextureTarget(textarget));
@@ -3704,4 +3709,32 @@
     mGLState.setRenderbufferBinding(object);
 }
 
+void Context::texStorage2DMultisample(GLenum target,
+                                      GLsizei samples,
+                                      GLenum internalformat,
+                                      GLsizei width,
+                                      GLsizei height,
+                                      GLboolean fixedsamplelocations)
+{
+    Extents size(width, height, 1);
+    Texture *texture = getTargetTexture(target);
+    handleError(texture->setStorageMultisample(target, samples, internalformat, size,
+                                               fixedsamplelocations));
+}
+
+void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
+{
+    mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER);
+    const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
+
+    switch (pname)
+    {
+        case GL_SAMPLE_POSITION:
+            handleError(framebuffer->getSamplePosition(index, val));
+            break;
+        default:
+            UNREACHABLE();
+    }
+}
+
 }  // namespace gl