2
* Copyright (c) 2012-2015 Etnaviv Project
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sub license,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice (including the
12
* next paragraph) shall be included in all copies or substantial portions
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
* DEALINGS IN THE SOFTWARE.
24
* Wladimir J. van der Laan <laanwj@gmail.com>
27
#include "etnaviv_tiling.h"
32
#define TEX_TILE_WIDTH (4)
33
#define TEX_TILE_HEIGHT (4)
34
#define TEX_TILE_WORDS (TEX_TILE_WIDTH * TEX_TILE_HEIGHT)
36
#define DO_TILE(type) \
37
src_stride /= sizeof(type); \
38
dst_stride = (dst_stride * TEX_TILE_HEIGHT) / sizeof(type); \
39
for (unsigned srcy = 0; srcy < height; ++srcy) { \
40
unsigned dsty = basey + srcy; \
41
unsigned ty = (dsty / TEX_TILE_HEIGHT) * dst_stride + \
42
(dsty % TEX_TILE_HEIGHT) * TEX_TILE_WIDTH; \
43
for (unsigned srcx = 0; srcx < width; ++srcx) { \
44
unsigned dstx = basex + srcx; \
45
((type *)dest)[ty + (dstx / TEX_TILE_WIDTH) * TEX_TILE_WORDS + \
46
(dstx % TEX_TILE_WIDTH)] = \
47
((type *)src)[srcy * src_stride + srcx]; \
51
#define DO_UNTILE(type) \
52
src_stride = (src_stride * TEX_TILE_HEIGHT) / sizeof(type); \
53
dst_stride /= sizeof(type); \
54
for (unsigned dsty = 0; dsty < height; ++dsty) { \
55
unsigned srcy = basey + dsty; \
56
unsigned sy = (srcy / TEX_TILE_HEIGHT) * src_stride + \
57
(srcy % TEX_TILE_HEIGHT) * TEX_TILE_WIDTH; \
58
for (unsigned dstx = 0; dstx < width; ++dstx) { \
59
unsigned srcx = basex + dstx; \
60
((type *)dest)[dsty * dst_stride + dstx] = \
61
((type *)src)[sy + (srcx / TEX_TILE_WIDTH) * TEX_TILE_WORDS + \
62
(srcx % TEX_TILE_WIDTH)]; \
67
etna_texture_tile(void *dest, void *src, unsigned basex, unsigned basey,
68
unsigned dst_stride, unsigned width, unsigned height,
69
unsigned src_stride, unsigned elmtsize)
73
} else if (elmtsize == 4) {
75
} else if (elmtsize == 2) {
77
} else if (elmtsize == 1) {
80
printf("etna_texture_tile: unhandled element size %i\n", elmtsize);
85
etna_texture_untile(void *dest, void *src, unsigned basex, unsigned basey,
86
unsigned src_stride, unsigned width, unsigned height,
87
unsigned dst_stride, unsigned elmtsize)
91
} else if (elmtsize == 4) {
93
} else if (elmtsize == 2) {
95
} else if (elmtsize == 1) {
98
printf("etna_texture_tile: unhandled element size %i\n", elmtsize);