ANGLETest::SetUp: resize the window only if needed.

This avoids a flickering of the window at the start of every test.

Reland with a speculative fix for ViewportTest

BUG=angleproject:1105

Change-Id: I83e89881de5b6f58cfb3e14cbe324fd9547f2836
Tested-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/288533
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/tests/test_utils/ANGLETest.cpp b/src/tests/test_utils/ANGLETest.cpp
index 2e6fdbd..eeb417e 100644
--- a/src/tests/test_utils/ANGLETest.cpp
+++ b/src/tests/test_utils/ANGLETest.cpp
@@ -17,9 +17,16 @@
 
 void ANGLETest::SetUp()
 {
-    if (!ResizeWindow(mWidth, mHeight))
+    // Resize the window before creating the context so that the first make current
+    // sets the viewport and scissor box to the right size.
+    bool needSwap = false;
+    if (mOSWindow->getWidth() != mWidth || mOSWindow->getHeight() != mHeight)
     {
-        FAIL() << "Failed to resize ANGLE test window.";
+        if (!mOSWindow->resize(mWidth, mHeight))
+        {
+            FAIL() << "Failed to resize ANGLE test window.";
+        }
+        needSwap = true;
     }
 
     if (!createEGLContext())
@@ -27,10 +34,13 @@
         FAIL() << "egl context creation failed.";
     }
 
-    // Swap the buffers so that the default framebuffer picks up the resize
-    // which will allow follow-up test code to assume the framebuffer covers
-    // the whole window.
-    swapBuffers();
+    if (needSwap)
+    {
+        // Swap the buffers so that the default framebuffer picks up the resize
+        // which will allow follow-up test code to assume the framebuffer covers
+        // the whole window.
+        swapBuffers();
+    }
 
     // This Viewport command is not strictly necessary but we add it so that programs
     // taking OpenGL traces can guess the size of the default framebuffer and show it
@@ -250,11 +260,6 @@
     return true;
 }
 
-bool ANGLETest::ResizeWindow(int width, int height)
-{
-    return mOSWindow->resize(width, height);
-}
-
 void ANGLETest::SetWindowVisible(bool isVisible)
 {
     mOSWindow->setVisible(isVisible);