Merge branch '7.8'
[mesa.git] / src / gallium / auxiliary / util / u_blit.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 * @file
30 * Copy/blit pixel rect between surfaces
31 *
32 * @author Brian Paul
33 */
34
35
36 #include "pipe/p_context.h"
37 #include "util/u_debug.h"
38 #include "pipe/p_defines.h"
39 #include "util/u_inlines.h"
40 #include "pipe/p_shader_tokens.h"
41 #include "pipe/p_state.h"
42
43 #include "util/u_blit.h"
44 #include "util/u_draw_quad.h"
45 #include "util/u_format.h"
46 #include "util/u_math.h"
47 #include "util/u_memory.h"
48 #include "util/u_sampler.h"
49 #include "util/u_simple_shaders.h"
50 #include "util/u_surface.h"
51 #include "util/u_rect.h"
52
53 #include "cso_cache/cso_context.h"
54
55
56 struct blit_state
57 {
58 struct pipe_context *pipe;
59 struct cso_context *cso;
60
61 struct pipe_blend_state blend;
62 struct pipe_depth_stencil_alpha_state depthstencil;
63 struct pipe_rasterizer_state rasterizer;
64 struct pipe_sampler_state sampler;
65 struct pipe_viewport_state viewport;
66 struct pipe_clip_state clip;
67 struct pipe_vertex_element velem[2];
68
69 void *vs;
70 void *fs[TGSI_WRITEMASK_XYZW + 1];
71
72 struct pipe_resource *vbuf; /**< quad vertices */
73 unsigned vbuf_slot;
74
75 float vertices[4][2][4]; /**< vertex/texcoords for quad */
76 };
77
78
79 /**
80 * Create state object for blit.
81 * Intended to be created once and re-used for many blit() calls.
82 */
83 struct blit_state *
84 util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
85 {
86 struct blit_state *ctx;
87 uint i;
88
89 ctx = CALLOC_STRUCT(blit_state);
90 if (!ctx)
91 return NULL;
92
93 ctx->pipe = pipe;
94 ctx->cso = cso;
95
96 /* disabled blending/masking */
97 memset(&ctx->blend, 0, sizeof(ctx->blend));
98 ctx->blend.rt[0].colormask = PIPE_MASK_RGBA;
99
100 /* no-op depth/stencil/alpha */
101 memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil));
102
103 /* rasterizer */
104 memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
105 ctx->rasterizer.front_winding = PIPE_WINDING_CW;
106 ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
107 ctx->rasterizer.gl_rasterization_rules = 1;
108
109 /* samplers */
110 memset(&ctx->sampler, 0, sizeof(ctx->sampler));
111 ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
112 ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
113 ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
114 ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
115 ctx->sampler.min_img_filter = 0; /* set later */
116 ctx->sampler.mag_img_filter = 0; /* set later */
117 ctx->sampler.normalized_coords = 1;
118
119 /* vertex elements state */
120 memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2);
121 for (i = 0; i < 2; i++) {
122 ctx->velem[i].src_offset = i * 4 * sizeof(float);
123 ctx->velem[i].instance_divisor = 0;
124 ctx->velem[i].vertex_buffer_index = 0;
125 ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
126 }
127
128 /* vertex shader - still required to provide the linkage between
129 * fragment shader input semantics and vertex_element/buffers.
130 */
131 {
132 const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
133 TGSI_SEMANTIC_GENERIC };
134 const uint semantic_indexes[] = { 0, 0 };
135 ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
136 semantic_indexes);
137 }
138
139 /* fragment shader */
140 ctx->fs[TGSI_WRITEMASK_XYZW] =
141 util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
142 ctx->vbuf = NULL;
143
144 /* init vertex data that doesn't change */
145 for (i = 0; i < 4; i++) {
146 ctx->vertices[i][0][3] = 1.0f; /* w */
147 ctx->vertices[i][1][2] = 0.0f; /* r */
148 ctx->vertices[i][1][3] = 1.0f; /* q */
149 }
150
151 return ctx;
152 }
153
154
155 /**
156 * Destroy a blit context
157 */
158 void
159 util_destroy_blit(struct blit_state *ctx)
160 {
161 struct pipe_context *pipe = ctx->pipe;
162 unsigned i;
163
164 pipe->delete_vs_state(pipe, ctx->vs);
165
166 for (i = 0; i < Elements(ctx->fs); i++)
167 if (ctx->fs[i])
168 pipe->delete_fs_state(pipe, ctx->fs[i]);
169
170 pipe_resource_reference(&ctx->vbuf, NULL);
171
172 FREE(ctx);
173 }
174
175
176 /**
177 * Get offset of next free slot in vertex buffer for quad vertices.
178 */
179 static unsigned
180 get_next_slot( struct blit_state *ctx )
181 {
182 const unsigned max_slots = 4096 / sizeof ctx->vertices;
183
184 if (ctx->vbuf_slot >= max_slots)
185 util_blit_flush( ctx );
186
187 if (!ctx->vbuf) {
188 ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
189 PIPE_BIND_VERTEX_BUFFER,
190 max_slots * sizeof ctx->vertices);
191 }
192
193 return ctx->vbuf_slot++ * sizeof ctx->vertices;
194 }
195
196
197
198
199
200 /**
201 * Setup vertex data for the textured quad we'll draw.
202 * Note: y=0=top
203 */
204 static unsigned
205 setup_vertex_data_tex(struct blit_state *ctx,
206 float x0, float y0, float x1, float y1,
207 float s0, float t0, float s1, float t1,
208 float z)
209 {
210 unsigned offset;
211
212 ctx->vertices[0][0][0] = x0;
213 ctx->vertices[0][0][1] = y0;
214 ctx->vertices[0][0][2] = z;
215 ctx->vertices[0][1][0] = s0; /*s*/
216 ctx->vertices[0][1][1] = t0; /*t*/
217
218 ctx->vertices[1][0][0] = x1;
219 ctx->vertices[1][0][1] = y0;
220 ctx->vertices[1][0][2] = z;
221 ctx->vertices[1][1][0] = s1; /*s*/
222 ctx->vertices[1][1][1] = t0; /*t*/
223
224 ctx->vertices[2][0][0] = x1;
225 ctx->vertices[2][0][1] = y1;
226 ctx->vertices[2][0][2] = z;
227 ctx->vertices[2][1][0] = s1;
228 ctx->vertices[2][1][1] = t1;
229
230 ctx->vertices[3][0][0] = x0;
231 ctx->vertices[3][0][1] = y1;
232 ctx->vertices[3][0][2] = z;
233 ctx->vertices[3][1][0] = s0;
234 ctx->vertices[3][1][1] = t1;
235
236 offset = get_next_slot( ctx );
237
238 pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf,
239 offset, sizeof(ctx->vertices), ctx->vertices);
240
241 return offset;
242 }
243
244
245 /**
246 * \return TRUE if two regions overlap, FALSE otherwise
247 */
248 static boolean
249 regions_overlap(int srcX0, int srcY0,
250 int srcX1, int srcY1,
251 int dstX0, int dstY0,
252 int dstX1, int dstY1)
253 {
254 if (MAX2(srcX0, srcX1) < MIN2(dstX0, dstX1))
255 return FALSE; /* src completely left of dst */
256
257 if (MAX2(dstX0, dstX1) < MIN2(srcX0, srcX1))
258 return FALSE; /* dst completely left of src */
259
260 if (MAX2(srcY0, srcY1) < MIN2(dstY0, dstY1))
261 return FALSE; /* src completely above dst */
262
263 if (MAX2(dstY0, dstY1) < MIN2(srcY0, srcY1))
264 return FALSE; /* dst completely above src */
265
266 return TRUE; /* some overlap */
267 }
268
269
270 /**
271 * Copy pixel block from src surface to dst surface.
272 * Overlapping regions are acceptable.
273 * Flipping and stretching are supported.
274 * \param filter one of PIPE_TEX_MIPFILTER_NEAREST/LINEAR
275 * \param writemask controls which channels in the dest surface are sourced
276 * from the src surface. Disabled channels are sourced
277 * from (0,0,0,1).
278 * XXX need some control over blitting Z and/or stencil.
279 */
280 void
281 util_blit_pixels_writemask(struct blit_state *ctx,
282 struct pipe_surface *src,
283 struct pipe_sampler_view *src_sampler_view,
284 int srcX0, int srcY0,
285 int srcX1, int srcY1,
286 struct pipe_surface *dst,
287 int dstX0, int dstY0,
288 int dstX1, int dstY1,
289 float z, uint filter,
290 uint writemask)
291 {
292 struct pipe_context *pipe = ctx->pipe;
293 struct pipe_screen *screen = pipe->screen;
294 struct pipe_sampler_view *sampler_view = NULL;
295 struct pipe_framebuffer_state fb;
296 const int srcW = abs(srcX1 - srcX0);
297 const int srcH = abs(srcY1 - srcY0);
298 unsigned offset;
299 boolean overlap;
300 float s0, t0, s1, t1;
301
302 assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
303 filter == PIPE_TEX_MIPFILTER_LINEAR);
304
305 assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D,
306 PIPE_BIND_SAMPLER_VIEW, 0));
307 assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
308 PIPE_BIND_RENDER_TARGET, 0));
309
310 /* do the regions overlap? */
311 overlap = util_same_surface(src, dst) &&
312 regions_overlap(srcX0, srcY0, srcX1, srcY1,
313 dstX0, dstY0, dstX1, dstY1);
314
315 /*
316 * Check for simple case: no format conversion, no flipping, no stretching,
317 * no overlapping.
318 * Filter mode should not matter since there's no stretching.
319 */
320 if (pipe->surface_copy &&
321 dst->format == src->format &&
322 srcX0 < srcX1 &&
323 dstX0 < dstX1 &&
324 srcY0 < srcY1 &&
325 dstY0 < dstY1 &&
326 (dstX1 - dstX0) == (srcX1 - srcX0) &&
327 (dstY1 - dstY0) == (srcY1 - srcY0) &&
328 !overlap) {
329 pipe->surface_copy(pipe,
330 dst, dstX0, dstY0, /* dest */
331 src, srcX0, srcY0, /* src */
332 srcW, srcH); /* size */
333 return;
334 }
335
336 assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
337 PIPE_BIND_RENDER_TARGET, 0));
338
339 /* Create a temporary texture when src and dest alias or when src
340 * is anything other than a single-level 2d texture.
341 *
342 * This can still be improved upon.
343 */
344 if (util_same_surface(src, dst) ||
345 src->texture->target != PIPE_TEXTURE_2D ||
346 src->texture->last_level != 0)
347 {
348 struct pipe_resource texTemp;
349 struct pipe_resource *tex;
350 struct pipe_sampler_view sv_templ;
351 struct pipe_surface *texSurf;
352 const int srcLeft = MIN2(srcX0, srcX1);
353 const int srcTop = MIN2(srcY0, srcY1);
354
355 if (srcLeft != srcX0) {
356 /* left-right flip */
357 int tmp = dstX0;
358 dstX0 = dstX1;
359 dstX1 = tmp;
360 }
361
362 if (srcTop != srcY0) {
363 /* up-down flip */
364 int tmp = dstY0;
365 dstY0 = dstY1;
366 dstY1 = tmp;
367 }
368
369 /* create temp texture */
370 memset(&texTemp, 0, sizeof(texTemp));
371 texTemp.target = PIPE_TEXTURE_2D;
372 texTemp.format = src->format;
373 texTemp.last_level = 0;
374 texTemp.width0 = srcW;
375 texTemp.height0 = srcH;
376 texTemp.depth0 = 1;
377
378 tex = screen->resource_create(screen, &texTemp);
379 if (!tex)
380 return;
381
382 u_sampler_view_default_template(&sv_templ, tex, tex->format);
383
384 sampler_view = ctx->pipe->create_sampler_view(ctx->pipe, tex, &sv_templ);
385 if (!sampler_view) {
386 pipe_resource_reference(&tex, NULL);
387 return;
388 }
389
390 texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0,
391 PIPE_BIND_BLIT_DESTINATION);
392
393 /* load temp texture */
394 if (pipe->surface_copy) {
395 pipe->surface_copy(pipe,
396 texSurf, 0, 0, /* dest */
397 src, srcLeft, srcTop, /* src */
398 srcW, srcH); /* size */
399 } else {
400 util_surface_copy(pipe, FALSE,
401 texSurf, 0, 0, /* dest */
402 src, srcLeft, srcTop, /* src */
403 srcW, srcH); /* size */
404 }
405
406 /* free the surface, update the texture if necessary.
407 */
408 pipe_surface_reference(&texSurf, NULL);
409 s0 = 0.0f;
410 s1 = 1.0f;
411 t0 = 0.0f;
412 t1 = 1.0f;
413
414 pipe_resource_reference(&tex, NULL);
415 }
416 else {
417 pipe_sampler_view_reference(&sampler_view, src_sampler_view);
418 s0 = srcX0 / (float)src->texture->width0;
419 s1 = srcX1 / (float)src->texture->width0;
420 t0 = srcY0 / (float)src->texture->height0;
421 t1 = srcY1 / (float)src->texture->height0;
422 }
423
424
425
426 /* save state (restored below) */
427 cso_save_blend(ctx->cso);
428 cso_save_depth_stencil_alpha(ctx->cso);
429 cso_save_rasterizer(ctx->cso);
430 cso_save_samplers(ctx->cso);
431 cso_save_fragment_sampler_views(ctx->cso);
432 cso_save_viewport(ctx->cso);
433 cso_save_framebuffer(ctx->cso);
434 cso_save_fragment_shader(ctx->cso);
435 cso_save_vertex_shader(ctx->cso);
436 cso_save_clip(ctx->cso);
437 cso_save_vertex_elements(ctx->cso);
438
439 /* set misc state we care about */
440 cso_set_blend(ctx->cso, &ctx->blend);
441 cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
442 cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
443 cso_set_clip(ctx->cso, &ctx->clip);
444 cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
445
446 /* sampler */
447 ctx->sampler.min_img_filter = filter;
448 ctx->sampler.mag_img_filter = filter;
449 cso_single_sampler(ctx->cso, 0, &ctx->sampler);
450 cso_single_sampler_done(ctx->cso);
451
452 /* viewport */
453 ctx->viewport.scale[0] = 0.5f * dst->width;
454 ctx->viewport.scale[1] = 0.5f * dst->height;
455 ctx->viewport.scale[2] = 0.5f;
456 ctx->viewport.scale[3] = 1.0f;
457 ctx->viewport.translate[0] = 0.5f * dst->width;
458 ctx->viewport.translate[1] = 0.5f * dst->height;
459 ctx->viewport.translate[2] = 0.5f;
460 ctx->viewport.translate[3] = 0.0f;
461 cso_set_viewport(ctx->cso, &ctx->viewport);
462
463 /* texture */
464 cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view);
465
466 if (ctx->fs[writemask] == NULL)
467 ctx->fs[writemask] =
468 util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D,
469 writemask);
470
471 /* shaders */
472 cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]);
473 cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
474
475 /* drawing dest */
476 memset(&fb, 0, sizeof(fb));
477 fb.width = dst->width;
478 fb.height = dst->height;
479 fb.nr_cbufs = 1;
480 fb.cbufs[0] = dst;
481 cso_set_framebuffer(ctx->cso, &fb);
482
483 /* draw quad */
484 offset = setup_vertex_data_tex(ctx,
485 (float) dstX0 / dst->width * 2.0f - 1.0f,
486 (float) dstY0 / dst->height * 2.0f - 1.0f,
487 (float) dstX1 / dst->width * 2.0f - 1.0f,
488 (float) dstY1 / dst->height * 2.0f - 1.0f,
489 s0, t0,
490 s1, t1,
491 z);
492
493 util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, offset,
494 PIPE_PRIM_TRIANGLE_FAN,
495 4, /* verts */
496 2); /* attribs/vert */
497
498 /* restore state we changed */
499 cso_restore_blend(ctx->cso);
500 cso_restore_depth_stencil_alpha(ctx->cso);
501 cso_restore_rasterizer(ctx->cso);
502 cso_restore_samplers(ctx->cso);
503 cso_restore_fragment_sampler_views(ctx->cso);
504 cso_restore_viewport(ctx->cso);
505 cso_restore_framebuffer(ctx->cso);
506 cso_restore_fragment_shader(ctx->cso);
507 cso_restore_vertex_shader(ctx->cso);
508 cso_restore_clip(ctx->cso);
509 cso_restore_vertex_elements(ctx->cso);
510
511 pipe_sampler_view_reference(&sampler_view, NULL);
512 }
513
514
515 void
516 util_blit_pixels(struct blit_state *ctx,
517 struct pipe_surface *src,
518 struct pipe_sampler_view *src_sampler_view,
519 int srcX0, int srcY0,
520 int srcX1, int srcY1,
521 struct pipe_surface *dst,
522 int dstX0, int dstY0,
523 int dstX1, int dstY1,
524 float z, uint filter )
525 {
526 util_blit_pixels_writemask( ctx, src, src_sampler_view,
527 srcX0, srcY0,
528 srcX1, srcY1,
529 dst,
530 dstX0, dstY0,
531 dstX1, dstY1,
532 z, filter,
533 TGSI_WRITEMASK_XYZW );
534 }
535
536
537 /* Release vertex buffer at end of frame to avoid synchronous
538 * rendering.
539 */
540 void util_blit_flush( struct blit_state *ctx )
541 {
542 pipe_resource_reference(&ctx->vbuf, NULL);
543 ctx->vbuf_slot = 0;
544 }
545
546
547
548 /**
549 * Copy pixel block from src texture to dst surface.
550 * Overlapping regions are acceptable.
551 *
552 * XXX Should support selection of level.
553 * XXX need some control over blitting Z and/or stencil.
554 */
555 void
556 util_blit_pixels_tex(struct blit_state *ctx,
557 struct pipe_sampler_view *src_sampler_view,
558 int srcX0, int srcY0,
559 int srcX1, int srcY1,
560 struct pipe_surface *dst,
561 int dstX0, int dstY0,
562 int dstX1, int dstY1,
563 float z, uint filter)
564 {
565 struct pipe_framebuffer_state fb;
566 float s0, t0, s1, t1;
567 unsigned offset;
568 struct pipe_resource *tex = src_sampler_view->texture;
569
570 assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
571 filter == PIPE_TEX_MIPFILTER_LINEAR);
572
573 assert(tex);
574 assert(tex->width0 != 0);
575 assert(tex->height0 != 0);
576
577 s0 = srcX0 / (float)tex->width0;
578 s1 = srcX1 / (float)tex->width0;
579 t0 = srcY0 / (float)tex->height0;
580 t1 = srcY1 / (float)tex->height0;
581
582 assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format,
583 PIPE_TEXTURE_2D,
584 PIPE_BIND_RENDER_TARGET,
585 0));
586
587 /* save state (restored below) */
588 cso_save_blend(ctx->cso);
589 cso_save_depth_stencil_alpha(ctx->cso);
590 cso_save_rasterizer(ctx->cso);
591 cso_save_samplers(ctx->cso);
592 cso_save_fragment_sampler_views(ctx->cso);
593 cso_save_framebuffer(ctx->cso);
594 cso_save_fragment_shader(ctx->cso);
595 cso_save_vertex_shader(ctx->cso);
596 cso_save_clip(ctx->cso);
597 cso_save_vertex_elements(ctx->cso);
598
599 /* set misc state we care about */
600 cso_set_blend(ctx->cso, &ctx->blend);
601 cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
602 cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
603 cso_set_clip(ctx->cso, &ctx->clip);
604 cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
605
606 /* sampler */
607 ctx->sampler.min_img_filter = filter;
608 ctx->sampler.mag_img_filter = filter;
609 cso_single_sampler(ctx->cso, 0, &ctx->sampler);
610 cso_single_sampler_done(ctx->cso);
611
612 /* viewport */
613 ctx->viewport.scale[0] = 0.5f * dst->width;
614 ctx->viewport.scale[1] = 0.5f * dst->height;
615 ctx->viewport.scale[2] = 0.5f;
616 ctx->viewport.scale[3] = 1.0f;
617 ctx->viewport.translate[0] = 0.5f * dst->width;
618 ctx->viewport.translate[1] = 0.5f * dst->height;
619 ctx->viewport.translate[2] = 0.5f;
620 ctx->viewport.translate[3] = 0.0f;
621 cso_set_viewport(ctx->cso, &ctx->viewport);
622
623 /* texture */
624 cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view);
625
626 /* shaders */
627 cso_set_fragment_shader_handle(ctx->cso, ctx->fs[TGSI_WRITEMASK_XYZW]);
628 cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
629
630 /* drawing dest */
631 memset(&fb, 0, sizeof(fb));
632 fb.width = dst->width;
633 fb.height = dst->height;
634 fb.nr_cbufs = 1;
635 fb.cbufs[0] = dst;
636 cso_set_framebuffer(ctx->cso, &fb);
637
638 /* draw quad */
639 offset = setup_vertex_data_tex(ctx,
640 (float) dstX0 / dst->width * 2.0f - 1.0f,
641 (float) dstY0 / dst->height * 2.0f - 1.0f,
642 (float) dstX1 / dst->width * 2.0f - 1.0f,
643 (float) dstY1 / dst->height * 2.0f - 1.0f,
644 s0, t0, s1, t1,
645 z);
646
647 util_draw_vertex_buffer(ctx->pipe,
648 ctx->vbuf, offset,
649 PIPE_PRIM_TRIANGLE_FAN,
650 4, /* verts */
651 2); /* attribs/vert */
652
653 /* restore state we changed */
654 cso_restore_blend(ctx->cso);
655 cso_restore_depth_stencil_alpha(ctx->cso);
656 cso_restore_rasterizer(ctx->cso);
657 cso_restore_samplers(ctx->cso);
658 cso_restore_fragment_sampler_views(ctx->cso);
659 cso_restore_framebuffer(ctx->cso);
660 cso_restore_fragment_shader(ctx->cso);
661 cso_restore_vertex_shader(ctx->cso);
662 cso_restore_clip(ctx->cso);
663 cso_restore_vertex_elements(ctx->cso);
664 }