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