1 /*
2  * Copyright 2010 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #include <stdio.h>
24 #include <errno.h>
25 #include "pipe/p_defines.h"
26 #include "pipe/p_state.h"
27 #include "pipe/p_context.h"
28 #include "pipe/p_screen.h"
29 #include "util/u_memory.h"
30 #include "util/u_inlines.h"
31 #include "util/u_transfer.h"
32 
noop_draw_vbo(struct pipe_context * ctx,const struct pipe_draw_info * info)33 static void noop_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
34 {
35 }
36 
noop_set_blend_color(struct pipe_context * ctx,const struct pipe_blend_color * state)37 static void noop_set_blend_color(struct pipe_context *ctx,
38 					const struct pipe_blend_color *state)
39 {
40 }
41 
noop_create_blend_state(struct pipe_context * ctx,const struct pipe_blend_state * state)42 static void *noop_create_blend_state(struct pipe_context *ctx,
43 					const struct pipe_blend_state *state)
44 {
45 	struct pipe_blend_state *nstate = CALLOC_STRUCT(pipe_blend_state);
46 
47 	if (nstate == NULL) {
48 		return NULL;
49 	}
50 	*nstate = *state;
51 	return nstate;
52 }
53 
noop_create_dsa_state(struct pipe_context * ctx,const struct pipe_depth_stencil_alpha_state * state)54 static void *noop_create_dsa_state(struct pipe_context *ctx,
55 				   const struct pipe_depth_stencil_alpha_state *state)
56 {
57 	struct pipe_depth_stencil_alpha_state *nstate = CALLOC_STRUCT(pipe_depth_stencil_alpha_state);
58 
59 	if (nstate == NULL) {
60 		return NULL;
61 	}
62 	*nstate = *state;
63 	return nstate;
64 }
65 
noop_create_rs_state(struct pipe_context * ctx,const struct pipe_rasterizer_state * state)66 static void *noop_create_rs_state(struct pipe_context *ctx,
67 					const struct pipe_rasterizer_state *state)
68 {
69 	struct pipe_rasterizer_state *nstate = CALLOC_STRUCT(pipe_rasterizer_state);
70 
71 	if (nstate == NULL) {
72 		return NULL;
73 	}
74 	*nstate = *state;
75 	return nstate;
76 }
77 
noop_create_sampler_state(struct pipe_context * ctx,const struct pipe_sampler_state * state)78 static void *noop_create_sampler_state(struct pipe_context *ctx,
79 					const struct pipe_sampler_state *state)
80 {
81 	struct pipe_sampler_state *nstate = CALLOC_STRUCT(pipe_sampler_state);
82 
83 	if (nstate == NULL) {
84 		return NULL;
85 	}
86 	*nstate = *state;
87 	return nstate;
88 }
89 
noop_create_sampler_view(struct pipe_context * ctx,struct pipe_resource * texture,const struct pipe_sampler_view * state)90 static struct pipe_sampler_view *noop_create_sampler_view(struct pipe_context *ctx,
91 							struct pipe_resource *texture,
92 							const struct pipe_sampler_view *state)
93 {
94 	struct pipe_sampler_view *sampler_view = CALLOC_STRUCT(pipe_sampler_view);
95 
96 	if (sampler_view == NULL)
97 		return NULL;
98 	/* initialize base object */
99 	pipe_resource_reference(&sampler_view->texture, texture);
100 	pipe_reference_init(&sampler_view->reference, 1);
101 	sampler_view->context = ctx;
102 	return sampler_view;
103 }
104 
noop_create_surface(struct pipe_context * ctx,struct pipe_resource * texture,const struct pipe_surface * surf_tmpl)105 static struct pipe_surface *noop_create_surface(struct pipe_context *ctx,
106 						struct pipe_resource *texture,
107 						const struct pipe_surface *surf_tmpl)
108 {
109 	struct pipe_surface *surface = CALLOC_STRUCT(pipe_surface);
110 
111 	if (surface == NULL)
112 		return NULL;
113 	pipe_reference_init(&surface->reference, 1);
114 	pipe_resource_reference(&surface->texture, texture);
115 	surface->context = ctx;
116 	surface->format = surf_tmpl->format;
117 	surface->width = texture->width0;
118 	surface->height = texture->height0;
119 	surface->usage = surf_tmpl->usage;
120 	surface->texture = texture;
121 	surface->u.tex.first_layer = surf_tmpl->u.tex.first_layer;
122 	surface->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
123 	surface->u.tex.level = surf_tmpl->u.tex.level;
124 
125 	return surface;
126 }
127 
noop_set_vs_sampler_view(struct pipe_context * ctx,unsigned count,struct pipe_sampler_view ** views)128 static void noop_set_vs_sampler_view(struct pipe_context *ctx, unsigned count,
129 					struct pipe_sampler_view **views)
130 {
131 }
132 
noop_set_ps_sampler_view(struct pipe_context * ctx,unsigned count,struct pipe_sampler_view ** views)133 static void noop_set_ps_sampler_view(struct pipe_context *ctx, unsigned count,
134 					struct pipe_sampler_view **views)
135 {
136 }
137 
noop_bind_sampler(struct pipe_context * ctx,unsigned count,void ** states)138 static void noop_bind_sampler(struct pipe_context *ctx, unsigned count, void **states)
139 {
140 }
141 
noop_set_clip_state(struct pipe_context * ctx,const struct pipe_clip_state * state)142 static void noop_set_clip_state(struct pipe_context *ctx,
143 				const struct pipe_clip_state *state)
144 {
145 }
146 
noop_set_polygon_stipple(struct pipe_context * ctx,const struct pipe_poly_stipple * state)147 static void noop_set_polygon_stipple(struct pipe_context *ctx,
148 					 const struct pipe_poly_stipple *state)
149 {
150 }
151 
noop_set_sample_mask(struct pipe_context * pipe,unsigned sample_mask)152 static void noop_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask)
153 {
154 }
155 
noop_set_scissor_state(struct pipe_context * ctx,const struct pipe_scissor_state * state)156 static void noop_set_scissor_state(struct pipe_context *ctx,
157 					const struct pipe_scissor_state *state)
158 {
159 }
160 
noop_set_stencil_ref(struct pipe_context * ctx,const struct pipe_stencil_ref * state)161 static void noop_set_stencil_ref(struct pipe_context *ctx,
162 				const struct pipe_stencil_ref *state)
163 {
164 }
165 
noop_set_viewport_state(struct pipe_context * ctx,const struct pipe_viewport_state * state)166 static void noop_set_viewport_state(struct pipe_context *ctx,
167 					const struct pipe_viewport_state *state)
168 {
169 }
170 
noop_set_framebuffer_state(struct pipe_context * ctx,const struct pipe_framebuffer_state * state)171 static void noop_set_framebuffer_state(struct pipe_context *ctx,
172 					const struct pipe_framebuffer_state *state)
173 {
174 }
175 
noop_set_constant_buffer(struct pipe_context * ctx,uint shader,uint index,struct pipe_constant_buffer * cb)176 static void noop_set_constant_buffer(struct pipe_context *ctx,
177 					uint shader, uint index,
178 					struct pipe_constant_buffer *cb)
179 {
180 }
181 
182 
noop_sampler_view_destroy(struct pipe_context * ctx,struct pipe_sampler_view * state)183 static void noop_sampler_view_destroy(struct pipe_context *ctx,
184 				struct pipe_sampler_view *state)
185 {
186 	pipe_resource_reference(&state->texture, NULL);
187 	FREE(state);
188 }
189 
190 
noop_surface_destroy(struct pipe_context * ctx,struct pipe_surface * surface)191 static void noop_surface_destroy(struct pipe_context *ctx,
192 				 struct pipe_surface *surface)
193 {
194 	pipe_resource_reference(&surface->texture, NULL);
195 	FREE(surface);
196 }
197 
noop_bind_state(struct pipe_context * ctx,void * state)198 static void noop_bind_state(struct pipe_context *ctx, void *state)
199 {
200 }
201 
noop_delete_state(struct pipe_context * ctx,void * state)202 static void noop_delete_state(struct pipe_context *ctx, void *state)
203 {
204 	FREE(state);
205 }
206 
noop_delete_vertex_element(struct pipe_context * ctx,void * state)207 static void noop_delete_vertex_element(struct pipe_context *ctx, void *state)
208 {
209 	FREE(state);
210 }
211 
212 
noop_set_index_buffer(struct pipe_context * ctx,const struct pipe_index_buffer * ib)213 static void noop_set_index_buffer(struct pipe_context *ctx,
214 					const struct pipe_index_buffer *ib)
215 {
216 }
217 
noop_set_vertex_buffers(struct pipe_context * ctx,unsigned count,const struct pipe_vertex_buffer * buffers)218 static void noop_set_vertex_buffers(struct pipe_context *ctx, unsigned count,
219 					const struct pipe_vertex_buffer *buffers)
220 {
221 }
222 
noop_create_vertex_elements(struct pipe_context * ctx,unsigned count,const struct pipe_vertex_element * state)223 static void *noop_create_vertex_elements(struct pipe_context *ctx,
224 					unsigned count,
225 					const struct pipe_vertex_element *state)
226 {
227 	struct pipe_vertex_element *nstate = CALLOC_STRUCT(pipe_vertex_element);
228 
229 	if (nstate == NULL) {
230 		return NULL;
231 	}
232 	*nstate = *state;
233 	return nstate;
234 }
235 
noop_create_shader_state(struct pipe_context * ctx,const struct pipe_shader_state * state)236 static void *noop_create_shader_state(struct pipe_context *ctx,
237 					const struct pipe_shader_state *state)
238 {
239 	struct pipe_shader_state *nstate = CALLOC_STRUCT(pipe_shader_state);
240 
241 	if (nstate == NULL) {
242 		return NULL;
243 	}
244 	*nstate = *state;
245 	return nstate;
246 }
247 
noop_create_stream_output_target(struct pipe_context * ctx,struct pipe_resource * res,unsigned buffer_offset,unsigned buffer_size)248 static struct pipe_stream_output_target *noop_create_stream_output_target(
249       struct pipe_context *ctx,
250       struct pipe_resource *res,
251       unsigned buffer_offset,
252       unsigned buffer_size)
253 {
254    struct pipe_stream_output_target *t = CALLOC_STRUCT(pipe_stream_output_target);
255    if (!t)
256       return NULL;
257 
258    pipe_reference_init(&t->reference, 1);
259    pipe_resource_reference(&t->buffer, res);
260    t->buffer_offset = buffer_offset;
261    t->buffer_size = buffer_size;
262    return t;
263 }
264 
noop_stream_output_target_destroy(struct pipe_context * ctx,struct pipe_stream_output_target * t)265 static void noop_stream_output_target_destroy(struct pipe_context *ctx,
266                                       struct pipe_stream_output_target *t)
267 {
268    pipe_resource_reference(&t->buffer, NULL);
269    FREE(t);
270 }
271 
noop_set_stream_output_targets(struct pipe_context * ctx,unsigned num_targets,struct pipe_stream_output_target ** targets,unsigned append_bitmask)272 static void noop_set_stream_output_targets(struct pipe_context *ctx,
273                            unsigned num_targets,
274                            struct pipe_stream_output_target **targets,
275                            unsigned append_bitmask)
276 {
277 }
278 
279 void noop_init_state_functions(struct pipe_context *ctx);
280 
noop_init_state_functions(struct pipe_context * ctx)281 void noop_init_state_functions(struct pipe_context *ctx)
282 {
283 	ctx->create_blend_state = noop_create_blend_state;
284 	ctx->create_depth_stencil_alpha_state = noop_create_dsa_state;
285 	ctx->create_fs_state = noop_create_shader_state;
286 	ctx->create_rasterizer_state = noop_create_rs_state;
287 	ctx->create_sampler_state = noop_create_sampler_state;
288 	ctx->create_sampler_view = noop_create_sampler_view;
289 	ctx->create_surface = noop_create_surface;
290 	ctx->create_vertex_elements_state = noop_create_vertex_elements;
291 	ctx->create_vs_state = noop_create_shader_state;
292 	ctx->bind_blend_state = noop_bind_state;
293 	ctx->bind_depth_stencil_alpha_state = noop_bind_state;
294 	ctx->bind_fragment_sampler_states = noop_bind_sampler;
295 	ctx->bind_fs_state = noop_bind_state;
296 	ctx->bind_rasterizer_state = noop_bind_state;
297 	ctx->bind_vertex_elements_state = noop_bind_state;
298 	ctx->bind_vertex_sampler_states = noop_bind_sampler;
299 	ctx->bind_vs_state = noop_bind_state;
300 	ctx->delete_blend_state = noop_delete_state;
301 	ctx->delete_depth_stencil_alpha_state = noop_delete_state;
302 	ctx->delete_fs_state = noop_delete_state;
303 	ctx->delete_rasterizer_state = noop_delete_state;
304 	ctx->delete_sampler_state = noop_delete_state;
305 	ctx->delete_vertex_elements_state = noop_delete_vertex_element;
306 	ctx->delete_vs_state = noop_delete_state;
307 	ctx->set_blend_color = noop_set_blend_color;
308 	ctx->set_clip_state = noop_set_clip_state;
309 	ctx->set_constant_buffer = noop_set_constant_buffer;
310 	ctx->set_fragment_sampler_views = noop_set_ps_sampler_view;
311 	ctx->set_framebuffer_state = noop_set_framebuffer_state;
312 	ctx->set_polygon_stipple = noop_set_polygon_stipple;
313 	ctx->set_sample_mask = noop_set_sample_mask;
314 	ctx->set_scissor_state = noop_set_scissor_state;
315 	ctx->set_stencil_ref = noop_set_stencil_ref;
316 	ctx->set_vertex_buffers = noop_set_vertex_buffers;
317 	ctx->set_index_buffer = noop_set_index_buffer;
318 	ctx->set_vertex_sampler_views = noop_set_vs_sampler_view;
319 	ctx->set_viewport_state = noop_set_viewport_state;
320 	ctx->sampler_view_destroy = noop_sampler_view_destroy;
321 	ctx->surface_destroy = noop_surface_destroy;
322 	ctx->draw_vbo = noop_draw_vbo;
323 	ctx->create_stream_output_target = noop_create_stream_output_target;
324 	ctx->stream_output_target_destroy = noop_stream_output_target_destroy;
325 	ctx->set_stream_output_targets = noop_set_stream_output_targets;
326 }
327