svga: Disable debug message.
[mesa.git] / src / gallium / auxiliary / util / u_blitter.h
1 /**************************************************************************
2 *
3 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 **************************************************************************/
26
27 #ifndef U_BLITTER_H
28 #define U_BLITTER_H
29
30 #include "util/u_memory.h"
31
32 #include "pipe/p_state.h"
33
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 struct pipe_context;
40
41 struct blitter_context
42 {
43 /* Private members, really. */
44 void *saved_blend_state; /**< blend state */
45 void *saved_dsa_state; /**< depth stencil alpha state */
46 void *saved_velem_state; /**< vertex elements state */
47 void *saved_rs_state; /**< rasterizer state */
48 void *saved_fs, *saved_vs; /**< fragment shader, vertex shader */
49
50 struct pipe_framebuffer_state saved_fb_state; /**< framebuffer state */
51 struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */
52 struct pipe_viewport_state saved_viewport;
53 struct pipe_clip_state saved_clip;
54
55 int saved_num_sampler_states;
56 void *saved_sampler_states[32];
57
58 int saved_num_textures;
59 struct pipe_texture *saved_textures[32]; /* is 32 enough? */
60 };
61
62 /**
63 * Create a blitter context.
64 */
65 struct blitter_context *util_blitter_create(struct pipe_context *pipe);
66
67 /**
68 * Destroy a blitter context.
69 */
70 void util_blitter_destroy(struct blitter_context *blitter);
71
72 /*
73 * These CSOs must be saved before any of the following functions is called:
74 * - blend state
75 * - depth stencil alpha state
76 * - rasterizer state
77 * - vertex shader
78 * - fragment shader
79 */
80
81 /**
82 * Clear a specified set of currently bound buffers to specified values.
83 */
84 void util_blitter_clear(struct blitter_context *blitter,
85 unsigned width, unsigned height,
86 unsigned num_cbufs,
87 unsigned clear_buffers,
88 const float *rgba,
89 double depth, unsigned stencil);
90
91 /**
92 * Copy a block of pixels from one surface to another.
93 *
94 * You can copy from any color format to any other color format provided
95 * the former can be sampled and the latter can be rendered to. Otherwise,
96 * a software fallback path is taken and both surfaces must be of the same
97 * format.
98 *
99 * The same holds for depth-stencil formats with the exception that stencil
100 * cannot be copied unless you set ignore_stencil to FALSE. In that case,
101 * a software fallback path is taken and both surfaces must be of the same
102 * format.
103 *
104 * Use pipe_screen->is_format_supported to know your options.
105 *
106 * These states must be saved in the blitter in addition to the state objects
107 * already required to be saved:
108 * - framebuffer state
109 * - fragment sampler states
110 * - fragment sampler textures
111 */
112 void util_blitter_copy(struct blitter_context *blitter,
113 struct pipe_surface *dst,
114 unsigned dstx, unsigned dsty,
115 struct pipe_surface *src,
116 unsigned srcx, unsigned srcy,
117 unsigned width, unsigned height,
118 boolean ignore_stencil);
119
120 /**
121 * Fill a region of a surface with a constant value.
122 *
123 * If the surface cannot be rendered to or it's a depth-stencil format,
124 * a software fallback path is taken.
125 *
126 * These states must be saved in the blitter in addition to the state objects
127 * already required to be saved:
128 * - framebuffer state
129 */
130 void util_blitter_fill(struct blitter_context *blitter,
131 struct pipe_surface *dst,
132 unsigned dstx, unsigned dsty,
133 unsigned width, unsigned height,
134 unsigned value);
135
136 /**
137 * Copy all pixels from one surface to another.
138 *
139 * The rules are the same as in util_blitter_copy with the addition that
140 * surfaces must have the same size.
141 */
142 static INLINE
143 void util_blitter_copy_surface(struct blitter_context *blitter,
144 struct pipe_surface *dst,
145 struct pipe_surface *src,
146 boolean ignore_stencil)
147 {
148 assert(dst->width == src->width && dst->height == src->height);
149
150 util_blitter_copy(blitter, dst, 0, 0, src, 0, 0, src->width, src->height,
151 ignore_stencil);
152 }
153
154
155 /* The functions below should be used to save currently bound constant state
156 * objects inside a driver. The objects are automatically restored at the end
157 * of the util_blitter_{clear, fill, copy, copy_surface} functions and then
158 * forgotten.
159 *
160 * CSOs not listed here are not affected by util_blitter. */
161
162 static INLINE
163 void util_blitter_save_blend(struct blitter_context *blitter,
164 void *state)
165 {
166 blitter->saved_blend_state = state;
167 }
168
169 static INLINE
170 void util_blitter_save_depth_stencil_alpha(struct blitter_context *blitter,
171 void *state)
172 {
173 blitter->saved_dsa_state = state;
174 }
175
176 static INLINE
177 void util_blitter_save_vertex_elements(struct blitter_context *blitter,
178 void *state)
179 {
180 blitter->saved_velem_state = state;
181 }
182
183 static INLINE
184 void util_blitter_save_stencil_ref(struct blitter_context *blitter,
185 const struct pipe_stencil_ref *state)
186 {
187 blitter->saved_stencil_ref = *state;
188 }
189
190 static INLINE
191 void util_blitter_save_rasterizer(struct blitter_context *blitter,
192 void *state)
193 {
194 blitter->saved_rs_state = state;
195 }
196
197 static INLINE
198 void util_blitter_save_fragment_shader(struct blitter_context *blitter,
199 void *fs)
200 {
201 blitter->saved_fs = fs;
202 }
203
204 static INLINE
205 void util_blitter_save_vertex_shader(struct blitter_context *blitter,
206 void *vs)
207 {
208 blitter->saved_vs = vs;
209 }
210
211 static INLINE
212 void util_blitter_save_framebuffer(struct blitter_context *blitter,
213 struct pipe_framebuffer_state *state)
214 {
215 blitter->saved_fb_state = *state;
216 }
217
218 static INLINE
219 void util_blitter_save_viewport(struct blitter_context *blitter,
220 struct pipe_viewport_state *state)
221 {
222 blitter->saved_viewport = *state;
223 }
224
225 static INLINE
226 void util_blitter_save_clip(struct blitter_context *blitter,
227 struct pipe_clip_state *state)
228 {
229 blitter->saved_clip = *state;
230 }
231
232 static INLINE
233 void util_blitter_save_fragment_sampler_states(
234 struct blitter_context *blitter,
235 int num_sampler_states,
236 void **sampler_states)
237 {
238 assert(num_sampler_states <= Elements(blitter->saved_sampler_states));
239
240 blitter->saved_num_sampler_states = num_sampler_states;
241 memcpy(blitter->saved_sampler_states, sampler_states,
242 num_sampler_states * sizeof(void *));
243 }
244
245 static INLINE
246 void util_blitter_save_fragment_sampler_textures(
247 struct blitter_context *blitter,
248 int num_textures,
249 struct pipe_texture **textures)
250 {
251 assert(num_textures <= Elements(blitter->saved_textures));
252
253 blitter->saved_num_textures = num_textures;
254 memcpy(blitter->saved_textures, textures,
255 num_textures * sizeof(struct pipe_texture *));
256 }
257
258 #ifdef __cplusplus
259 }
260 #endif
261
262 #endif