1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2009 VMware, Inc. 4848b8605Smrg * All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17848b8605Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25848b8605Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg/** 29848b8605Smrg * Functions for converting tiled data to linear and vice versa. 30848b8605Smrg */ 31848b8605Smrg 32848b8605Smrg 33848b8605Smrg#ifndef U_LINEAR_H 34848b8605Smrg#define U_LINEAR_H 35848b8605Smrg 36848b8605Smrg#include "pipe/p_compiler.h" 37848b8605Smrg#include "pipe/p_format.h" 38848b8605Smrg 39848b8605Smrgstruct u_linear_format_block 40848b8605Smrg{ 41848b8605Smrg /** Block size in bytes */ 42848b8605Smrg unsigned size; 43848b8605Smrg 44848b8605Smrg /** Block width in pixels */ 45848b8605Smrg unsigned width; 46848b8605Smrg 47848b8605Smrg /** Block height in pixels */ 48848b8605Smrg unsigned height; 49848b8605Smrg}; 50848b8605Smrg 51848b8605Smrg 52848b8605Smrgstruct pipe_tile_info 53848b8605Smrg{ 54848b8605Smrg unsigned size; 55848b8605Smrg unsigned stride; 56848b8605Smrg 57848b8605Smrg /* The number of tiles */ 58848b8605Smrg unsigned tiles_x; 59848b8605Smrg unsigned tiles_y; 60848b8605Smrg 61848b8605Smrg /* size of each tile expressed in blocks */ 62848b8605Smrg unsigned cols; 63848b8605Smrg unsigned rows; 64848b8605Smrg 65848b8605Smrg /* Describe the tile in pixels */ 66848b8605Smrg struct u_linear_format_block tile; 67848b8605Smrg 68848b8605Smrg /* Describe each block within the tile */ 69848b8605Smrg struct u_linear_format_block block; 70848b8605Smrg}; 71848b8605Smrg 72848b8605Smrgvoid pipe_linear_to_tile(size_t src_stride, const void *src_ptr, 73848b8605Smrg struct pipe_tile_info *t, void *dst_ptr); 74848b8605Smrg 75848b8605Smrgvoid pipe_linear_from_tile(struct pipe_tile_info *t, const void *src_ptr, 76848b8605Smrg size_t dst_stride, void *dst_ptr); 77848b8605Smrg 78848b8605Smrg/** 79848b8605Smrg * Convenience function to fillout a pipe_tile_info struct. 80848b8605Smrg * @t info to fill out. 81848b8605Smrg * @block block info about pixel layout 82848b8605Smrg * @tile_width the width of the tile in pixels 83848b8605Smrg * @tile_height the height of the tile in pixels 84848b8605Smrg * @tiles_x number of tiles in x axis 85848b8605Smrg * @tiles_y number of tiles in y axis 86848b8605Smrg */ 87848b8605Smrgvoid pipe_linear_fill_info(struct pipe_tile_info *t, 88848b8605Smrg const struct u_linear_format_block *block, 89848b8605Smrg unsigned tile_width, unsigned tile_height, 90848b8605Smrg unsigned tiles_x, unsigned tiles_y); 91848b8605Smrg 92b8e80941Smrgstatic inline boolean pipe_linear_check_tile(const struct pipe_tile_info *t) 93848b8605Smrg{ 94848b8605Smrg if (t->tile.size != t->block.size * t->cols * t->rows) 95848b8605Smrg return FALSE; 96848b8605Smrg 97848b8605Smrg if (t->stride != t->block.size * t->cols * t->tiles_x) 98848b8605Smrg return FALSE; 99848b8605Smrg 100848b8605Smrg if (t->size < t->stride * t->rows * t->tiles_y) 101848b8605Smrg return FALSE; 102848b8605Smrg 103848b8605Smrg return TRUE; 104848b8605Smrg} 105848b8605Smrg 106848b8605Smrg#endif /* U_LINEAR_H */ 107