Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / gallium / auxiliary / util / u_linear.c
1
2 #include "pipe/p_debug.h"
3 #include "u_linear.h"
4
5 void
6 pipe_linear_to_tile(size_t src_stride, void *src_ptr,
7 struct pipe_tile_info *t, void *dst_ptr)
8 {
9 int x, y, z;
10 char *ptr;
11 size_t bytes = t->cols * t->block.size;
12
13
14 assert(pipe_linear_check_tile(t));
15
16 /* lets write lineary to the tiled buffer */
17 for (y = 0; y < t->tiles_y; y++) {
18 for (x = 0; x < t->tiles_x; x++) {
19 /* this inner loop could be replace with SSE magic */
20 ptr = (char*)src_ptr + src_stride * t->rows * y + bytes * x;
21 for (z = 0; z < t->rows; z++) {
22 memcpy(dst_ptr, ptr, bytes);
23 dst_ptr += bytes;
24 ptr += src_stride;
25 }
26 }
27 }
28 }
29
30 void pipe_linear_from_tile(struct pipe_tile_info *t, void *src_ptr,
31 size_t dst_stride, void *dst_ptr)
32 {
33 int x, y, z;
34 char *ptr;
35 size_t bytes = t->cols * t->block.size;
36
37 /* lets read lineary from the tiled buffer */
38 for (y = 0; y < t->tiles_y; y++) {
39 for (x = 0; x < t->tiles_x; x++) {
40 /* this inner loop could be replace with SSE magic */
41 ptr = (char*)dst_ptr + dst_stride * t->rows * y + bytes * x;
42 for (z = 0; z < t->rows; z++) {
43 memcpy(ptr, src_ptr, bytes);
44 src_ptr += bytes;
45 ptr += dst_stride;
46 }
47 }
48 }
49 }
50
51 void
52 pipe_linear_fill_info(struct pipe_tile_info *t,
53 struct pipe_format_block *block,
54 unsigned tile_width, unsigned tile_height,
55 unsigned tiles_x, unsigned tiles_y)
56 {
57 t->block = *block;
58
59 t->tile.width = tile_width;
60 t->tile.height = tile_height;
61 t->cols = t->tile.width / t->block.width;
62 t->rows = t->tile.height / t->block.height;
63 t->tile.size = t->cols * t->rows * t->block.size;
64
65 t->tiles_x = tiles_x;
66 t->tiles_y = tiles_y;
67 t->stride = t->cols * t->tiles_x * t->block.size;
68 t->size = t->tiles_x * t->tiles_y * t->tile.size;
69 }