1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/**************************************************************************
Copyright 2010 Intel Corporation
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xf86.h"
#include "intel.h"
#include "i830_reg.h"
static dri_bo *
intel_shadow_create_bo(intel_screen_private *intel,
int16_t x1, int16_t y1,
int16_t x2, int16_t y2,
int *pitch)
{
int w = x2 - x1, h = y2 - y1;
int size = h * w * intel->cpp;
dri_bo *bo;
bo = drm_intel_bo_alloc(intel->bufmgr, "shadow", size, 0);
if (bo && drm_intel_gem_bo_map_gtt(bo) == 0) {
char *dst = bo->virtual;
char *src = intel->shadow_buffer;
int src_pitch = intel->shadow_stride;
int row_length = w * intel->cpp;
int num_rows = h;
src += y1 * src_pitch + x1 * intel->cpp;
do {
memcpy (dst, src, row_length);
src += src_pitch;
dst += row_length;
} while (--num_rows);
drm_intel_gem_bo_unmap_gtt(bo);
}
*pitch = w * intel->cpp;
return bo;
}
static void intel_shadow_memcpy(intel_screen_private *intel)
{
char *src_data, *dst_data;
unsigned int src_pitch, dst_pitch;
RegionPtr region;
BoxPtr box;
int n;
if (drm_intel_gem_bo_map_gtt(intel->front_buffer))
return;
src_data = intel->shadow_buffer;
dst_data = intel->front_buffer->virtual;
src_pitch = intel->shadow_stride;
dst_pitch = intel->front_pitch;
region = DamageRegion(intel->shadow_damage);
box = REGION_RECTS(region);
n = REGION_NUM_RECTS(region);
while (n--) {
char *src = src_data + box->y1*src_pitch + box->x1*intel->cpp;
char *dst = dst_data + box->y1*dst_pitch + box->x1*intel->cpp;
int len = (box->x2 - box->x1)*intel->cpp;
int row = box->y2 - box->y1;
while (row--) {
memcpy(dst, src, len);
src += src_pitch;
dst += dst_pitch;
}
box++;
}
}
void intel_shadow_blt(intel_screen_private *intel)
{
ScrnInfoPtr scrn = intel->scrn;
uint32_t blt, br13;
RegionPtr region;
BoxPtr box;
int n;
/* Can we trust the BLT? Otherwise do an uncached mmecy. */
if (!intel->can_blt || IS_GEN2(intel)) {
intel_shadow_memcpy(intel);
return;
}
blt = XY_SRC_COPY_BLT_CMD;
br13 = intel->front_pitch;
if (intel->front_tiling && INTEL_INFO(intel)->gen >= 40) {
br13 >>= 2;
blt |= XY_SRC_COPY_BLT_DST_TILED;
}
switch (intel->cpp) {
default:
case 4: blt |=
XY_SRC_COPY_BLT_WRITE_ALPHA | XY_SRC_COPY_BLT_WRITE_RGB;
br13 |= 1 << 25; /* RGB8888 */
case 2: br13 |= 1 << 24; /* RGB565 */
case 1: break;
}
br13 |= 0xcc << 16; /* copy */
region = DamageRegion(intel->shadow_damage);
box = REGION_RECTS(region);
n = REGION_NUM_RECTS(region);
while (n--) {
int pitch;
dri_bo *bo;
bo = intel_shadow_create_bo(intel,
box->x1, box->y1,
box->x2, box->y2,
&pitch);
if (bo == NULL)
return;
BEGIN_BATCH_BLT(8);
OUT_BATCH(blt);
OUT_BATCH(br13);
OUT_BATCH(box->y1 << 16 | box->x1);
OUT_BATCH(box->y2 << 16 | box->x2);
OUT_RELOC_FENCED(intel->front_buffer,
I915_GEM_DOMAIN_RENDER,
I915_GEM_DOMAIN_RENDER,
0);
OUT_BATCH(0);
OUT_BATCH(pitch);
OUT_RELOC(bo, I915_GEM_DOMAIN_RENDER, 0, 0);
ADVANCE_BATCH();
drm_intel_bo_unreference(bo);
box++;
}
}
void intel_shadow_create(struct intel_screen_private *intel)
{
ScrnInfoPtr scrn = intel->scrn;
ScreenPtr screen = scrn->pScreen;
PixmapPtr pixmap;
int stride;
void *buffer;
pixmap = screen->GetScreenPixmap(screen);
stride = intel->cpp*scrn->virtualX;
buffer = malloc(stride * scrn->virtualY);
if (buffer &&
screen->ModifyPixmapHeader(pixmap,
scrn->virtualX, scrn->virtualY,
-1, -1,
stride, buffer)) {
free(intel->shadow_buffer);
intel->shadow_buffer = buffer;
} else {
free(buffer);
stride = intel->shadow_stride;
}
if (!intel->shadow_damage) {
intel->shadow_damage =
DamageCreate(NULL, NULL,
DamageReportNone, TRUE,
screen, intel);
DamageRegister(&pixmap->drawable, intel->shadow_damage);
DamageSetReportAfterOp(intel->shadow_damage, TRUE);
}
scrn->displayWidth = stride / intel->cpp;
intel->shadow_stride = stride;
}
|