Preserve the scissor and viewport rectangles on swap and blit
TRAC #14054
The SetRenderTarget calls used in Blit::boxFilter() and Surface::swap() implicitly reset the scissor and viewport rectangles. So we need to ensure that the original rectangles get captured, and restored afterwards (the Context only keeps track of explicitly changed state).
Signed-off-by: Daniel Koch

git-svn-id: http://angleproject.googlecode.com/svn/trunk@472 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libEGL/Surface.cpp b/src/libEGL/Surface.cpp
index b1a2ddb..3b5add4 100644
--- a/src/libEGL/Surface.cpp
+++ b/src/libEGL/Surface.cpp
@@ -220,6 +220,7 @@
     device->SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
     device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED);
     device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE);
+    device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
     device->SetPixelShader(NULL);
     device->SetVertexShader(NULL);
 
@@ -236,6 +237,11 @@
     device->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
 
     device->SetStreamSourceFreq(0, 1); // DrawPrimitiveUP only cares about stream 0, not the rest.
+
+    RECT scissorRect = {0};   // Scissoring is disabled for flipping, but we need this to capture and restore the old rectangle
+    device->SetScissorRect(&scissorRect);
+    D3DVIEWPORT9 viewport = {0, 0, mWidth, mHeight, 0.0f, 1.0f};
+    device->SetViewport(&viewport);
 }
 
 void Surface::applyFlipState(IDirect3DDevice9 *device)
@@ -296,8 +302,6 @@
 
 void Surface::restoreState(IDirect3DDevice9 *device)
 {
-    mPreFlipState->Apply();
-
     device->SetRenderTarget(0, mPreFlipBackBuffer);
     device->SetDepthStencilSurface(mPreFlipDepthStencil);
 
@@ -312,6 +316,8 @@
         mPreFlipDepthStencil->Release();
         mPreFlipDepthStencil = NULL;
     }
+
+    mPreFlipState->Apply();
 }
 
 // On the next flip, this will cause the state to be recorded from scratch.
diff --git a/src/libGLESv2/Blit.cpp b/src/libGLESv2/Blit.cpp
index c450bc4..7d51a80 100644
--- a/src/libGLESv2/Blit.cpp
+++ b/src/libGLESv2/Blit.cpp
@@ -470,6 +470,9 @@
     {
         device->SetStreamSourceFreq(i, 1);
     }
+
+    RECT scissorRect = {0};   // Scissoring is disabled for flipping, but we need this to capture and restore the old rectangle
+    device->SetScissorRect(&scissorRect);
 }
 
 void Blit::render()