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