1/**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29#include "main/context.h"
30#include "main/viewport.h"
31#include "st_context.h"
32#include "st_atom.h"
33#include "st_util.h"
34#include "pipe/p_context.h"
35#include "cso_cache/cso_context.h"
36
37/**
38 * Update the viewport transformation matrix.  Depends on:
39 *  - viewport pos/size
40 *  - depthrange
41 *  - window pos/size or FBO size
42 */
43void
44st_update_viewport( struct st_context *st )
45{
46   struct gl_context *ctx = st->ctx;
47   unsigned i;
48
49   /* _NEW_VIEWPORT
50    */
51   for (i = 0; i < st->state.num_viewports; i++) {
52      float *scale = st->state.viewport[i].scale;
53      float *translate = st->state.viewport[i].translate;
54
55      _mesa_get_viewport_xform(ctx, i, scale, translate);
56
57      /* _NEW_BUFFERS */
58      /* Drawing to a window where the coordinate system is upside down. */
59      if (st->state.fb_orientation == Y_0_TOP) {
60         scale[1] *= -1;
61         translate[1] = st->state.fb_height - translate[1];
62      }
63   }
64
65   cso_set_viewport(st->cso_context, &st->state.viewport[0]);
66
67   if (st->state.num_viewports > 1) {
68      struct pipe_context *pipe = st->pipe;
69
70      pipe->set_viewport_states(pipe, 1, st->state.num_viewports - 1,
71                                &st->state.viewport[1]);
72   }
73}
74