1 /**************************************************************************
3 * Copyright 2003 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 **************************************************************************/
32 #include "brw_batch.h"
34 #include "brw_context.h"
37 #include "pipe/p_context.h"
38 #include "pipe/p_winsys.h"
40 #define FILE_DEBUG_FLAG DEBUG_BLIT
42 void brw_fill_blit(struct brw_context
*brw
,
45 struct pipe_buffer
*dst_buffer
,
61 BR13
= (0xF0 << 16) | (1<<24);
62 CMD
= XY_COLOR_BLT_CMD
;
65 BR13
= (0xF0 << 16) | (1<<24) | (1<<25);
66 CMD
= XY_COLOR_BLT_CMD
| XY_BLT_WRITE_ALPHA
| XY_BLT_WRITE_RGB
;
77 BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS
);
79 OUT_BATCH( dst_pitch
| BR13
);
80 OUT_BATCH( (y
<< 16) | x
);
81 OUT_BATCH( ((y
+h
) << 16) | (x
+w
) );
82 OUT_RELOC( dst_buffer
, BRW_BUFFER_ACCESS_WRITE
, dst_offset
);
87 static unsigned translate_raster_op(unsigned logicop
)
90 case PIPE_LOGICOP_CLEAR
: return 0x00;
91 case PIPE_LOGICOP_AND
: return 0x88;
92 case PIPE_LOGICOP_AND_REVERSE
: return 0x44;
93 case PIPE_LOGICOP_COPY
: return 0xCC;
94 case PIPE_LOGICOP_AND_INVERTED
: return 0x22;
95 case PIPE_LOGICOP_NOOP
: return 0xAA;
96 case PIPE_LOGICOP_XOR
: return 0x66;
97 case PIPE_LOGICOP_OR
: return 0xEE;
98 case PIPE_LOGICOP_NOR
: return 0x11;
99 case PIPE_LOGICOP_EQUIV
: return 0x99;
100 case PIPE_LOGICOP_INVERT
: return 0x55;
101 case PIPE_LOGICOP_OR_REVERSE
: return 0xDD;
102 case PIPE_LOGICOP_COPY_INVERTED
: return 0x33;
103 case PIPE_LOGICOP_OR_INVERTED
: return 0xBB;
104 case PIPE_LOGICOP_NAND
: return 0x77;
105 case PIPE_LOGICOP_SET
: return 0xFF;
113 void brw_copy_blit(struct brw_context
*brw
,
117 struct pipe_buffer
*src_buffer
,
121 struct pipe_buffer
*dst_buffer
,
124 short src_x
, short src_y
,
125 short dst_x
, short dst_y
,
130 int dst_y2
= dst_y
+ h
;
131 int dst_x2
= dst_x
+ w
;
135 DBG("%s src:buf(%d)/%d %d,%d dst:buf(%d)/%d %d,%d sz:%dx%d op:%d\n",
137 src_buffer
, src_pitch
, src_x
, src_y
,
138 dst_buffer
, dst_pitch
, dst_x
, dst_y
,
141 assert( logic_op
- PIPE_LOGICOP_CLEAR
>= 0 );
142 assert( logic_op
- PIPE_LOGICOP_CLEAR
< 0x10 );
151 BR13
= (translate_raster_op(logic_op
) << 16) | (1<<24);
152 CMD
= XY_SRC_COPY_BLT_CMD
;
155 BR13
= (translate_raster_op(logic_op
) << 16) | (1<<24) |
157 CMD
= XY_SRC_COPY_BLT_CMD
| XY_BLT_WRITE_ALPHA
| XY_BLT_WRITE_RGB
;
173 if (dst_y2
< dst_y
||
181 /* Initial y values don't seem to work with negative pitches. If
182 * we adjust the offsets manually (below), it seems to work fine.
184 * On the other hand, if we always adjust, the hardware doesn't
185 * know which blit directions to use, so overlapping copypixels get
188 if (dst_pitch
> 0 && src_pitch
> 0) {
189 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS
);
191 OUT_BATCH( dst_pitch
| BR13
);
192 OUT_BATCH( (dst_y
<< 16) | dst_x
);
193 OUT_BATCH( (dst_y2
<< 16) | dst_x2
);
194 OUT_RELOC( dst_buffer
, BRW_BUFFER_ACCESS_WRITE
,
196 OUT_BATCH( (src_y
<< 16) | src_x
);
197 OUT_BATCH( src_pitch
);
198 OUT_RELOC( src_buffer
, BRW_BUFFER_ACCESS_READ
,
203 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS
);
205 OUT_BATCH( (dst_pitch
& 0xffff) | BR13
);
206 OUT_BATCH( (0 << 16) | dst_x
);
207 OUT_BATCH( (h
<< 16) | dst_x2
);
208 OUT_RELOC( dst_buffer
, BRW_BUFFER_ACCESS_WRITE
,
209 dst_offset
+ dst_y
* dst_pitch
);
210 OUT_BATCH( (src_pitch
& 0xffff) );
211 OUT_RELOC( src_buffer
, BRW_BUFFER_ACCESS_READ
,
212 src_offset
+ src_y
* src_pitch
);