gallium: interface cleanups, remove nblocksx/y from pipe_texture and more
[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 u_linear_format_block
39 {
40 /** Block size in bytes */
41 unsigned size;
42
43 /** Block width in pixels */
44 unsigned width;
45
46 /** Block height in pixels */
47 unsigned height;
48 };
49
50
51 struct pipe_tile_info
52 {
53 unsigned size;
54 unsigned stride;
55
56 /* The number of tiles */
57 unsigned tiles_x;
58 unsigned tiles_y;
59
60 /* size of each tile expressed in blocks */
61 unsigned cols;
62 unsigned rows;
63
64 /* Describe the tile in pixels */
65 struct u_linear_format_block tile;
66
67 /* Describe each block within the tile */
68 struct u_linear_format_block block;
69 };
70
71 void pipe_linear_to_tile(size_t src_stride, const void *src_ptr,
72 struct pipe_tile_info *t, void *dst_ptr);
73
74 void pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr,
75 size_t dst_stride, void *dst_ptr);
76
77 /**
78 * Convenience function to fillout a pipe_tile_info struct.
79 * @t info to fill out.
80 * @block block info about pixel layout
81 * @tile_width the width of the tile in pixels
82 * @tile_height the height of the tile in pixels
83 * @tiles_x number of tiles in x axis
84 * @tiles_y number of tiles in y axis
85 */
86 void pipe_linear_fill_info(struct pipe_tile_info *t,
87 const struct u_linear_format_block *block,
88 unsigned tile_width, unsigned tile_height,
89 unsigned tiles_x, unsigned tiles_y);
90
91 static INLINE boolean pipe_linear_check_tile(const struct pipe_tile_info *t)
92 {
93 if (t->tile.size != t->block.size * t->cols * t->rows)
94 return FALSE;
95
96 if (t->stride != t->block.size * t->cols * t->tiles_x)
97 return FALSE;
98
99 if (t->size < t->stride * t->rows * t->tiles_y)
100 return FALSE;
101
102 return TRUE;
103 }
104
105 #endif /* U_LINEAR_H */