Android: remove headers from LOCAL_SRC_FILES
[mesa.git] / src / mesa / state_tracker / st_atom_scissor.c
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 * Authors:
30 * Keith Whitwell <keithw@vmware.com>
31 */
32
33
34 #include "main/macros.h"
35 #include "st_context.h"
36 #include "pipe/p_context.h"
37 #include "st_atom.h"
38
39
40 /**
41 * Scissor depends on the scissor box, and the framebuffer dimensions.
42 */
43 static void
44 update_scissor( struct st_context *st )
45 {
46 struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
47 const struct gl_context *ctx = st->ctx;
48 const struct gl_framebuffer *fb = ctx->DrawBuffer;
49 GLint miny, maxy;
50 unsigned i;
51 bool changed = false;
52 for (i = 0 ; i < ctx->Const.MaxViewports; i++) {
53 scissor[i].minx = 0;
54 scissor[i].miny = 0;
55 scissor[i].maxx = fb->Width;
56 scissor[i].maxy = fb->Height;
57
58 if (ctx->Scissor.EnableFlags & (1 << i)) {
59 /* need to be careful here with xmax or ymax < 0 */
60 GLint xmax = MAX2(0, ctx->Scissor.ScissorArray[i].X + ctx->Scissor.ScissorArray[i].Width);
61 GLint ymax = MAX2(0, ctx->Scissor.ScissorArray[i].Y + ctx->Scissor.ScissorArray[i].Height);
62
63 if (ctx->Scissor.ScissorArray[i].X > (GLint)scissor[i].minx)
64 scissor[i].minx = ctx->Scissor.ScissorArray[i].X;
65 if (ctx->Scissor.ScissorArray[i].Y > (GLint)scissor[i].miny)
66 scissor[i].miny = ctx->Scissor.ScissorArray[i].Y;
67
68 if (xmax < (GLint) scissor[i].maxx)
69 scissor[i].maxx = xmax;
70 if (ymax < (GLint) scissor[i].maxy)
71 scissor[i].maxy = ymax;
72
73 /* check for null space */
74 if (scissor[i].minx >= scissor[i].maxx || scissor[i].miny >= scissor[i].maxy)
75 scissor[i].minx = scissor[i].miny = scissor[i].maxx = scissor[i].maxy = 0;
76 }
77
78 /* Now invert Y if needed.
79 * Gallium drivers use the convention Y=0=top for surfaces.
80 */
81 if (st_fb_orientation(fb) == Y_0_TOP) {
82 miny = fb->Height - scissor[i].maxy;
83 maxy = fb->Height - scissor[i].miny;
84 scissor[i].miny = miny;
85 scissor[i].maxy = maxy;
86 }
87
88 if (memcmp(&scissor[i], &st->state.scissor[i], sizeof(scissor[0])) != 0) {
89 /* state has changed */
90 st->state.scissor[i] = scissor[i]; /* struct copy */
91 changed = true;
92 }
93 }
94 if (changed)
95 st->pipe->set_scissor_states(st->pipe, 0, ctx->Const.MaxViewports, scissor); /* activate */
96 }
97
98
99 const struct st_tracked_state st_update_scissor = {
100 "st_update_scissor", /* name */
101 { /* dirty */
102 (_NEW_SCISSOR | _NEW_BUFFERS), /* mesa */
103 0, /* st */
104 },
105 update_scissor /* update */
106 };