Bug 625043: Properly save and restore old clip rect. r=jrmuizel a=blocking-final
authorBas Schouten <bschouten@mozilla.com>
Mon, 24 Jan 2011 19:57:19 +0100
changeset 61179 3f19e5698520a8cd63e15719a8dce7f2bd90463c
parent 61178 6128904992831ad1d9b65880417e6998e5eaed06
child 61180 ef150764ac976fcb8b17a40f43ce1f93e617297e
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel, blocking-final
bugs625043
milestone2.0b10pre
Bug 625043: Properly save and restore old clip rect. r=jrmuizel a=blocking-final
gfx/layers/d3d9/ContainerLayerD3D9.cpp
--- a/gfx/layers/d3d9/ContainerLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ContainerLayerD3D9.cpp
@@ -164,20 +164,22 @@ HasOpaqueAncestorLayer(Layer* aLayer)
 }
 
 void
 ContainerLayerD3D9::RenderLayer()
 {
   nsRefPtr<IDirect3DSurface9> previousRenderTarget;
   nsRefPtr<IDirect3DTexture9> renderTexture;
   float previousRenderTargetOffset[4];
-  RECT oldClipRect;
+  RECT containerClipRect;
   float renderTargetOffset[] = { 0, 0, 0, 0 };
   float oldViewMatrix[4][4];
 
+  device()->GetScissorRect(&containerClipRect);
+
   nsIntRect visibleRect = mVisibleRegion.GetBounds();
   PRBool useIntermediate = UseIntermediateSurface();
 
   mSupportsComponentAlphaChildren = PR_FALSE;
   gfxMatrix contTransform;
   if (useIntermediate) {
     device()->GetRenderTarget(0, getter_AddRefs(previousRenderTarget));
     device()->CreateTexture(visibleRect.width, visibleRect.height, 1,
@@ -254,17 +256,16 @@ ContainerLayerD3D9::RenderLayer()
     const nsIntRect* clipRect = layerToRender->GetLayer()->GetClipRect();
     if ((clipRect && clipRect->IsEmpty()) ||
         layerToRender->GetLayer()->GetEffectiveVisibleRegion().IsEmpty()) {
       continue;
     }
 
     if (clipRect || useIntermediate) {
       RECT r;
-      device()->GetScissorRect(&oldClipRect);
       if (clipRect) {
         r.left = (LONG)(clipRect->x - renderTargetOffset[0]);
         r.top = (LONG)(clipRect->y - renderTargetOffset[1]);
         r.right = (LONG)(clipRect->x - renderTargetOffset[0] + clipRect->width);
         r.bottom = (LONG)(clipRect->y - renderTargetOffset[1] + clipRect->height);
       } else {
         r.left = 0;
         r.top = 0;
@@ -294,36 +295,32 @@ ContainerLayerD3D9::RenderLayer()
             r.left = 0;
             r.top = 0;
             r.right = visibleRect.width;
             r.bottom = visibleRect.height;
             clipRect = nsnull;
           }
         }
         // Intersect with current clip rect.
-        r.left = NS_MAX<PRInt32>(oldClipRect.left, r.left);
-        r.right = NS_MIN<PRInt32>(oldClipRect.right, r.right);
-        r.top = NS_MAX<PRInt32>(oldClipRect.top, r.top);
-        r.bottom = NS_MIN<PRInt32>(oldClipRect.bottom, r.bottom);
+        r.left = NS_MAX<PRInt32>(containerClipRect.left, r.left);
+        r.right = NS_MIN<PRInt32>(containerClipRect.right, r.right);
+        r.top = NS_MAX<PRInt32>(containerClipRect.top, r.top);
+        r.bottom = NS_MIN<PRInt32>(containerClipRect.bottom, r.bottom);
       } else {
         // > 0 is implied during the intersection when useIntermediate == true;
         r.left = NS_MAX<LONG>(0, r.left);
         r.top = NS_MAX<LONG>(0, r.top);
       }
       r.bottom = NS_MIN<LONG>(r.bottom, desc.Height);
       r.right = NS_MIN<LONG>(r.right, desc.Width);
 
       device()->SetScissorRect(&r);
     }
 
     layerToRender->RenderLayer();
-
-    if (clipRect || useIntermediate) {
-      device()->SetScissorRect(&oldClipRect);
-    }
   }
 
   if (useIntermediate) {
     device()->SetRenderTarget(0, previousRenderTarget);
     device()->SetVertexShaderConstantF(CBvRenderTargetOffset, previousRenderTargetOffset, 1);
     device()->SetVertexShaderConstantF(CBmProjection, &oldViewMatrix[0][0], 4);
 
     device()->SetVertexShaderConstantF(CBvLayerQuad,
@@ -332,18 +329,21 @@ ContainerLayerD3D9::RenderLayer()
                                                           visibleRect.width,
                                                           visibleRect.height),
                                        1);
 
     SetShaderTransformAndOpacity();
 
     mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
 
+    device()->SetScissorRect(&containerClipRect);
     device()->SetTexture(0, renderTexture);
     device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
+  } else {
+    device()->SetScissorRect(&containerClipRect);
   }
 }
 
 void
 ContainerLayerD3D9::LayerManagerDestroyed()
 {
   while (mFirstChild) {
     GetFirstChildD3D9()->LayerManagerDestroyed();