1c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul/**************************************************************************
2c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul *
3c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * Copyright 2009 VMware, Inc.
4c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * All Rights Reserved.
5c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul *
6c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * Permission is hereby granted, free of charge, to any person obtaining a
7c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * copy of this software and associated documentation files (the
8c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * "Software"), to deal in the Software without restriction, including
9c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * without limitation the rights to use, copy, modify, merge, publish,
10c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * distribute, sub license, and/or sell copies of the Software, and to
11c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * permit persons to whom the Software is furnished to do so, subject to
12c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * the following conditions:
13c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul *
14c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * The above copyright notice and this permission notice (including the
15c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * next paragraph) shall be included in all copies or substantial portions
16c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * of the Software.
17c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul *
18c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul *
26c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul **************************************************************************/
27c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul
28c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul/**
29c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul * Functions for converting tiled data to linear and vice versa.
30c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul */
31c5a97eda32d37de7d1154288bf4298dff3542551Brian Paul
32f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
33f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz#ifndef U_LINEAR_H
34f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz#define U_LINEAR_H
35f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
3623120b8d305cc5163e75c551fb46327fb9b84d85Vinson Lee#include "pipe/p_compiler.h"
37f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz#include "pipe/p_format.h"
386b06a6b929aa742f92653728254255f1867d6210Brian Paul
39ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheideggerstruct u_linear_format_block
40ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger{
41ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger   /** Block size in bytes */
42ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger   unsigned size;
43ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger
44ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger   /** Block width in pixels */
45ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger   unsigned width;
46ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger
47ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger   /** Block height in pixels */
48ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger   unsigned height;
49ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger};
50ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger
51ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger
52f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantzstruct pipe_tile_info
53f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz{
54f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   unsigned size;
55f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   unsigned stride;
56f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
57f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   /* The number of tiles */
58f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   unsigned tiles_x;
59f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   unsigned tiles_y;
60f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
61f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   /* size of each tile expressed in blocks */
62f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   unsigned cols;
63f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   unsigned rows;
64f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
65f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   /* Describe the tile in pixels */
66ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger   struct u_linear_format_block tile;
67f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
68f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   /* Describe each block within the tile */
69ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger   struct u_linear_format_block block;
70f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz};
71f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
726b06a6b929aa742f92653728254255f1867d6210Brian Paulvoid pipe_linear_to_tile(size_t src_stride, const void *src_ptr,
73f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz			 struct pipe_tile_info *t, void  *dst_ptr);
74f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
756b06a6b929aa742f92653728254255f1867d6210Brian Paulvoid pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr,
76f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz			   size_t dst_stride, void *dst_ptr);
77f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
78f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz/**
79f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz * Convenience function to fillout a pipe_tile_info struct.
80f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz * @t info to fill out.
81f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz * @block block info about pixel layout
82f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz * @tile_width the width of the tile in pixels
83f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz * @tile_height the height of the tile in pixels
84f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz * @tiles_x number of tiles in x axis
85f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz * @tiles_y number of tiles in y axis
86f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz */
87f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantzvoid pipe_linear_fill_info(struct pipe_tile_info *t,
88ac400ffce62be47fc77e8d10cabcd39b92b6c627Roland Scheidegger			   const struct u_linear_format_block *block,
89f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz			   unsigned tile_width, unsigned tile_height,
90f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz			   unsigned tiles_x, unsigned tiles_y);
91f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
926b06a6b929aa742f92653728254255f1867d6210Brian Paulstatic INLINE boolean pipe_linear_check_tile(const struct pipe_tile_info *t)
93f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz{
94f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   if (t->tile.size != t->block.size * t->cols * t->rows)
95f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz      return FALSE;
96f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
97f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   if (t->stride != t->block.size * t->cols * t->tiles_x)
98f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz      return FALSE;
99f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
100f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   if (t->size < t->stride * t->rows * t->tiles_y)
101f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz      return FALSE;
102f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
103f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz   return TRUE;
104f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz}
105f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz
106f0e3366b0860047632bec59c8ee815670cfb2d25Jakob Bornecrantz#endif /* U_LINEAR_H */
107