#include "util/u_memory.h"
#include "util/u_math.h"
#include "util/u_tile.h"
+#include "util/u_rect.h"
#include "lp_context.h"
#include "lp_surface.h"
#include "lp_texture.h"
/**
- * Set pixels in a tile to the given clear color/value, float.
+ * Set a tile to a solid color.
*/
static void
-clear_tile_rgba(struct llvmpipe_cached_tile *tile,
- enum pipe_format format,
- const float clear_value[4])
+clear_tile(struct llvmpipe_cached_tile *tile,
+ uint8_t clear_color[4])
{
- if (clear_value[0] == 0.0 &&
- clear_value[1] == 0.0 &&
- clear_value[2] == 0.0 &&
- clear_value[3] == 0.0) {
- memset(tile->data.color, 0, sizeof(tile->data.color));
+ if (clear_color[0] == clear_color[1] &&
+ clear_color[1] == clear_color[2] &&
+ clear_color[2] == clear_color[3]) {
+ memset(tile->color, clear_color[0], TILE_SIZE * TILE_SIZE * 4);
}
else {
- uint8_t c[4];
- uint x, y, i;
- for (i = 0; i < 4; ++i)
- c[i] = float_to_ubyte(clear_value[i]);
+ uint x, y, chan;
for (y = 0; y < TILE_SIZE; y++)
for (x = 0; x < TILE_SIZE; x++)
- for (i = 0; i < 4; ++i)
- TILE_PIXEL(tile->data.color, x, y, i) = c[i];
- }
-}
-
-
-/**
- * Set a tile to a solid value/color.
- */
-static void
-clear_tile(struct llvmpipe_cached_tile *tile,
- enum pipe_format format,
- uint clear_value)
-{
- uint i, j;
-
- if (clear_value == 0) {
- memset(tile->data.any, 0, 4 * TILE_SIZE * TILE_SIZE);
- }
- else {
- for (i = 0; i < TILE_SIZE; i++) {
- for (j = 0; j < TILE_SIZE; j++) {
- tile->data.color32[i][j] = clear_value;
- }
- }
+ for (chan = 0; chan < 4; ++chan)
+ TILE_PIXEL(tile->color, x, y, chan) = clear_color[chan];
}
}
lp_tile_cache_flush_clear(struct llvmpipe_tile_cache *tc)
{
struct pipe_transfer *pt = tc->transfer;
+ struct pipe_screen *screen = pt->texture->screen;
const uint w = tc->transfer->width;
const uint h = tc->transfer->height;
uint x, y;
uint numCleared = 0;
- /* clear the scratch tile to the clear value */
- clear_tile(&tc->tile, pt->format, tc->clear_val);
-
/* push the tile to all positions marked as clear */
for (y = 0; y < h; y += TILE_SIZE) {
for (x = 0; x < w; x += TILE_SIZE) {
union tile_address addr = tile_address(x, y, 0, 0, 0);
if (is_clear_flag_set(tc->clear_flags, addr)) {
- pipe_put_tile_raw(pt,
- x, y, TILE_SIZE, TILE_SIZE,
- tc->tile.data.color32, 0/*STRIDE*/);
+ unsigned tw = TILE_SIZE;
+ unsigned th = TILE_SIZE;
+ void *dst;
+
+ if (pipe_clip_tile(x, y, &tw, &th, pt))
+ continue;
+
+ dst = screen->transfer_map(screen, pt);
+ assert(dst);
+ if(!dst)
+ continue;
+
+ pipe_fill_rect(dst, &pt->block, pt->stride,
+ x, y, tw, th,
+ tc->clear_val);
/* do this? */
clear_clear_flag(tc->clear_flags, addr);
lp_put_tile_rgba_soa(pt,
tile->addr.bits.x * TILE_SIZE,
tile->addr.bits.y * TILE_SIZE,
- tile->data.color);
+ tile->color);
tile->addr.bits.invalid = 1; /* mark as empty */
inuse++;
}
lp_put_tile_rgba_soa(pt,
tile->addr.bits.x * TILE_SIZE,
tile->addr.bits.y * TILE_SIZE,
- tile->data.color);
+ tile->color);
}
tile->addr = addr;
if (is_clear_flag_set(tc->clear_flags, addr)) {
/* don't get tile from framebuffer, just clear it */
- clear_tile_rgba(tile, pt->format, tc->clear_color);
+ clear_tile(tile, tc->clear_color);
clear_clear_flag(tc->clear_flags, addr);
}
else {
lp_get_tile_rgba_soa(pt,
tile->addr.bits.x * TILE_SIZE,
tile->addr.bits.y * TILE_SIZE,
- tile->data.color);
+ tile->color);
}
}
tc->last_tile = tile;
- return tile->data.color;
+ return tile->color;
}
lp_tile_cache_clear(struct llvmpipe_tile_cache *tc, const float *rgba,
uint clearValue)
{
+ unsigned chan;
uint pos;
- tc->clear_color[0] = rgba[0];
- tc->clear_color[1] = rgba[1];
- tc->clear_color[2] = rgba[2];
- tc->clear_color[3] = rgba[3];
+ for(chan = 0; chan < 4; ++chan)
+ tc->clear_color[chan] = float_to_ubyte(rgba[chan]);
tc->clear_val = clearValue;
struct llvmpipe_cached_tile
{
union tile_address addr;
- union {
-
- /** color in SOA format */
- uint8_t ALIGN16_ATTRIB color[TILE_SIZE*TILE_SIZE*NUM_CHANNELS];
-
- uint color32[TILE_SIZE][TILE_SIZE];
- ubyte any[1];
- } data;
+ /** color in SOA format */
+ uint8_t ALIGN16_ATTRIB color[TILE_SIZE*TILE_SIZE*NUM_CHANNELS];
};
#define NUM_ENTRIES 50
struct llvmpipe_cached_tile entries[NUM_ENTRIES];
uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32];
- float clear_color[4]; /**< for color bufs */
+ uint8_t clear_color[4]; /**< for color bufs */
uint clear_val; /**< for z+stencil, or packed color clear value */
struct pipe_transfer *tex_trans;
void *tex_trans_map;
int tex_face, tex_level, tex_z;
- struct llvmpipe_cached_tile tile; /**< scratch tile for clears */
-
struct llvmpipe_cached_tile *last_tile; /**< most recently retrieved tile */
};
union tile_address addr = tile_address( x, y, 0, 0, 0 );
if (tc->last_tile->addr.value == addr.value)
- return &tc->last_tile->data.color;
+ return &tc->last_tile->color;
return lp_find_cached_tile( tc, addr );
}