Blit9: Pass the dest rect to setViewportAndShaderConstants.

Using the sourceRect for calculating the viewport and texture coordinates
was not enough when the source and destination rectangles were different
sizes (generating mipmaps).

BUG=709232

Change-Id: I2704ddf6e3da0939ad77d278ab495e53a2d9bc7d
Reviewed-on: https://chromium-review.googlesource.com/473266
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/tests/gl_tests/MipmapTest.cpp b/src/tests/gl_tests/MipmapTest.cpp
index f5e8bd8..d2f7ff9 100644
--- a/src/tests/gl_tests/MipmapTest.cpp
+++ b/src/tests/gl_tests/MipmapTest.cpp
@@ -6,6 +6,8 @@
 
 #include "test_utils/ANGLETest.h"
 
+#include "test_utils/gl_raii.h"
+
 using namespace angle;
 
 namespace
@@ -683,6 +685,34 @@
     EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::green);
 }
 
+// Regression test for a bug that cause mipmaps to only generate using the top left corner as input.
+TEST_P(MipmapTest, MipMapGenerationD3D9Bug)
+{
+    if (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8") ||
+        !extensionEnabled("GL_ANGLE_texture_usage"))
+    {
+        std::cout << "Test skipped due to missing extensions." << std::endl;
+        return;
+    }
+
+    const GLColor mip0Color[4] = {
+        GLColor::red, GLColor::green, GLColor::red, GLColor::green,
+    };
+    const GLColor mip1Color = GLColor(127, 127, 0, 255);
+
+    GLTexture texture;
+    glBindTexture(GL_TEXTURE_2D, texture.get());
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+    glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA8_OES, 2, 2);
+    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, mip0Color);
+    glGenerateMipmap(GL_TEXTURE_2D);
+
+    // Only draw to a 1 pixel viewport so the lower mip is used
+    clearAndDrawQuad(m2DProgram, 1, 1);
+    EXPECT_PIXEL_COLOR_NEAR(0, 0, mip1Color, 1.0);
+}
+
 // This test ensures that the level-zero workaround for TextureCubes (on D3D11 Feature Level 9_3)
 // works as expected. It tests enabling/disabling mipmaps, generating mipmaps, and rendering to level zero.
 TEST_P(MipmapTest, TextureCubeGeneralLevelZero)