40083138a435f23b53c245aa183a30ddecb51c8c
[mesa.git] / src / gallium / drivers / softpipe / sp_quad_output.c
1 /**************************************************************************
2 *
3 * Copyright 2007 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 #include "pipe/p_util.h"
29 #include "sp_context.h"
30 #include "sp_headers.h"
31 #include "sp_surface.h"
32 #include "sp_quad.h"
33 #include "sp_tile_cache.h"
34
35
36 /**
37 * Last step of quad processing: write quad colors to the framebuffer,
38 * taking mask into account.
39 */
40 static void
41 output_quad(struct quad_stage *qs, struct quad_header *quad)
42 {
43 /* in-tile pos: */
44 const int itx = quad->x0 % TILE_SIZE;
45 const int ity = quad->y0 % TILE_SIZE;
46
47 struct softpipe_context *softpipe = qs->softpipe;
48 uint cbuf;
49
50 /* loop over colorbuffer outputs */
51 for (cbuf = 0; cbuf < softpipe->framebuffer.num_cbufs; cbuf++) {
52 struct softpipe_cached_tile *tile
53 = sp_get_cached_tile(softpipe,
54 softpipe->cbuf_cache[cbuf],
55 quad->x0, quad->y0);
56 float (*quadColor)[4] = quad->outputs.color[cbuf];
57 int i, j;
58
59 /* get/swizzle dest colors */
60 for (j = 0; j < QUAD_SIZE; j++) {
61 if (quad->mask & (1 << j)) {
62 int x = itx + (j & 1);
63 int y = ity + (j >> 1);
64 for (i = 0; i < 4; i++) { /* loop over color chans */
65 tile->data.color[y][x][i] = quadColor[i][j];
66 }
67 }
68 }
69 }
70 }
71
72
73 static void output_begin(struct quad_stage *qs)
74 {
75 assert(qs->next == NULL);
76 }
77
78
79 static void output_destroy(struct quad_stage *qs)
80 {
81 FREE( qs );
82 }
83
84
85 struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe )
86 {
87 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
88
89 stage->softpipe = softpipe;
90 stage->begin = output_begin;
91 stage->run = output_quad;
92 stage->destroy = output_destroy;
93
94 return stage;
95 }