gallium: add initial pure integer support (v2)
[mesa.git] / src / gallium / auxiliary / util / u_tile.c
1 /**************************************************************************
2 *
3 * Copyright 2007 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 * RGBA/float tile get/put functions.
30 * Usable both by drivers and state trackers.
31 */
32
33
34 #include "pipe/p_defines.h"
35 #include "util/u_inlines.h"
36
37 #include "util/u_format.h"
38 #include "util/u_math.h"
39 #include "util/u_memory.h"
40 #include "util/u_rect.h"
41 #include "util/u_tile.h"
42
43
44 /**
45 * Move raw block of pixels from transfer object to user memory.
46 */
47 void
48 pipe_get_tile_raw(struct pipe_context *pipe,
49 struct pipe_transfer *pt,
50 uint x, uint y, uint w, uint h,
51 void *dst, int dst_stride)
52 {
53 const void *src;
54
55 if (dst_stride == 0)
56 dst_stride = util_format_get_stride(pt->resource->format, w);
57
58 if (u_clip_tile(x, y, &w, &h, &pt->box))
59 return;
60
61 src = pipe->transfer_map(pipe, pt);
62 assert(src);
63 if(!src)
64 return;
65
66 util_copy_rect(dst, pt->resource->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y);
67
68 pipe->transfer_unmap(pipe, pt);
69 }
70
71
72 /**
73 * Move raw block of pixels from user memory to transfer object.
74 */
75 void
76 pipe_put_tile_raw(struct pipe_context *pipe,
77 struct pipe_transfer *pt,
78 uint x, uint y, uint w, uint h,
79 const void *src, int src_stride)
80 {
81 void *dst;
82 enum pipe_format format = pt->resource->format;
83
84 if (src_stride == 0)
85 src_stride = util_format_get_stride(format, w);
86
87 if (u_clip_tile(x, y, &w, &h, &pt->box))
88 return;
89
90 dst = pipe->transfer_map(pipe, pt);
91 assert(dst);
92 if(!dst)
93 return;
94
95 util_copy_rect(dst, format, pt->stride, x, y, w, h, src, src_stride, 0, 0);
96
97 pipe->transfer_unmap(pipe, pt);
98 }
99
100
101
102
103 /** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
104 #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
105
106 #define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
107 us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
108
109
110
111 /*** PIPE_FORMAT_Z16_UNORM ***/
112
113 /**
114 * Return each Z value as four floats in [0,1].
115 */
116 static void
117 z16_get_tile_rgba(const ushort *src,
118 unsigned w, unsigned h,
119 float *p,
120 unsigned dst_stride)
121 {
122 const float scale = 1.0f / 65535.0f;
123 unsigned i, j;
124
125 for (i = 0; i < h; i++) {
126 float *pRow = p;
127 for (j = 0; j < w; j++, pRow += 4) {
128 pRow[0] =
129 pRow[1] =
130 pRow[2] =
131 pRow[3] = *src++ * scale;
132 }
133 p += dst_stride;
134 }
135 }
136
137
138
139
140 /*** PIPE_FORMAT_Z32_UNORM ***/
141
142 /**
143 * Return each Z value as four floats in [0,1].
144 */
145 static void
146 z32_get_tile_rgba(const unsigned *src,
147 unsigned w, unsigned h,
148 float *p,
149 unsigned dst_stride)
150 {
151 const double scale = 1.0 / (double) 0xffffffff;
152 unsigned i, j;
153
154 for (i = 0; i < h; i++) {
155 float *pRow = p;
156 for (j = 0; j < w; j++, pRow += 4) {
157 pRow[0] =
158 pRow[1] =
159 pRow[2] =
160 pRow[3] = (float) (*src++ * scale);
161 }
162 p += dst_stride;
163 }
164 }
165
166
167 /*** PIPE_FORMAT_Z24_UNORM_S8_USCALED ***/
168
169 /**
170 * Return Z component as four float in [0,1]. Stencil part ignored.
171 */
172 static void
173 s8z24_get_tile_rgba(const unsigned *src,
174 unsigned w, unsigned h,
175 float *p,
176 unsigned dst_stride)
177 {
178 const double scale = 1.0 / ((1 << 24) - 1);
179 unsigned i, j;
180
181 for (i = 0; i < h; i++) {
182 float *pRow = p;
183 for (j = 0; j < w; j++, pRow += 4) {
184 pRow[0] =
185 pRow[1] =
186 pRow[2] =
187 pRow[3] = (float) (scale * (*src++ & 0xffffff));
188 }
189 p += dst_stride;
190 }
191 }
192
193
194 /*** PIPE_FORMAT_S8_USCALED_Z24_UNORM ***/
195
196 /**
197 * Return Z component as four float in [0,1]. Stencil part ignored.
198 */
199 static void
200 z24s8_get_tile_rgba(const unsigned *src,
201 unsigned w, unsigned h,
202 float *p,
203 unsigned dst_stride)
204 {
205 const double scale = 1.0 / ((1 << 24) - 1);
206 unsigned i, j;
207
208 for (i = 0; i < h; i++) {
209 float *pRow = p;
210 for (j = 0; j < w; j++, pRow += 4) {
211 pRow[0] =
212 pRow[1] =
213 pRow[2] =
214 pRow[3] = (float) (scale * (*src++ >> 8));
215 }
216 p += dst_stride;
217 }
218 }
219
220 /*** PIPE_FORMAT_S8X24_USCALED ***/
221
222 /**
223 * Return S component as four uint32_t in [0..255]. Z part ignored.
224 */
225 static void
226 s8x24_get_tile_rgba(const unsigned *src,
227 unsigned w, unsigned h,
228 float *p,
229 unsigned dst_stride)
230 {
231 unsigned i, j;
232
233 for (i = 0; i < h; i++) {
234 float *pRow = p;
235
236 for (j = 0; j < w; j++, pRow += 4) {
237 pRow[0] =
238 pRow[1] =
239 pRow[2] =
240 pRow[3] = (float)((*src++ >> 24) & 0xff);
241 }
242
243 p += dst_stride;
244 }
245 }
246
247 /*** PIPE_FORMAT_X24S8_USCALED ***/
248
249 /**
250 * Return S component as four uint32_t in [0..255]. Z part ignored.
251 */
252 static void
253 x24s8_get_tile_rgba(const unsigned *src,
254 unsigned w, unsigned h,
255 float *p,
256 unsigned dst_stride)
257 {
258 unsigned i, j;
259
260 for (i = 0; i < h; i++) {
261 float *pRow = p;
262 for (j = 0; j < w; j++, pRow += 4) {
263 pRow[0] =
264 pRow[1] =
265 pRow[2] =
266 pRow[3] = (float)(*src++ & 0xff);
267 }
268 p += dst_stride;
269 }
270 }
271
272
273 /**
274 * Return S component as four uint32_t in [0..255]. Z part ignored.
275 */
276 static void
277 s8_get_tile_rgba(const unsigned char *src,
278 unsigned w, unsigned h,
279 float *p,
280 unsigned dst_stride)
281 {
282 unsigned i, j;
283
284 for (i = 0; i < h; i++) {
285 float *pRow = p;
286 for (j = 0; j < w; j++, pRow += 4) {
287 pRow[0] =
288 pRow[1] =
289 pRow[2] =
290 pRow[3] = (float)(*src++ & 0xff);
291 }
292 p += dst_stride;
293 }
294 }
295
296 /*** PIPE_FORMAT_Z32_FLOAT ***/
297
298 /**
299 * Return each Z value as four floats in [0,1].
300 */
301 static void
302 z32f_get_tile_rgba(const float *src,
303 unsigned w, unsigned h,
304 float *p,
305 unsigned dst_stride)
306 {
307 unsigned i, j;
308
309 for (i = 0; i < h; i++) {
310 float *pRow = p;
311 for (j = 0; j < w; j++, pRow += 4) {
312 pRow[0] =
313 pRow[1] =
314 pRow[2] =
315 pRow[3] = *src++;
316 }
317 p += dst_stride;
318 }
319 }
320
321 /*** PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED ***/
322
323 /**
324 * Return each Z value as four floats in [0,1].
325 */
326 static void
327 z32f_x24s8_get_tile_rgba(const float *src,
328 unsigned w, unsigned h,
329 float *p,
330 unsigned dst_stride)
331 {
332 unsigned i, j;
333
334 for (i = 0; i < h; i++) {
335 float *pRow = p;
336 for (j = 0; j < w; j++, pRow += 4) {
337 pRow[0] =
338 pRow[1] =
339 pRow[2] =
340 pRow[3] = *src;
341 src += 2;
342 }
343 p += dst_stride;
344 }
345 }
346
347
348 void
349 pipe_tile_raw_to_rgba(enum pipe_format format,
350 void *src,
351 uint w, uint h,
352 float *dst, unsigned dst_stride)
353 {
354 switch (format) {
355 case PIPE_FORMAT_Z16_UNORM:
356 z16_get_tile_rgba((ushort *) src, w, h, dst, dst_stride);
357 break;
358 case PIPE_FORMAT_Z32_UNORM:
359 z32_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
360 break;
361 case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
362 case PIPE_FORMAT_Z24X8_UNORM:
363 s8z24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
364 break;
365 case PIPE_FORMAT_S8_USCALED:
366 s8_get_tile_rgba((unsigned char *) src, w, h, dst, dst_stride);
367 break;
368 case PIPE_FORMAT_X24S8_USCALED:
369 s8x24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
370 break;
371 case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
372 case PIPE_FORMAT_X8Z24_UNORM:
373 z24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
374 break;
375 case PIPE_FORMAT_S8X24_USCALED:
376 x24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
377 break;
378 case PIPE_FORMAT_Z32_FLOAT:
379 z32f_get_tile_rgba((float *) src, w, h, dst, dst_stride);
380 break;
381 case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
382 z32f_x24s8_get_tile_rgba((float *) src, w, h, dst, dst_stride);
383 break;
384 default:
385 util_format_read_4f(format,
386 dst, dst_stride * sizeof(float),
387 src, util_format_get_stride(format, w),
388 0, 0, w, h);
389 }
390 }
391
392 void
393 pipe_tile_raw_to_unsigned(enum pipe_format format,
394 void *src,
395 uint w, uint h,
396 unsigned *dst, unsigned dst_stride)
397 {
398 util_format_read_4ui(format,
399 dst, dst_stride * sizeof(float),
400 src, util_format_get_stride(format, w),
401 0, 0, w, h);
402 }
403
404 void
405 pipe_tile_raw_to_signed(enum pipe_format format,
406 void *src,
407 uint w, uint h,
408 int *dst, unsigned dst_stride)
409 {
410 util_format_read_4i(format,
411 dst, dst_stride * sizeof(float),
412 src, util_format_get_stride(format, w),
413 0, 0, w, h);
414 }
415
416 void
417 pipe_get_tile_rgba(struct pipe_context *pipe,
418 struct pipe_transfer *pt,
419 uint x, uint y, uint w, uint h,
420 float *p)
421 {
422 pipe_get_tile_rgba_format(pipe, pt, x, y, w, h, pt->resource->format, p);
423 }
424
425
426 void
427 pipe_get_tile_rgba_format(struct pipe_context *pipe,
428 struct pipe_transfer *pt,
429 uint x, uint y, uint w, uint h,
430 enum pipe_format format,
431 float *p)
432 {
433 unsigned dst_stride = w * 4;
434 void *packed;
435
436 if (u_clip_tile(x, y, &w, &h, &pt->box)) {
437 return;
438 }
439
440 packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
441 if (!packed) {
442 return;
443 }
444
445 if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
446 assert((x & 1) == 0);
447 }
448
449 pipe_get_tile_raw(pipe, pt, x, y, w, h, packed, 0);
450
451 pipe_tile_raw_to_rgba(format, packed, w, h, p, dst_stride);
452
453 FREE(packed);
454 }
455
456
457 void
458 pipe_put_tile_rgba(struct pipe_context *pipe,
459 struct pipe_transfer *pt,
460 uint x, uint y, uint w, uint h,
461 const float *p)
462 {
463 pipe_put_tile_rgba_format(pipe, pt, x, y, w, h, pt->resource->format, p);
464 }
465
466
467 void
468 pipe_put_tile_rgba_format(struct pipe_context *pipe,
469 struct pipe_transfer *pt,
470 uint x, uint y, uint w, uint h,
471 enum pipe_format format,
472 const float *p)
473 {
474 unsigned src_stride = w * 4;
475 void *packed;
476
477 if (u_clip_tile(x, y, &w, &h, &pt->box))
478 return;
479
480 packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
481
482 if (!packed)
483 return;
484
485 switch (format) {
486 case PIPE_FORMAT_Z16_UNORM:
487 /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
488 break;
489 case PIPE_FORMAT_Z32_UNORM:
490 /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
491 break;
492 case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
493 case PIPE_FORMAT_Z24X8_UNORM:
494 /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
495 break;
496 case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
497 case PIPE_FORMAT_X8Z24_UNORM:
498 /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
499 break;
500 case PIPE_FORMAT_Z32_FLOAT:
501 /*z32f_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
502 break;
503 case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
504 /*z32f_s8x24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
505 break;
506 default:
507 util_format_write_4f(format,
508 p, src_stride * sizeof(float),
509 packed, util_format_get_stride(format, w),
510 0, 0, w, h);
511 }
512
513 pipe_put_tile_raw(pipe, pt, x, y, w, h, packed, 0);
514
515 FREE(packed);
516 }
517
518 void
519 pipe_put_tile_i_format(struct pipe_context *pipe,
520 struct pipe_transfer *pt,
521 uint x, uint y, uint w, uint h,
522 enum pipe_format format,
523 const int *p)
524 {
525 unsigned src_stride = w * 4;
526 void *packed;
527
528 if (u_clip_tile(x, y, &w, &h, &pt->box))
529 return;
530
531 packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
532
533 if (!packed)
534 return;
535
536 util_format_write_4i(format,
537 p, src_stride * sizeof(float),
538 packed, util_format_get_stride(format, w),
539 0, 0, w, h);
540
541 pipe_put_tile_raw(pipe, pt, x, y, w, h, packed, 0);
542
543 FREE(packed);
544 }
545
546 void
547 pipe_put_tile_ui_format(struct pipe_context *pipe,
548 struct pipe_transfer *pt,
549 uint x, uint y, uint w, uint h,
550 enum pipe_format format,
551 const unsigned int *p)
552 {
553 unsigned src_stride = w * 4;
554 void *packed;
555
556 if (u_clip_tile(x, y, &w, &h, &pt->box))
557 return;
558
559 packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
560
561 if (!packed)
562 return;
563
564 util_format_write_4ui(format,
565 p, src_stride * sizeof(float),
566 packed, util_format_get_stride(format, w),
567 0, 0, w, h);
568
569 pipe_put_tile_raw(pipe, pt, x, y, w, h, packed, 0);
570
571 FREE(packed);
572 }
573
574 /**
575 * Get a block of Z values, converted to 32-bit range.
576 */
577 void
578 pipe_get_tile_z(struct pipe_context *pipe,
579 struct pipe_transfer *pt,
580 uint x, uint y, uint w, uint h,
581 uint *z)
582 {
583 const uint dstStride = w;
584 ubyte *map;
585 uint *pDest = z;
586 uint i, j;
587 enum pipe_format format = pt->resource->format;
588
589 if (u_clip_tile(x, y, &w, &h, &pt->box))
590 return;
591
592 map = (ubyte *)pipe->transfer_map(pipe, pt);
593 if (!map) {
594 assert(0);
595 return;
596 }
597
598 switch (format) {
599 case PIPE_FORMAT_Z32_UNORM:
600 {
601 const uint *ptrc
602 = (const uint *)(map + y * pt->stride + x*4);
603 for (i = 0; i < h; i++) {
604 memcpy(pDest, ptrc, 4 * w);
605 pDest += dstStride;
606 ptrc += pt->stride/4;
607 }
608 }
609 break;
610 case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
611 case PIPE_FORMAT_Z24X8_UNORM:
612 {
613 const uint *ptrc
614 = (const uint *)(map + y * pt->stride + x*4);
615 for (i = 0; i < h; i++) {
616 for (j = 0; j < w; j++) {
617 /* convert 24-bit Z to 32-bit Z */
618 pDest[j] = (ptrc[j] << 8) | ((ptrc[j] >> 16) & 0xff);
619 }
620 pDest += dstStride;
621 ptrc += pt->stride/4;
622 }
623 }
624 break;
625 case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
626 case PIPE_FORMAT_X8Z24_UNORM:
627 {
628 const uint *ptrc
629 = (const uint *)(map + y * pt->stride + x*4);
630 for (i = 0; i < h; i++) {
631 for (j = 0; j < w; j++) {
632 /* convert 24-bit Z to 32-bit Z */
633 pDest[j] = (ptrc[j] & 0xffffff00) | ((ptrc[j] >> 24) & 0xff);
634 }
635 pDest += dstStride;
636 ptrc += pt->stride/4;
637 }
638 }
639 break;
640 case PIPE_FORMAT_Z16_UNORM:
641 {
642 const ushort *ptrc
643 = (const ushort *)(map + y * pt->stride + x*2);
644 for (i = 0; i < h; i++) {
645 for (j = 0; j < w; j++) {
646 /* convert 16-bit Z to 32-bit Z */
647 pDest[j] = (ptrc[j] << 16) | ptrc[j];
648 }
649 pDest += dstStride;
650 ptrc += pt->stride/2;
651 }
652 }
653 break;
654 default:
655 assert(0);
656 }
657
658 pipe->transfer_unmap(pipe, pt);
659 }
660
661
662 void
663 pipe_put_tile_z(struct pipe_context *pipe,
664 struct pipe_transfer *pt,
665 uint x, uint y, uint w, uint h,
666 const uint *zSrc)
667 {
668 const uint srcStride = w;
669 const uint *ptrc = zSrc;
670 ubyte *map;
671 uint i, j;
672 enum pipe_format format = pt->resource->format;
673
674 if (u_clip_tile(x, y, &w, &h, &pt->box))
675 return;
676
677 map = (ubyte *)pipe->transfer_map(pipe, pt);
678 if (!map) {
679 assert(0);
680 return;
681 }
682
683 switch (format) {
684 case PIPE_FORMAT_Z32_UNORM:
685 {
686 uint *pDest = (uint *) (map + y * pt->stride + x*4);
687 for (i = 0; i < h; i++) {
688 memcpy(pDest, ptrc, 4 * w);
689 pDest += pt->stride/4;
690 ptrc += srcStride;
691 }
692 }
693 break;
694 case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
695 {
696 uint *pDest = (uint *) (map + y * pt->stride + x*4);
697 /*assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);*/
698 for (i = 0; i < h; i++) {
699 for (j = 0; j < w; j++) {
700 /* convert 32-bit Z to 24-bit Z, preserve stencil */
701 pDest[j] = (pDest[j] & 0xff000000) | ptrc[j] >> 8;
702 }
703 pDest += pt->stride/4;
704 ptrc += srcStride;
705 }
706 }
707 break;
708 case PIPE_FORMAT_Z24X8_UNORM:
709 {
710 uint *pDest = (uint *) (map + y * pt->stride + x*4);
711 for (i = 0; i < h; i++) {
712 for (j = 0; j < w; j++) {
713 /* convert 32-bit Z to 24-bit Z (0 stencil) */
714 pDest[j] = ptrc[j] >> 8;
715 }
716 pDest += pt->stride/4;
717 ptrc += srcStride;
718 }
719 }
720 break;
721 case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
722 {
723 uint *pDest = (uint *) (map + y * pt->stride + x*4);
724 /*assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);*/
725 for (i = 0; i < h; i++) {
726 for (j = 0; j < w; j++) {
727 /* convert 32-bit Z to 24-bit Z, preserve stencil */
728 pDest[j] = (pDest[j] & 0xff) | (ptrc[j] & 0xffffff00);
729 }
730 pDest += pt->stride/4;
731 ptrc += srcStride;
732 }
733 }
734 break;
735 case PIPE_FORMAT_X8Z24_UNORM:
736 {
737 uint *pDest = (uint *) (map + y * pt->stride + x*4);
738 for (i = 0; i < h; i++) {
739 for (j = 0; j < w; j++) {
740 /* convert 32-bit Z to 24-bit Z (0 stencil) */
741 pDest[j] = ptrc[j] & 0xffffff00;
742 }
743 pDest += pt->stride/4;
744 ptrc += srcStride;
745 }
746 }
747 break;
748 case PIPE_FORMAT_Z16_UNORM:
749 {
750 ushort *pDest = (ushort *) (map + y * pt->stride + x*2);
751 for (i = 0; i < h; i++) {
752 for (j = 0; j < w; j++) {
753 /* convert 32-bit Z to 16-bit Z */
754 pDest[j] = ptrc[j] >> 16;
755 }
756 pDest += pt->stride/2;
757 ptrc += srcStride;
758 }
759 }
760 break;
761 default:
762 assert(0);
763 }
764
765 pipe->transfer_unmap(pipe, pt);
766 }
767
768
769 void
770 pipe_get_tile_ui_format(struct pipe_context *pipe,
771 struct pipe_transfer *pt,
772 uint x, uint y, uint w, uint h,
773 enum pipe_format format,
774 unsigned int *p)
775 {
776 unsigned dst_stride = w * 4;
777 void *packed;
778
779 if (u_clip_tile(x, y, &w, &h, &pt->box)) {
780 return;
781 }
782
783 packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
784 if (!packed) {
785 return;
786 }
787
788 if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
789 assert((x & 1) == 0);
790 }
791
792 pipe_get_tile_raw(pipe, pt, x, y, w, h, packed, 0);
793
794 pipe_tile_raw_to_unsigned(format, packed, w, h, p, dst_stride);
795
796 FREE(packed);
797 }
798
799
800 void
801 pipe_get_tile_i_format(struct pipe_context *pipe,
802 struct pipe_transfer *pt,
803 uint x, uint y, uint w, uint h,
804 enum pipe_format format,
805 int *p)
806 {
807 unsigned dst_stride = w * 4;
808 void *packed;
809
810 if (u_clip_tile(x, y, &w, &h, &pt->box)) {
811 return;
812 }
813
814 packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
815 if (!packed) {
816 return;
817 }
818
819 if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
820 assert((x & 1) == 0);
821 }
822
823 pipe_get_tile_raw(pipe, pt, x, y, w, h, packed, 0);
824
825 pipe_tile_raw_to_signed(format, packed, w, h, p, dst_stride);
826
827 FREE(packed);
828 }