OSDN Git Service

i915g: Use PIPE_FLUSH_END_OF_FRAME to trigger throttling
[android-x86/external-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
35 void
36 i915_fill_blit(struct i915_context *i915,
37                unsigned cpp,
38                unsigned rgba_mask,
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(DBG_BLIT, "%s dst:buf(%p)/%d+%d %d,%d sz:%dx%d\n",
50             __FUNCTION__, dst_buffer, dst_pitch, dst_offset, x, y, w, h);
51
52    if(!i915_winsys_validate_buffers(i915->batch, &dst_buffer, 1)) {
53       FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
54       assert(i915_winsys_validate_buffers(i915->batch, &dst_buffer, 1));
55    }
56
57    switch (cpp) {
58    case 1:
59    case 2:
60    case 3:
61       BR13 = (((int) dst_pitch) & 0xffff) |
62          (0xF0 << 16) | (1 << 24);
63       CMD = XY_COLOR_BLT_CMD;
64       break;
65    case 4:
66       BR13 = (((int) dst_pitch) & 0xffff) |
67          (0xF0 << 16) | (1 << 24) | (1 << 25);
68       CMD = (XY_COLOR_BLT_CMD | rgba_mask);
69       break;
70    default:
71       return;
72    }
73
74    if (!BEGIN_BATCH(6)) {
75       FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
76       assert(BEGIN_BATCH(6));
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_FENCED(dst_buffer, I915_USAGE_2D_TARGET, dst_offset);
83    OUT_BATCH(color);
84
85    i915_set_flush_dirty(i915, I915_FLUSH_CACHE);
86 }
87
88 void
89 i915_copy_blit(struct i915_context *i915,
90                unsigned cpp,
91                unsigned short src_pitch,
92                struct i915_winsys_buffer *src_buffer,
93                unsigned src_offset,
94                unsigned short dst_pitch,
95                struct i915_winsys_buffer *dst_buffer,
96                unsigned dst_offset,
97                short src_x, short src_y,
98                short dst_x, short dst_y, 
99                short w, short h)
100 {
101    unsigned CMD, BR13;
102    int dst_y2 = dst_y + h;
103    int dst_x2 = dst_x + w;
104    struct i915_winsys_buffer *buffers[2] = {src_buffer, dst_buffer};
105
106
107    I915_DBG(DBG_BLIT,
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    if(!i915_winsys_validate_buffers(i915->batch, buffers, 2)) {
114       FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
115       assert(i915_winsys_validate_buffers(i915->batch, buffers, 2));
116    }
117
118    switch (cpp) {
119    case 1:
120    case 2:
121    case 3:
122       BR13 = (((int) dst_pitch) & 0xffff) |
123          (0xCC << 16) | (1 << 24);
124       CMD = XY_SRC_COPY_BLT_CMD;
125       break;
126    case 4:
127       BR13 = (((int) dst_pitch) & 0xffff) |
128              (0xCC << 16) | (1 << 24) | (1 << 25);
129       CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
130             XY_SRC_COPY_BLT_WRITE_RGB);
131       break;
132    default:
133       return;
134    }
135
136    if (dst_y2 < dst_y || dst_x2 < dst_x) {
137       return;
138    }
139
140    /* Hardware can handle negative pitches but loses the ability to do
141     * proper overlapping blits in that case.  We don't really have a
142     * need for either at this stage.
143     */
144    assert (dst_pitch > 0 && src_pitch > 0);
145
146    if (!BEGIN_BATCH(8)) {
147       FLUSH_BATCH(NULL, I915_FLUSH_ASYNC);
148       assert(BEGIN_BATCH(8));
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_FENCED(dst_buffer, I915_USAGE_2D_TARGET, dst_offset);
155    OUT_BATCH((src_y << 16) | src_x);
156    OUT_BATCH(((int) src_pitch & 0xffff));
157    OUT_RELOC_FENCED(src_buffer, I915_USAGE_2D_SOURCE, src_offset);
158
159    i915_set_flush_dirty(i915, I915_FLUSH_CACHE);
160 }