Merge branch 'nouveau-gallium-0.1' into darktama-gallium-0.1
[mesa.git] / src / mesa / pipe / i915simple / i915_blit.c
1 /**************************************************************************
2 *
3 * Copyright 2003 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 #include "i915_context.h"
30 #include "i915_winsys.h"
31 #include "i915_blit.h"
32 #include "i915_reg.h"
33 #include "i915_batch.h"
34
35 #define FILE_DEBUG_FLAG DEBUG_BLIT
36
37 void
38 i915_fill_blit(struct i915_context *i915,
39 unsigned cpp,
40 short dst_pitch,
41 struct pipe_buffer_handle *dst_buffer,
42 unsigned dst_offset,
43 short x, short y,
44 short w, short h,
45 unsigned color)
46 {
47 unsigned BR13, CMD;
48 BATCH_LOCALS;
49
50 dst_pitch *= (short) cpp;
51
52 switch (cpp) {
53 case 1:
54 case 2:
55 case 3:
56 BR13 = dst_pitch | (0xF0 << 16) | (1 << 24);
57 CMD = XY_COLOR_BLT_CMD;
58 break;
59 case 4:
60 BR13 = dst_pitch | (0xF0 << 16) | (1 << 24) | (1 << 25);
61 CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA |
62 XY_COLOR_BLT_WRITE_RGB);
63 break;
64 default:
65 return;
66 }
67
68 // DBG("%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
69 // __FUNCTION__, dst_buffer, dst_pitch, dst_offset, x, y, w, h);
70
71
72 if (!BEGIN_BATCH(6, 1)) {
73 FLUSH_BATCH();
74 assert(BEGIN_BATCH(6, 1));
75 }
76 OUT_BATCH(CMD);
77 OUT_BATCH(BR13);
78 OUT_BATCH((y << 16) | x);
79 OUT_BATCH(((y + h) << 16) | (x + w));
80 OUT_RELOC( dst_buffer, I915_BUFFER_ACCESS_WRITE, dst_offset);
81 OUT_BATCH(color);
82 ADVANCE_BATCH();
83 }
84
85
86 void
87 i915_copy_blit( struct i915_context *i915,
88 unsigned cpp,
89 short src_pitch,
90 struct pipe_buffer_handle *src_buffer,
91 unsigned src_offset,
92 short dst_pitch,
93 struct pipe_buffer_handle *dst_buffer,
94 unsigned dst_offset,
95 short src_x, short src_y,
96 short dst_x, short dst_y,
97 short w, short h )
98 {
99 unsigned CMD, BR13;
100 int dst_y2 = dst_y + h;
101 int dst_x2 = dst_x + w;
102 BATCH_LOCALS;
103
104
105 I915_DBG(i915,
106 "%s src:buf(%p)/%d+%d %d,%d dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
107 __FUNCTION__,
108 src_buffer, src_pitch, src_offset, src_x, src_y,
109 dst_buffer, dst_pitch, dst_offset, dst_x, dst_y, w, h);
110
111 src_pitch *= (short) cpp;
112 dst_pitch *= (short) cpp;
113
114 switch (cpp) {
115 case 1:
116 case 2:
117 case 3:
118 BR13 = (((int) dst_pitch) & 0xffff) |
119 (0xCC << 16) | (1 << 24);
120 CMD = XY_SRC_COPY_BLT_CMD;
121 break;
122 case 4:
123 BR13 =
124 (((int) dst_pitch) & 0xffff) |
125 (0xCC << 16) | (1 << 24) | (1 << 25);
126 CMD =
127 (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
128 XY_SRC_COPY_BLT_WRITE_RGB);
129 break;
130 default:
131 return;
132 }
133
134 if (dst_y2 < dst_y ||
135 dst_x2 < dst_x) {
136 return;
137 }
138
139 /* Hardware can handle negative pitches but loses the ability to do
140 * proper overlapping blits in that case. We don't really have a
141 * need for either at this stage.
142 */
143 assert (dst_pitch > 0 && src_pitch > 0);
144
145
146 if (!BEGIN_BATCH(8, 2)) {
147 FLUSH_BATCH();
148 assert(BEGIN_BATCH(8, 2));
149 }
150 OUT_BATCH(CMD);
151 OUT_BATCH(BR13);
152 OUT_BATCH((dst_y << 16) | dst_x);
153 OUT_BATCH((dst_y2 << 16) | dst_x2);
154 OUT_RELOC(dst_buffer, I915_BUFFER_ACCESS_WRITE, dst_offset);
155 OUT_BATCH((src_y << 16) | src_x);
156 OUT_BATCH(((int) src_pitch & 0xffff));
157 OUT_RELOC(src_buffer, I915_BUFFER_ACCESS_READ, src_offset);
158 ADVANCE_BATCH();
159 }
160
161