Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / state_trackers / python / st_sample.c
1 /**************************************************************************
2 *
3 * Copyright 2008 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 "pipe/p_compiler.h"
30 #include "pipe/p_format.h"
31 #include "pipe/p_state.h"
32 #include "pipe/p_inlines.h"
33 #include "util/u_tile.h"
34 #include "util/u_math.h"
35 #include "util/u_memory.h"
36
37 #include "st_device.h"
38 #include "st_sample.h"
39
40
41 /**
42 * Use our own pseudo random generator to ensure consistent runs among
43 * multiple runs and platforms.
44 *
45 * @sa http://en.wikipedia.org/wiki/Linear_congruential_generator
46 */
47 static uint32_t st_random(void) {
48 static uint64_t seed = UINT64_C(0xbb9a063afb0a739d);
49
50 seed = UINT64_C(134775813) * seed + UINT64_C(1);
51
52 return (uint16_t)(seed >> 32);
53 }
54
55
56 /**
57 * We don't want to include the patent-encumbered DXT code here, so instead
58 * we store several uncompressed/compressed data pairs for hardware testing
59 * purposes.
60 */
61 struct dxt_data
62 {
63 uint8_t rgba[16*4];
64 uint8_t raw[16];
65 };
66
67
68 static const struct dxt_data
69 dxt1_rgb_data[] = {
70 {
71 {
72 0x99, 0xb0, 0x8e, 0xff,
73 0x5d, 0x62, 0x89, 0xff,
74 0x99, 0xb0, 0x8e, 0xff,
75 0x99, 0xb0, 0x8e, 0xff,
76 0xd6, 0xff, 0x94, 0xff,
77 0x5d, 0x62, 0x89, 0xff,
78 0x99, 0xb0, 0x8e, 0xff,
79 0xd6, 0xff, 0x94, 0xff,
80 0x5d, 0x62, 0x89, 0xff,
81 0x5d, 0x62, 0x89, 0xff,
82 0x99, 0xb0, 0x8e, 0xff,
83 0x21, 0x14, 0x84, 0xff,
84 0x5d, 0x62, 0x89, 0xff,
85 0x21, 0x14, 0x84, 0xff,
86 0x21, 0x14, 0x84, 0xff,
87 0x99, 0xb0, 0x8e, 0xff
88 },
89 {0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97}
90 },
91 {
92 {
93 0xb5, 0xcf, 0x9c, 0xff,
94 0x83, 0x8c, 0x8b, 0xff,
95 0x21, 0x08, 0x6b, 0xff,
96 0x83, 0x8c, 0x8b, 0xff,
97 0x52, 0x4a, 0x7b, 0xff,
98 0x83, 0x8c, 0x8b, 0xff,
99 0x83, 0x8c, 0x8b, 0xff,
100 0xb5, 0xcf, 0x9c, 0xff,
101 0x21, 0x08, 0x6b, 0xff,
102 0xb5, 0xcf, 0x9c, 0xff,
103 0x83, 0x8c, 0x8b, 0xff,
104 0x52, 0x4a, 0x7b, 0xff,
105 0xb5, 0xcf, 0x9c, 0xff,
106 0x83, 0x8c, 0x8b, 0xff,
107 0x52, 0x4a, 0x7b, 0xff,
108 0x83, 0x8c, 0x8b, 0xff
109 },
110 {0x73, 0xb6, 0x4d, 0x20, 0x98, 0x2b, 0xe1, 0xb8}
111 },
112 {
113 {
114 0x00, 0x2c, 0xff, 0xff,
115 0x94, 0x8d, 0x7b, 0xff,
116 0x4a, 0x5c, 0xbd, 0xff,
117 0x4a, 0x5c, 0xbd, 0xff,
118 0x4a, 0x5c, 0xbd, 0xff,
119 0x94, 0x8d, 0x7b, 0xff,
120 0x94, 0x8d, 0x7b, 0xff,
121 0x94, 0x8d, 0x7b, 0xff,
122 0xde, 0xbe, 0x39, 0xff,
123 0x94, 0x8d, 0x7b, 0xff,
124 0xde, 0xbe, 0x39, 0xff,
125 0xde, 0xbe, 0x39, 0xff,
126 0xde, 0xbe, 0x39, 0xff,
127 0xde, 0xbe, 0x39, 0xff,
128 0xde, 0xbe, 0x39, 0xff,
129 0x94, 0x8d, 0x7b, 0xff
130 },
131 {0xe7, 0xdd, 0x7f, 0x01, 0xf9, 0xab, 0x08, 0x80}
132 },
133 {
134 {
135 0x6b, 0x24, 0x21, 0xff,
136 0x7b, 0x4f, 0x5d, 0xff,
137 0x7b, 0x4f, 0x5d, 0xff,
138 0x8b, 0x7a, 0x99, 0xff,
139 0x7b, 0x4f, 0x5d, 0xff,
140 0x7b, 0x4f, 0x5d, 0xff,
141 0x6b, 0x24, 0x21, 0xff,
142 0x8b, 0x7a, 0x99, 0xff,
143 0x9c, 0xa6, 0xd6, 0xff,
144 0x6b, 0x24, 0x21, 0xff,
145 0x7b, 0x4f, 0x5d, 0xff,
146 0x8b, 0x7a, 0x99, 0xff,
147 0x6b, 0x24, 0x21, 0xff,
148 0x8b, 0x7a, 0x99, 0xff,
149 0x7b, 0x4f, 0x5d, 0xff,
150 0x9c, 0xa6, 0xd6, 0xff
151 },
152 {0x3a, 0x9d, 0x24, 0x69, 0xbd, 0x9f, 0xb4, 0x39}
153 }
154 };
155
156
157 static const struct dxt_data
158 dxt1_rgba_data[] = {
159 {
160 {
161 0x00, 0x00, 0x00, 0x00,
162 0x4e, 0xaa, 0x90, 0xff,
163 0x4e, 0xaa, 0x90, 0xff,
164 0x00, 0x00, 0x00, 0x00,
165 0x4e, 0xaa, 0x90, 0xff,
166 0x29, 0xff, 0xff, 0xff,
167 0x00, 0x00, 0x00, 0x00,
168 0x4e, 0xaa, 0x90, 0xff,
169 0x73, 0x55, 0x21, 0xff,
170 0x00, 0x00, 0x00, 0x00,
171 0x00, 0x00, 0x00, 0x00,
172 0x4e, 0xaa, 0x90, 0xff,
173 0x4e, 0xaa, 0x90, 0xff,
174 0x00, 0x00, 0x00, 0x00,
175 0x00, 0x00, 0x00, 0x00,
176 0x4e, 0xaa, 0x90, 0xff
177 },
178 {0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe}
179 },
180 {
181 {
182 0xb5, 0xe3, 0x63, 0xff,
183 0x00, 0x00, 0x00, 0x00,
184 0x6b, 0x24, 0x84, 0xff,
185 0xb5, 0xe3, 0x63, 0xff,
186 0x00, 0x00, 0x00, 0x00,
187 0xb5, 0xe3, 0x63, 0xff,
188 0x00, 0x00, 0x00, 0x00,
189 0x00, 0x00, 0x00, 0x00,
190 0x00, 0x00, 0x00, 0x00,
191 0x00, 0x00, 0x00, 0x00,
192 0x6b, 0x24, 0x84, 0xff,
193 0x6b, 0x24, 0x84, 0xff,
194 0x00, 0x00, 0x00, 0x00,
195 0xb5, 0xe3, 0x63, 0xff,
196 0x90, 0x83, 0x73, 0xff,
197 0xb5, 0xe3, 0x63, 0xff
198 },
199 {0x30, 0x69, 0x0c, 0xb7, 0x4d, 0xf7, 0x0f, 0x67}
200 },
201 {
202 {
203 0x00, 0x00, 0x00, 0x00,
204 0xc6, 0x86, 0x8c, 0xff,
205 0xc6, 0x86, 0x8c, 0xff,
206 0x21, 0x65, 0x42, 0xff,
207 0x21, 0x65, 0x42, 0xff,
208 0x21, 0x65, 0x42, 0xff,
209 0x21, 0x65, 0x42, 0xff,
210 0x00, 0x00, 0x00, 0x00,
211 0x00, 0x00, 0x00, 0x00,
212 0x21, 0x65, 0x42, 0xff,
213 0xc6, 0x86, 0x8c, 0xff,
214 0x00, 0x00, 0x00, 0x00,
215 0x00, 0x00, 0x00, 0x00,
216 0x00, 0x00, 0x00, 0x00,
217 0x00, 0x00, 0x00, 0x00,
218 0xc6, 0x86, 0x8c, 0xff
219 },
220 {0x28, 0x23, 0x31, 0xc4, 0x17, 0xc0, 0xd3, 0x7f}
221 },
222 {
223 {
224 0x00, 0x00, 0x00, 0x00,
225 0x00, 0x00, 0x00, 0x00,
226 0x00, 0x00, 0x00, 0x00,
227 0xc6, 0xe3, 0x9c, 0xff,
228 0x7b, 0x1c, 0x52, 0xff,
229 0x00, 0x00, 0x00, 0x00,
230 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00,
232 0x00, 0x00, 0x00, 0x00,
233 0x7b, 0x1c, 0x52, 0xff,
234 0x00, 0x00, 0x00, 0x00,
235 0x7b, 0x1c, 0x52, 0xff,
236 0xa0, 0x7f, 0x77, 0xff,
237 0xc6, 0xe3, 0x9c, 0xff,
238 0x00, 0x00, 0x00, 0x00,
239 0xa0, 0x7f, 0x77, 0xff
240 },
241 {0xea, 0x78, 0x13, 0xc7, 0x7f, 0xfc, 0x33, 0xb6}
242 },
243 };
244
245
246 static const struct dxt_data
247 dxt3_rgba_data[] = {
248 {
249 {
250 0x6d, 0xc6, 0x96, 0x77,
251 0x6d, 0xc6, 0x96, 0xee,
252 0x6d, 0xc6, 0x96, 0xaa,
253 0x8c, 0xff, 0xb5, 0x44,
254 0x6d, 0xc6, 0x96, 0xff,
255 0x6d, 0xc6, 0x96, 0x88,
256 0x31, 0x55, 0x5a, 0x66,
257 0x6d, 0xc6, 0x96, 0x99,
258 0x31, 0x55, 0x5a, 0xbb,
259 0x31, 0x55, 0x5a, 0x55,
260 0x31, 0x55, 0x5a, 0x11,
261 0x6d, 0xc6, 0x96, 0xcc,
262 0x6d, 0xc6, 0x96, 0xcc,
263 0x6d, 0xc6, 0x96, 0x11,
264 0x31, 0x55, 0x5a, 0x44,
265 0x31, 0x55, 0x5a, 0x88
266 },
267 {0xe7, 0x4a, 0x8f, 0x96, 0x5b, 0xc1, 0x1c, 0x84, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a}
268 },
269 {
270 {
271 0xad, 0xeb, 0x73, 0x99,
272 0x97, 0xaa, 0x86, 0x66,
273 0x6b, 0x28, 0xad, 0x99,
274 0xad, 0xeb, 0x73, 0x99,
275 0x6b, 0x28, 0xad, 0x22,
276 0xad, 0xeb, 0x73, 0xff,
277 0x97, 0xaa, 0x86, 0x55,
278 0x6b, 0x28, 0xad, 0x55,
279 0x6b, 0x28, 0xad, 0x44,
280 0xad, 0xeb, 0x73, 0x33,
281 0x6b, 0x28, 0xad, 0xee,
282 0x6b, 0x28, 0xad, 0x99,
283 0x97, 0xaa, 0x86, 0x66,
284 0xad, 0xeb, 0x73, 0xbb,
285 0x97, 0xaa, 0x86, 0x99,
286 0xad, 0xeb, 0x73, 0xbb
287 },
288 {0x69, 0x99, 0xf2, 0x55, 0x34, 0x9e, 0xb6, 0xb9, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22}
289 },
290 {
291 {
292 0x63, 0xd7, 0xd6, 0x00,
293 0x57, 0x62, 0x5d, 0xdd,
294 0x57, 0x62, 0x5d, 0xcc,
295 0x57, 0x62, 0x5d, 0xbb,
296 0x52, 0x28, 0x21, 0xaa,
297 0x57, 0x62, 0x5d, 0xcc,
298 0x57, 0x62, 0x5d, 0xcc,
299 0x57, 0x62, 0x5d, 0x66,
300 0x57, 0x62, 0x5d, 0x22,
301 0x57, 0x62, 0x5d, 0xdd,
302 0x63, 0xd7, 0xd6, 0xee,
303 0x57, 0x62, 0x5d, 0x33,
304 0x63, 0xd7, 0xd6, 0x55,
305 0x52, 0x28, 0x21, 0x55,
306 0x57, 0x62, 0x5d, 0x11,
307 0x5d, 0x9c, 0x99, 0xee
308 },
309 {0xd0, 0xbc, 0xca, 0x6c, 0xd2, 0x3e, 0x55, 0xe1, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4}
310 },
311 {
312 {
313 0x94, 0x6f, 0x60, 0x22,
314 0x94, 0x6f, 0x60, 0x22,
315 0xc5, 0xab, 0x76, 0x11,
316 0xc5, 0xab, 0x76, 0xee,
317 0x63, 0x34, 0x4a, 0xdd,
318 0x63, 0x34, 0x4a, 0x33,
319 0x94, 0x6f, 0x60, 0x77,
320 0xf7, 0xe7, 0x8c, 0x00,
321 0x94, 0x6f, 0x60, 0x33,
322 0x63, 0x34, 0x4a, 0xaa,
323 0x94, 0x6f, 0x60, 0x77,
324 0x63, 0x34, 0x4a, 0xcc,
325 0x94, 0x6f, 0x60, 0xaa,
326 0xf7, 0xe7, 0x8c, 0x99,
327 0x63, 0x34, 0x4a, 0x44,
328 0xc5, 0xab, 0x76, 0xaa
329 },
330 {0x22, 0xe1, 0x3d, 0x07, 0xa3, 0xc7, 0x9a, 0xa4, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93}
331 },
332 };
333
334
335 static const struct dxt_data
336 dxt5_rgba_data[] = {
337 {
338 {
339 0x6d, 0xc6, 0x96, 0x74,
340 0x6d, 0xc6, 0x96, 0xf8,
341 0x6d, 0xc6, 0x96, 0xb6,
342 0x8c, 0xff, 0xb5, 0x53,
343 0x6d, 0xc6, 0x96, 0xf8,
344 0x6d, 0xc6, 0x96, 0x95,
345 0x31, 0x55, 0x5a, 0x53,
346 0x6d, 0xc6, 0x96, 0x95,
347 0x31, 0x55, 0x5a, 0xb6,
348 0x31, 0x55, 0x5a, 0x53,
349 0x31, 0x55, 0x5a, 0x11,
350 0x6d, 0xc6, 0x96, 0xd7,
351 0x6d, 0xc6, 0x96, 0xb6,
352 0x6d, 0xc6, 0x96, 0x11,
353 0x31, 0x55, 0x5a, 0x32,
354 0x31, 0x55, 0x5a, 0x95
355 },
356 {0xf8, 0x11, 0xc5, 0x0c, 0x9a, 0x73, 0xb4, 0x9c, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a}
357 },
358 {
359 {
360 0xad, 0xeb, 0x73, 0xa1,
361 0x97, 0xaa, 0x86, 0x65,
362 0x6b, 0x28, 0xad, 0xa1,
363 0xad, 0xeb, 0x73, 0xa1,
364 0x6b, 0x28, 0xad, 0x2a,
365 0xad, 0xeb, 0x73, 0xfb,
366 0x97, 0xaa, 0x86, 0x47,
367 0x6b, 0x28, 0xad, 0x65,
368 0x6b, 0x28, 0xad, 0x47,
369 0xad, 0xeb, 0x73, 0x47,
370 0x6b, 0x28, 0xad, 0xdd,
371 0x6b, 0x28, 0xad, 0xa1,
372 0x97, 0xaa, 0x86, 0x65,
373 0xad, 0xeb, 0x73, 0xbf,
374 0x97, 0xaa, 0x86, 0xa1,
375 0xad, 0xeb, 0x73, 0xbf
376 },
377 {0xfb, 0x2a, 0x34, 0x19, 0xdc, 0xbf, 0xe8, 0x71, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22}
378 },
379 {
380 {
381 0x63, 0xd7, 0xd6, 0x00,
382 0x57, 0x62, 0x5d, 0xf5,
383 0x57, 0x62, 0x5d, 0xd2,
384 0x57, 0x62, 0x5d, 0xaf,
385 0x52, 0x28, 0x21, 0xaf,
386 0x57, 0x62, 0x5d, 0xd2,
387 0x57, 0x62, 0x5d, 0xd2,
388 0x57, 0x62, 0x5d, 0x69,
389 0x57, 0x62, 0x5d, 0x23,
390 0x57, 0x62, 0x5d, 0xd2,
391 0x63, 0xd7, 0xd6, 0xf5,
392 0x57, 0x62, 0x5d, 0x46,
393 0x63, 0xd7, 0xd6, 0x46,
394 0x52, 0x28, 0x21, 0x69,
395 0x57, 0x62, 0x5d, 0x23,
396 0x5d, 0x9c, 0x99, 0xf5
397 },
398 {0xf5, 0x00, 0x81, 0x36, 0xa9, 0x17, 0xec, 0x1e, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4}
399 },
400 {
401 {
402 0x94, 0x6f, 0x60, 0x25,
403 0x94, 0x6f, 0x60, 0x25,
404 0xc5, 0xab, 0x76, 0x05,
405 0xc5, 0xab, 0x76, 0xe8,
406 0x63, 0x34, 0x4a, 0xe8,
407 0x63, 0x34, 0x4a, 0x25,
408 0x94, 0x6f, 0x60, 0x86,
409 0xf7, 0xe7, 0x8c, 0x05,
410 0x94, 0x6f, 0x60, 0x25,
411 0x63, 0x34, 0x4a, 0xa7,
412 0x94, 0x6f, 0x60, 0x66,
413 0x63, 0x34, 0x4a, 0xc7,
414 0x94, 0x6f, 0x60, 0xa7,
415 0xf7, 0xe7, 0x8c, 0xa7,
416 0x63, 0x34, 0x4a, 0x45,
417 0xc5, 0xab, 0x76, 0xa7
418 },
419 {0xe8, 0x05, 0x7f, 0x80, 0x33, 0x5f, 0xb5, 0x79, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93}
420 },
421 };
422
423
424 static INLINE void
425 st_sample_dxt_pixel_block(enum pipe_format format,
426 uint8_t *raw,
427 float *rgba, unsigned rgba_stride,
428 unsigned w, unsigned h)
429 {
430 const struct dxt_data *data;
431 unsigned n;
432 unsigned i;
433 unsigned x, y, ch;
434
435 switch(format) {
436 case PIPE_FORMAT_DXT1_RGB:
437 data = dxt1_rgb_data;
438 n = sizeof(dxt1_rgb_data)/sizeof(dxt1_rgb_data[0]);
439 break;
440 case PIPE_FORMAT_DXT1_RGBA:
441 data = dxt1_rgba_data;
442 n = sizeof(dxt1_rgba_data)/sizeof(dxt1_rgba_data[0]);
443 break;
444 case PIPE_FORMAT_DXT3_RGBA:
445 data = dxt3_rgba_data;
446 n = sizeof(dxt3_rgba_data)/sizeof(dxt3_rgba_data[0]);
447 break;
448 case PIPE_FORMAT_DXT5_RGBA:
449 data = dxt5_rgba_data;
450 n = sizeof(dxt5_rgba_data)/sizeof(dxt5_rgba_data[0]);
451 break;
452 default:
453 assert(0);
454 return;
455 }
456
457 i = st_random() % n;
458
459 for(y = 0; y < h; ++y)
460 for(x = 0; x < w; ++x)
461 for(ch = 0; ch < 4; ++ch)
462 rgba[y*rgba_stride + x*4 + ch] = (float)(data[i].rgba[y*4*4 + x*4 + ch])/255.0f;
463
464 memcpy(raw, data[i].raw, pf_get_blocksize(format));
465 }
466
467
468 static INLINE void
469 st_sample_generic_pixel_block(enum pipe_format format,
470 uint8_t *raw,
471 float *rgba, unsigned rgba_stride,
472 unsigned w, unsigned h)
473 {
474 unsigned i;
475 unsigned x, y, ch;
476 int blocksize = pf_get_blocksize(format);
477
478 for(i = 0; i < blocksize; ++i)
479 raw[i] = (uint8_t)st_random();
480
481
482 pipe_tile_raw_to_rgba(format,
483 raw,
484 w, h,
485 rgba, rgba_stride);
486
487 if(format == PIPE_FORMAT_YCBCR || format == PIPE_FORMAT_YCBCR_REV) {
488 for(y = 0; y < h; ++y) {
489 for(x = 0; x < w; ++x) {
490 for(ch = 0; ch < 4; ++ch) {
491 unsigned offset = y*rgba_stride + x*4 + ch;
492 rgba[offset] = CLAMP(rgba[offset], 0.0f, 1.0f);
493 }
494 }
495 }
496 }
497 }
498
499
500 /**
501 * Randomly sample pixels.
502 */
503 void
504 st_sample_pixel_block(enum pipe_format format,
505 void *raw,
506 float *rgba, unsigned rgba_stride,
507 unsigned w, unsigned h)
508 {
509 switch(format) {
510 case PIPE_FORMAT_DXT1_RGB:
511 case PIPE_FORMAT_DXT1_RGBA:
512 case PIPE_FORMAT_DXT3_RGBA:
513 case PIPE_FORMAT_DXT5_RGBA:
514 st_sample_dxt_pixel_block(format, raw, rgba, rgba_stride, w, h);
515 break;
516
517 default:
518 st_sample_generic_pixel_block(format, raw, rgba, rgba_stride, w, h);
519 break;
520 }
521 }
522
523
524 void
525 st_sample_surface(struct st_surface *surface, float *rgba)
526 {
527 struct pipe_texture *texture = surface->texture;
528 struct pipe_screen *screen = texture->screen;
529 unsigned width = u_minify(texture->width0, surface->level);
530 unsigned height = u_minify(texture->height0, surface->level);
531 uint rgba_stride = width * 4;
532 struct pipe_transfer *transfer;
533 void *raw;
534
535 transfer = screen->get_tex_transfer(screen,
536 surface->texture,
537 surface->face,
538 surface->level,
539 surface->zslice,
540 PIPE_TRANSFER_WRITE,
541 0, 0,
542 width,
543 height);
544 if (!transfer)
545 return;
546
547 raw = screen->transfer_map(screen, transfer);
548 if (raw) {
549 enum pipe_format format = texture->format;
550 uint x, y;
551 int nblocksx = pf_get_nblocksx(format, width);
552 int nblocksy = pf_get_nblocksy(format, height);
553 int blockwidth = pf_get_blockwidth(format);
554 int blockheight = pf_get_blockheight(format);
555 int blocksize = pf_get_blocksize(format);
556
557
558 for (y = 0; y < nblocksy; ++y) {
559 for (x = 0; x < nblocksx; ++x) {
560 st_sample_pixel_block(format,
561 (uint8_t *) raw + y * transfer->stride + x * blocksize,
562 rgba + y * blockheight * rgba_stride + x * blockwidth * 4,
563 rgba_stride,
564 MIN2(blockwidth, width - x*blockwidth),
565 MIN2(blockheight, height - y*blockheight));
566 }
567 }
568
569 screen->transfer_unmap(screen, transfer);
570 }
571
572 screen->tex_transfer_destroy(transfer);
573 }