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