/** * Convert a linear image into a tiled image. * \param src_stride source row stride in bytes * \param dst_stride dest row stride in bytes (bytes per row of tiles) */ void lp_linear_to_tiled(const uint8_t *src, uint8_t *dst, unsigned width, unsigned height, enum pipe_format format, unsigned src_stride, unsigned dst_stride) { const unsigned tiles_per_row = dst_stride / BYTES_PER_TILE; unsigned i, j; for (j = 0; j < height; j += TILE_SIZE) { for (i = 0; i < width; i += TILE_SIZE) { unsigned tile_offset = ((j / TILE_SIZE) * tiles_per_row + i / TILE_SIZE); unsigned byte_offset = tile_offset * BYTES_PER_TILE; uint8_t *dst_tile = dst + byte_offset; lp_tile_read_4ub(format, dst_tile, src, src_stride, i, j, TILE_SIZE, TILE_SIZE); } } }
/** * Get a tile from the cache. * \param x, y position of tile, in pixels */ void * lp_get_cached_tile(struct llvmpipe_tile_cache *tc, unsigned x, unsigned y ) { struct llvmpipe_cached_tile *tile = &tc->entries[y/TILE_SIZE][x/TILE_SIZE]; struct pipe_transfer *pt = tc->transfer; assert(tc->surface); assert(tc->transfer); switch(tile->status) { case LP_TILE_STATUS_CLEAR: /* don't get tile from framebuffer, just clear it */ clear_tile(tile, tc->clear_color); tile->status = LP_TILE_STATUS_DEFINED; break; case LP_TILE_STATUS_UNDEFINED: { unsigned w = TILE_SIZE; unsigned h = TILE_SIZE; x &= ~(TILE_SIZE - 1); y &= ~(TILE_SIZE - 1); if (!pipe_clip_tile(x, y, &w, &h, tc->transfer)) lp_tile_read_4ub(pt->format, tile->color, tc->transfer_map, tc->transfer->stride, x, y, w, h); tile->status = LP_TILE_STATUS_DEFINED; break; } case LP_TILE_STATUS_DEFINED: /* nothing to do */ break; } return tile->color; }