st/nine: Back scissor to nine_context

Part of the refactor to move all gallium calls to
nine_state.c, and have all internal states required
for those calls in nine_context.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c
index 7b0009d9..8f9872c 100644
--- a/src/gallium/state_trackers/nine/device9.c
+++ b/src/gallium/state_trackers/nine/device9.c
@@ -105,6 +105,8 @@
     This->state.scissor.maxx = refSurf->desc.Width;
     This->state.scissor.maxy = refSurf->desc.Height;
 
+    nine_context_set_scissor(This, &This->state.scissor);
+
     if (This->nswapchains && This->swapchains[0]->params.EnableAutoDepthStencil) {
         nine_context_set_render_state(This, D3DRS_ZENABLE, TRUE);
         This->state.rs_advertised[D3DRS_ZENABLE] = TRUE;
@@ -2711,7 +2713,10 @@
     state->scissor.maxx = pRect->right;
     state->scissor.maxy = pRect->bottom;
 
-    state->changed.group |= NINE_STATE_SCISSOR;
+    if (unlikely(This->is_recording))
+        state->changed.group |= NINE_STATE_SCISSOR;
+    else
+        nine_context_set_scissor(This, &state->scissor);
 
     return D3D_OK;
 }
diff --git a/src/gallium/state_trackers/nine/nine_state.c b/src/gallium/state_trackers/nine/nine_state.c
index 4b5b199..89d7b10 100644
--- a/src/gallium/state_trackers/nine/nine_state.c
+++ b/src/gallium/state_trackers/nine/nine_state.c
@@ -824,7 +824,7 @@
 {
     struct pipe_context *pipe = device->pipe;
 
-    pipe->set_scissor_states(pipe, 0, 1, &device->state.scissor);
+    pipe->set_scissor_states(pipe, 0, 1, &device->context.scissor);
 }
 
 static inline void
@@ -1441,7 +1441,12 @@
     const unsigned i = RenderTargetIndex;
 
     if (i == 0) {
-        /* viewport and scissor changes */
+        context->scissor.minx = 0;
+        context->scissor.miny = 0;
+        context->scissor.maxx = rt->desc.Width;
+        context->scissor.maxy = rt->desc.Height;
+
+        /* viewport changes */
         state->changed.group |= NINE_STATE_VIEWPORT | NINE_STATE_SCISSOR | NINE_STATE_MULTISAMPLE;
 
         if (context->rt[0] &&
@@ -1457,6 +1462,17 @@
 }
 
 void
+nine_context_set_scissor(struct NineDevice9 *device,
+                         const struct pipe_scissor_state *scissor)
+{
+    struct nine_state *state = &device->state;
+    struct nine_context *context = &device->context;
+
+    context->scissor = *scissor;
+    state->changed.group |= NINE_STATE_SCISSOR;
+}
+
+void
 nine_context_apply_stateblock(struct NineDevice9 *device,
                               const struct nine_state *src)
 {
@@ -1605,6 +1621,10 @@
         context->changed.ps_const_i = !!src->changed.ps_const_i;
         context->changed.ps_const_b = !!src->changed.ps_const_b;
     }
+
+    /* Scissor */
+    if (src->changed.group & NINE_STATE_SCISSOR)
+        context->scissor = src->scissor;
 }
 
 static void
@@ -1659,10 +1679,10 @@
 
     /* Both rectangles apply, which is weird, but that's D3D9. */
     if (context->rs[D3DRS_SCISSORTESTENABLE]) {
-        rect.x1 = MAX2(rect.x1, device->state.scissor.minx);
-        rect.y1 = MAX2(rect.y1, device->state.scissor.miny);
-        rect.x2 = MIN2(rect.x2, device->state.scissor.maxx);
-        rect.y2 = MIN2(rect.y2, device->state.scissor.maxy);
+        rect.x1 = MAX2(rect.x1, context->scissor.minx);
+        rect.y1 = MAX2(rect.y1, context->scissor.miny);
+        rect.x2 = MIN2(rect.x2, context->scissor.maxx);
+        rect.y2 = MIN2(rect.y2, context->scissor.maxy);
     }
 
     if (Count) {
diff --git a/src/gallium/state_trackers/nine/nine_state.h b/src/gallium/state_trackers/nine/nine_state.h
index 50fecd0..28a6d6c 100644
--- a/src/gallium/state_trackers/nine/nine_state.h
+++ b/src/gallium/state_trackers/nine/nine_state.h
@@ -238,6 +238,8 @@
 
     uint8_t rt_mask;
 
+    struct pipe_scissor_state scissor;
+
     struct NineVertexShader9 *vs;
     BOOL programmable_vs;
     float *vs_const_f;
@@ -383,6 +385,10 @@
                                          UINT BoolCount);
 
 void
+nine_context_set_scissor(struct NineDevice9 *device,
+                         const struct pipe_scissor_state *scissor);
+
+void
 nine_context_set_render_target(struct NineDevice9 *device,
                                DWORD RenderTargetIndex,
                                struct NineSurface9 *rt);