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