svga: Remove unnecessary headers.
[mesa.git] / src / gallium / drivers / svga / svga_pipe_misc.c
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #include "svga_cmd.h"
27
28 #include "svga_context.h"
29 #include "svga_screen_texture.h"
30
31
32 static void svga_set_scissor_state( struct pipe_context *pipe,
33 const struct pipe_scissor_state *scissor )
34 {
35 struct svga_context *svga = svga_context(pipe);
36
37 memcpy( &svga->curr.scissor, scissor, sizeof(*scissor) );
38 svga->dirty |= SVGA_NEW_SCISSOR;
39 }
40
41
42 static void svga_set_polygon_stipple( struct pipe_context *pipe,
43 const struct pipe_poly_stipple *stipple )
44 {
45 /* overridden by the draw module */
46 }
47
48
49 void svga_cleanup_framebuffer(struct svga_context *svga)
50 {
51 struct pipe_framebuffer_state *curr = &svga->curr.framebuffer;
52 struct pipe_framebuffer_state *hw = &svga->state.hw_clear.framebuffer;
53 int i;
54
55 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
56 pipe_surface_reference(&curr->cbufs[i], NULL);
57 pipe_surface_reference(&hw->cbufs[i], NULL);
58 }
59
60 pipe_surface_reference(&curr->zsbuf, NULL);
61 pipe_surface_reference(&hw->zsbuf, NULL);
62 }
63
64
65 #define DEPTH_BIAS_SCALE_FACTOR_D16 ((float)(1<<15))
66 #define DEPTH_BIAS_SCALE_FACTOR_D24S8 ((float)(1<<23))
67 #define DEPTH_BIAS_SCALE_FACTOR_D32 ((float)(1<<31))
68
69
70 static void svga_set_framebuffer_state(struct pipe_context *pipe,
71 const struct pipe_framebuffer_state *fb)
72 {
73 struct svga_context *svga = svga_context(pipe);
74 struct pipe_framebuffer_state *dst = &svga->curr.framebuffer;
75 boolean propagate = FALSE;
76 int i;
77
78 dst->width = fb->width;
79 dst->height = fb->height;
80 dst->nr_cbufs = fb->nr_cbufs;
81
82 /* check if we need to propaget any of the target surfaces */
83 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
84 if (dst->cbufs[i] && dst->cbufs[i] != fb->cbufs[i])
85 if (svga_surface_needs_propagation(dst->cbufs[i]))
86 propagate = TRUE;
87 }
88
89 if (propagate) {
90 /* make sure that drawing calls comes before propagation calls */
91 svga_hwtnl_flush_retry( svga );
92
93 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
94 if (dst->cbufs[i] && dst->cbufs[i] != fb->cbufs[i])
95 svga_propagate_surface(pipe, dst->cbufs[i]);
96 }
97
98 /* XXX: Actually the virtual hardware may support rendertargets with
99 * different size, depending on the host API and driver, but since we cannot
100 * know that make no such assumption here. */
101 for(i = 0; i < fb->nr_cbufs; ++i) {
102 if (fb->zsbuf && fb->cbufs[i]) {
103 assert(fb->zsbuf->width == fb->cbufs[i]->width);
104 assert(fb->zsbuf->height == fb->cbufs[i]->height);
105 }
106 }
107
108 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
109 pipe_surface_reference(&dst->cbufs[i], fb->cbufs[i]);
110 pipe_surface_reference(&dst->zsbuf, fb->zsbuf);
111
112
113 if (svga->curr.framebuffer.zsbuf)
114 {
115 switch (svga->curr.framebuffer.zsbuf->format) {
116 case PIPE_FORMAT_Z16_UNORM:
117 svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D16;
118 break;
119 case PIPE_FORMAT_S8Z24_UNORM:
120 case PIPE_FORMAT_X8Z24_UNORM:
121 case PIPE_FORMAT_Z24S8_UNORM:
122 case PIPE_FORMAT_Z24X8_UNORM:
123 svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D24S8;
124 break;
125 case PIPE_FORMAT_Z32_UNORM:
126 svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D32;
127 break;
128 case PIPE_FORMAT_Z32_FLOAT:
129 svga->curr.depthscale = 1.0f / ((float)(1<<23));
130 break;
131 default:
132 svga->curr.depthscale = 0.0f;
133 break;
134 }
135 }
136 else {
137 svga->curr.depthscale = 0.0f;
138 }
139
140 svga->dirty |= SVGA_NEW_FRAME_BUFFER;
141 }
142
143
144
145 static void svga_set_clip_state( struct pipe_context *pipe,
146 const struct pipe_clip_state *clip )
147 {
148 struct svga_context *svga = svga_context(pipe);
149
150 svga->curr.clip = *clip; /* struct copy */
151
152 svga->dirty |= SVGA_NEW_CLIP;
153 }
154
155
156
157 /* Called when driver state tracker notices changes to the viewport
158 * matrix:
159 */
160 static void svga_set_viewport_state( struct pipe_context *pipe,
161 const struct pipe_viewport_state *viewport )
162 {
163 struct svga_context *svga = svga_context(pipe);
164
165 svga->curr.viewport = *viewport; /* struct copy */
166
167 svga->dirty |= SVGA_NEW_VIEWPORT;
168 }
169
170
171
172 void svga_init_misc_functions( struct svga_context *svga )
173 {
174 svga->pipe.set_scissor_state = svga_set_scissor_state;
175 svga->pipe.set_polygon_stipple = svga_set_polygon_stipple;
176 svga->pipe.set_framebuffer_state = svga_set_framebuffer_state;
177 svga->pipe.set_clip_state = svga_set_clip_state;
178 svga->pipe.set_viewport_state = svga_set_viewport_state;
179 }
180
181