Merge branch 'width0'
[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 const struct pipe_format_block *block,
427 uint8_t *raw,
428 float *rgba, unsigned rgba_stride,
429 unsigned w, unsigned h)
430 {
431 const struct dxt_data *data;
432 unsigned n;
433 unsigned i;
434 unsigned x, y, ch;
435
436 switch(format) {
437 case PIPE_FORMAT_DXT1_RGB:
438 data = dxt1_rgb_data;
439 n = sizeof(dxt1_rgb_data)/sizeof(dxt1_rgb_data[0]);
440 break;
441 case PIPE_FORMAT_DXT1_RGBA:
442 data = dxt1_rgba_data;
443 n = sizeof(dxt1_rgba_data)/sizeof(dxt1_rgba_data[0]);
444 break;
445 case PIPE_FORMAT_DXT3_RGBA:
446 data = dxt3_rgba_data;
447 n = sizeof(dxt3_rgba_data)/sizeof(dxt3_rgba_data[0]);
448 break;
449 case PIPE_FORMAT_DXT5_RGBA:
450 data = dxt5_rgba_data;
451 n = sizeof(dxt5_rgba_data)/sizeof(dxt5_rgba_data[0]);
452 break;
453 default:
454 assert(0);
455 return;
456 }
457
458 i = st_random() % n;
459
460 for(y = 0; y < h; ++y)
461 for(x = 0; x < w; ++x)
462 for(ch = 0; ch < 4; ++ch)
463 rgba[y*rgba_stride + x*4 + ch] = (float)(data[i].rgba[y*4*4 + x*4 + ch])/255.0f;
464
465 memcpy(raw, data[i].raw, block->size);
466 }
467
468
469 static INLINE void
470 st_sample_generic_pixel_block(enum pipe_format format,
471 const struct pipe_format_block *block,
472 uint8_t *raw,
473 float *rgba, unsigned rgba_stride,
474 unsigned w, unsigned h)
475 {
476 unsigned i;
477 unsigned x, y, ch;
478
479 for(i = 0; i < block->size; ++i)
480 raw[i] = (uint8_t)st_random();
481
482
483 pipe_tile_raw_to_rgba(format,
484 raw,
485 w, h,
486 rgba, rgba_stride);
487
488 if(format == PIPE_FORMAT_YCBCR || format == PIPE_FORMAT_YCBCR_REV) {
489 for(y = 0; y < h; ++y) {
490 for(x = 0; x < w; ++x) {
491 for(ch = 0; ch < 4; ++ch) {
492 unsigned offset = y*rgba_stride + x*4 + ch;
493 rgba[offset] = CLAMP(rgba[offset], 0.0f, 1.0f);
494 }
495 }
496 }
497 }
498 }
499
500
501 /**
502 * Randomly sample pixels.
503 */
504 void
505 st_sample_pixel_block(enum pipe_format format,
506 const struct pipe_format_block *block,
507 void *raw,
508 float *rgba, unsigned rgba_stride,
509 unsigned w, unsigned h)
510 {
511 switch(format) {
512 case PIPE_FORMAT_DXT1_RGB:
513 case PIPE_FORMAT_DXT1_RGBA:
514 case PIPE_FORMAT_DXT3_RGBA:
515 case PIPE_FORMAT_DXT5_RGBA:
516 st_sample_dxt_pixel_block(format, block, raw, rgba, rgba_stride, w, h);
517 break;
518
519 default:
520 st_sample_generic_pixel_block(format, block, raw, rgba, rgba_stride, w, h);
521 break;
522 }
523 }
524
525
526 void
527 st_sample_surface(struct st_surface *surface, float *rgba)
528 {
529 struct pipe_texture *texture = surface->texture;
530 struct pipe_screen *screen = texture->screen;
531 unsigned width = u_minify(texture->width0, surface->level);
532 unsigned height = u_minify(texture->height0, surface->level);
533 uint rgba_stride = width * 4;
534 struct pipe_transfer *transfer;
535 void *raw;
536
537 transfer = screen->get_tex_transfer(screen,
538 surface->texture,
539 surface->face,
540 surface->level,
541 surface->zslice,
542 PIPE_TRANSFER_WRITE,
543 0, 0,
544 width,
545 height);
546 if (!transfer)
547 return;
548
549 raw = screen->transfer_map(screen, transfer);
550 if (raw) {
551 const struct pipe_format_block *block = &texture->block;
552 uint x, y;
553
554 for (y = 0; y < transfer->nblocksy; ++y) {
555 for (x = 0; x < transfer->nblocksx; ++x) {
556 st_sample_pixel_block(texture->format,
557 block,
558 (uint8_t *) raw + y * transfer->stride + x * block->size,
559 rgba + y * block->height * rgba_stride + x * block->width * 4,
560 rgba_stride,
561 MIN2(block->width, width - x*block->width),
562 MIN2(block->height, height - y*block->height));
563 }
564 }
565
566 screen->transfer_unmap(screen, transfer);
567 }
568
569 screen->tex_transfer_destroy(transfer);
570 }