Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / auxiliary / util / u_linear.h
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
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 VMWARE 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 * Functions for converting tiled data to linear and vice versa.
30 */
31
32
33 #ifndef U_LINEAR_H
34 #define U_LINEAR_H
35
36 #include "pipe/p_format.h"
37
38 struct pipe_tile_info
39 {
40 unsigned size;
41 unsigned stride;
42
43 /* The number of tiles */
44 unsigned tiles_x;
45 unsigned tiles_y;
46
47 /* size of each tile expressed in blocks */
48 unsigned cols;
49 unsigned rows;
50
51 /* Describe the tile in pixels */
52 struct pipe_format_block tile;
53
54 /* Describe each block within the tile */
55 struct pipe_format_block block;
56 };
57
58 void pipe_linear_to_tile(size_t src_stride, const void *src_ptr,
59 struct pipe_tile_info *t, void *dst_ptr);
60
61 void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr,
62 size_t dst_stride, void *dst_ptr);
63
64 /**
65 * Convenience function to fillout a pipe_tile_info struct.
66 * @t info to fill out.
67 * @block block info about pixel layout
68 * @tile_width the width of the tile in pixels
69 * @tile_height the height of the tile in pixels
70 * @tiles_x number of tiles in x axis
71 * @tiles_y number of tiles in y axis
72 */
73 void pipe_linear_fill_info(struct pipe_tile_info *t,
74 const struct pipe_format_block *block,
75 unsigned tile_width, unsigned tile_height,
76 unsigned tiles_x, unsigned tiles_y);
77
78 static INLINE boolean pipe_linear_check_tile(const struct pipe_tile_info *t)
79 {
80 if (t->tile.size != t->block.size * t->cols * t->rows)
81 return FALSE;
82
83 if (t->stride != t->block.size * t->cols * t->tiles_x)
84 return FALSE;
85
86 if (t->size < t->stride * t->rows * t->tiles_y)
87 return FALSE;
88
89 return TRUE;
90 }
91
92 #endif /* U_LINEAR_H */