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