1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "pipe/p_util.h"
29 #include "sp_context.h"
30 #include "sp_headers.h"
31 #include "sp_surface.h"
33 #include "sp_tile_cache.h"
37 * Write quad to framebuffer, taking mask into account.
39 * Note that surfaces support only full quad reads and writes.
42 output_quad(struct quad_stage
*qs
, struct quad_header
*quad
)
44 struct softpipe_context
*softpipe
= qs
->softpipe
;
45 struct softpipe_cached_tile
*tile
46 = sp_get_cached_tile(softpipe
,
47 softpipe
->cbuf_cache
[softpipe
->current_cbuf
],
50 const int itx
= quad
->x0
% TILE_SIZE
;
51 const int ity
= quad
->y0
% TILE_SIZE
;
52 float (*quadColor
)[4] = quad
->outputs
.color
;
55 /* get/swizzle dest colors */
56 for (j
= 0; j
< QUAD_SIZE
; j
++) {
57 if (quad
->mask
& (1 << j
)) {
58 int x
= itx
+ (j
& 1);
59 int y
= ity
+ (j
>> 1);
60 for (i
= 0; i
< 4; i
++) { /* loop over color chans */
61 tile
->data
.color
[y
][x
][i
] = quadColor
[i
][j
];
68 static void output_begin(struct quad_stage
*qs
)
70 assert(qs
->next
== NULL
);
74 static void output_destroy(struct quad_stage
*qs
)
80 struct quad_stage
*sp_quad_output_stage( struct softpipe_context
*softpipe
)
82 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
84 stage
->softpipe
= softpipe
;
85 stage
->begin
= output_begin
;
86 stage
->run
= output_quad
;
87 stage
->destroy
= output_destroy
;