00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <errno.h>
00031
00032 #include "brw_batch.h"
00033 #include "brw_blit.h"
00034 #include "brw_context.h"
00035 #include "brw_reg.h"
00036
00037 #include "pipe/p_context.h"
00038 #include "pipe/p_winsys.h"
00039
00040 #define FILE_DEBUG_FLAG DEBUG_BLIT
00041
00042 void brw_fill_blit(struct brw_context *brw,
00043 unsigned cpp,
00044 short dst_pitch,
00045 struct pipe_buffer *dst_buffer,
00046 unsigned dst_offset,
00047 boolean dst_tiled,
00048 short x, short y,
00049 short w, short h,
00050 unsigned color)
00051 {
00052 unsigned BR13, CMD;
00053 BATCH_LOCALS;
00054
00055 dst_pitch *= cpp;
00056
00057 switch(cpp) {
00058 case 1:
00059 case 2:
00060 case 3:
00061 BR13 = (0xF0 << 16) | (1<<24);
00062 CMD = XY_COLOR_BLT_CMD;
00063 break;
00064 case 4:
00065 BR13 = (0xF0 << 16) | (1<<24) | (1<<25);
00066 CMD = XY_COLOR_BLT_CMD | XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
00067 break;
00068 default:
00069 return;
00070 }
00071
00072 if (dst_tiled) {
00073 CMD |= XY_DST_TILED;
00074 dst_pitch /= 4;
00075 }
00076
00077 BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS);
00078 OUT_BATCH( CMD );
00079 OUT_BATCH( dst_pitch | BR13 );
00080 OUT_BATCH( (y << 16) | x );
00081 OUT_BATCH( ((y+h) << 16) | (x+w) );
00082 OUT_RELOC( dst_buffer, BRW_BUFFER_ACCESS_WRITE, dst_offset );
00083 OUT_BATCH( color );
00084 ADVANCE_BATCH();
00085 }
00086
00087 static unsigned translate_raster_op(unsigned logicop)
00088 {
00089 switch(logicop) {
00090 case PIPE_LOGICOP_CLEAR: return 0x00;
00091 case PIPE_LOGICOP_AND: return 0x88;
00092 case PIPE_LOGICOP_AND_REVERSE: return 0x44;
00093 case PIPE_LOGICOP_COPY: return 0xCC;
00094 case PIPE_LOGICOP_AND_INVERTED: return 0x22;
00095 case PIPE_LOGICOP_NOOP: return 0xAA;
00096 case PIPE_LOGICOP_XOR: return 0x66;
00097 case PIPE_LOGICOP_OR: return 0xEE;
00098 case PIPE_LOGICOP_NOR: return 0x11;
00099 case PIPE_LOGICOP_EQUIV: return 0x99;
00100 case PIPE_LOGICOP_INVERT: return 0x55;
00101 case PIPE_LOGICOP_OR_REVERSE: return 0xDD;
00102 case PIPE_LOGICOP_COPY_INVERTED: return 0x33;
00103 case PIPE_LOGICOP_OR_INVERTED: return 0xBB;
00104 case PIPE_LOGICOP_NAND: return 0x77;
00105 case PIPE_LOGICOP_SET: return 0xFF;
00106 default: return 0;
00107 }
00108 }
00109
00110
00111
00112
00113 void brw_copy_blit(struct brw_context *brw,
00114 unsigned do_flip,
00115 unsigned cpp,
00116 short src_pitch,
00117 struct pipe_buffer *src_buffer,
00118 unsigned src_offset,
00119 boolean src_tiled,
00120 short dst_pitch,
00121 struct pipe_buffer *dst_buffer,
00122 unsigned dst_offset,
00123 boolean dst_tiled,
00124 short src_x, short src_y,
00125 short dst_x, short dst_y,
00126 short w, short h,
00127 unsigned logic_op)
00128 {
00129 unsigned CMD, BR13;
00130 int dst_y2 = dst_y + h;
00131 int dst_x2 = dst_x + w;
00132 BATCH_LOCALS;
00133
00134
00135 DBG("%s src:buf(%d)/%d %d,%d dst:buf(%d)/%d %d,%d sz:%dx%d op:%d\n",
00136 __FUNCTION__,
00137 src_buffer, src_pitch, src_x, src_y,
00138 dst_buffer, dst_pitch, dst_x, dst_y,
00139 w,h,logic_op);
00140
00141 assert( logic_op - PIPE_LOGICOP_CLEAR >= 0 );
00142 assert( logic_op - PIPE_LOGICOP_CLEAR < 0x10 );
00143
00144 src_pitch *= cpp;
00145 dst_pitch *= cpp;
00146
00147 switch(cpp) {
00148 case 1:
00149 case 2:
00150 case 3:
00151 BR13 = (translate_raster_op(logic_op) << 16) | (1<<24);
00152 CMD = XY_SRC_COPY_BLT_CMD;
00153 break;
00154 case 4:
00155 BR13 = (translate_raster_op(logic_op) << 16) | (1<<24) |
00156 (1<<25);
00157 CMD = XY_SRC_COPY_BLT_CMD | XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
00158 break;
00159 default:
00160 return;
00161 }
00162
00163 if (src_tiled) {
00164 CMD |= XY_SRC_TILED;
00165 src_pitch /= 4;
00166 }
00167
00168 if (dst_tiled) {
00169 CMD |= XY_DST_TILED;
00170 dst_pitch /= 4;
00171 }
00172
00173 if (dst_y2 < dst_y ||
00174 dst_x2 < dst_x) {
00175 return;
00176 }
00177
00178 dst_pitch &= 0xffff;
00179 src_pitch &= 0xffff;
00180
00181
00182
00183
00184
00185
00186
00187
00188 if (dst_pitch > 0 && src_pitch > 0) {
00189 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS);
00190 OUT_BATCH( CMD );
00191 OUT_BATCH( dst_pitch | BR13 );
00192 OUT_BATCH( (dst_y << 16) | dst_x );
00193 OUT_BATCH( (dst_y2 << 16) | dst_x2 );
00194 OUT_RELOC( dst_buffer, BRW_BUFFER_ACCESS_WRITE,
00195 dst_offset );
00196 OUT_BATCH( (src_y << 16) | src_x );
00197 OUT_BATCH( src_pitch );
00198 OUT_RELOC( src_buffer, BRW_BUFFER_ACCESS_READ,
00199 src_offset );
00200 ADVANCE_BATCH();
00201 }
00202 else {
00203 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS);
00204 OUT_BATCH( CMD );
00205 OUT_BATCH( (dst_pitch & 0xffff) | BR13 );
00206 OUT_BATCH( (0 << 16) | dst_x );
00207 OUT_BATCH( (h << 16) | dst_x2 );
00208 OUT_RELOC( dst_buffer, BRW_BUFFER_ACCESS_WRITE,
00209 dst_offset + dst_y * dst_pitch );
00210 OUT_BATCH( (src_pitch & 0xffff) );
00211 OUT_RELOC( src_buffer, BRW_BUFFER_ACCESS_READ,
00212 src_offset + src_y * src_pitch );
00213 ADVANCE_BATCH();
00214 }
00215 }
00216
00217
00218