sna: Tidy up some recent valgrind complaints with reuse of scratch pixmaps
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
parent
d3a4f5db14
commit
0c12f7cb01
|
|
@ -145,7 +145,7 @@ struct sna_pixmap {
|
||||||
uint8_t mapped :1;
|
uint8_t mapped :1;
|
||||||
uint8_t flush :1;
|
uint8_t flush :1;
|
||||||
uint8_t gpu :1;
|
uint8_t gpu :1;
|
||||||
uint8_t freed :1;
|
uint8_t header :1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sna_glyph {
|
struct sna_glyph {
|
||||||
|
|
|
||||||
|
|
@ -269,11 +269,12 @@ static Bool sna_destroy_private(PixmapPtr pixmap, struct sna_pixmap *priv)
|
||||||
kgem_bo_destroy(&sna->kgem, priv->cpu_bo);
|
kgem_bo_destroy(&sna->kgem, priv->cpu_bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sna->freed_pixmap && priv->freed) {
|
if (!sna->freed_pixmap && priv->header) {
|
||||||
sna->freed_pixmap = pixmap;
|
sna->freed_pixmap = pixmap;
|
||||||
assert(priv->ptr == NULL);
|
assert(priv->ptr == NULL);
|
||||||
priv->gpu_bo = NULL;
|
priv->gpu_bo = NULL;
|
||||||
priv->cpu_bo = NULL;
|
priv->cpu_bo = NULL;
|
||||||
|
priv->mapped = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -370,6 +371,35 @@ static inline void sna_set_pixmap(PixmapPtr pixmap, struct sna_pixmap *sna)
|
||||||
dixSetPrivate(&pixmap->devPrivates, &sna_pixmap_index, sna);
|
dixSetPrivate(&pixmap->devPrivates, &sna_pixmap_index, sna);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sna_pixmap *
|
||||||
|
_sna_pixmap_init(struct sna_pixmap *priv, PixmapPtr pixmap)
|
||||||
|
{
|
||||||
|
list_init(&priv->list);
|
||||||
|
list_init(&priv->inactive);
|
||||||
|
priv->source_count = SOURCE_BIAS;
|
||||||
|
priv->pixmap = pixmap;
|
||||||
|
|
||||||
|
return priv;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct sna_pixmap *
|
||||||
|
_sna_pixmap_reset(PixmapPtr pixmap)
|
||||||
|
{
|
||||||
|
struct sna_pixmap *priv;
|
||||||
|
|
||||||
|
assert(pixmap->drawable.type == DRAWABLE_PIXMAP);
|
||||||
|
assert(pixmap->drawable.class == 0);
|
||||||
|
assert(pixmap->drawable.id == 0);
|
||||||
|
assert(pixmap->drawable.x == 0);
|
||||||
|
assert(pixmap->drawable.y == 0);
|
||||||
|
|
||||||
|
priv = sna_pixmap(pixmap);
|
||||||
|
assert(priv != NULL);
|
||||||
|
|
||||||
|
memset(priv, 0, sizeof(*priv));
|
||||||
|
return _sna_pixmap_init(priv, pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
static struct sna_pixmap *_sna_pixmap_attach(struct sna *sna,
|
static struct sna_pixmap *_sna_pixmap_attach(struct sna *sna,
|
||||||
PixmapPtr pixmap)
|
PixmapPtr pixmap)
|
||||||
{
|
{
|
||||||
|
|
@ -379,12 +409,8 @@ static struct sna_pixmap *_sna_pixmap_attach(struct sna *sna,
|
||||||
if (!priv)
|
if (!priv)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
list_init(&priv->list);
|
|
||||||
list_init(&priv->inactive);
|
|
||||||
priv->pixmap = pixmap;
|
|
||||||
|
|
||||||
sna_set_pixmap(pixmap, priv);
|
sna_set_pixmap(pixmap, priv);
|
||||||
return priv;
|
return _sna_pixmap_init(priv, pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sna_pixmap *sna_pixmap_attach(PixmapPtr pixmap)
|
struct sna_pixmap *sna_pixmap_attach(PixmapPtr pixmap)
|
||||||
|
|
@ -463,15 +489,15 @@ sna_pixmap_create_scratch(ScreenPtr screen,
|
||||||
pixmap = sna->freed_pixmap;
|
pixmap = sna->freed_pixmap;
|
||||||
sna->freed_pixmap = NULL;
|
sna->freed_pixmap = NULL;
|
||||||
|
|
||||||
priv = sna_pixmap(pixmap);
|
pixmap->usage_hint = CREATE_PIXMAP_USAGE_SCRATCH;
|
||||||
memset(priv, 0, sizeof(*priv));
|
pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
|
||||||
list_init(&priv->list);
|
pixmap->refcnt = 1;
|
||||||
list_init(&priv->inactive);
|
|
||||||
priv->pixmap = pixmap;
|
priv = _sna_pixmap_reset(pixmap);
|
||||||
} else {
|
} else {
|
||||||
pixmap = create_pixmap(sna, screen, 0, 0, depth,
|
pixmap = create_pixmap(sna, screen, 0, 0, depth,
|
||||||
CREATE_PIXMAP_USAGE_SCRATCH);
|
CREATE_PIXMAP_USAGE_SCRATCH);
|
||||||
if (!pixmap)
|
if (pixmap == NullPixmap)
|
||||||
return NullPixmap;
|
return NullPixmap;
|
||||||
|
|
||||||
priv = _sna_pixmap_attach(sna, pixmap);
|
priv = _sna_pixmap_attach(sna, pixmap);
|
||||||
|
|
@ -490,12 +516,14 @@ sna_pixmap_create_scratch(ScreenPtr screen,
|
||||||
return NullPixmap;
|
return NullPixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->freed = 1;
|
priv->header = true;
|
||||||
sna_damage_all(&priv->gpu_damage, width, height);
|
sna_damage_all(&priv->gpu_damage, width, height);
|
||||||
|
|
||||||
miModifyPixmapHeader(pixmap,
|
pixmap->drawable.width = width;
|
||||||
width, height, depth, bpp,
|
pixmap->drawable.height = height;
|
||||||
priv->gpu_bo->pitch, NULL);
|
pixmap->drawable.depth = depth;
|
||||||
|
pixmap->drawable.bitsPerPixel = bpp;
|
||||||
|
pixmap->devKind = PixmapBytePad(width, depth);
|
||||||
pixmap->devPrivate.ptr = NULL;
|
pixmap->devPrivate.ptr = NULL;
|
||||||
|
|
||||||
return pixmap;
|
return pixmap;
|
||||||
|
|
@ -506,7 +534,6 @@ static PixmapPtr sna_create_pixmap(ScreenPtr screen,
|
||||||
unsigned int usage)
|
unsigned int usage)
|
||||||
{
|
{
|
||||||
PixmapPtr pixmap;
|
PixmapPtr pixmap;
|
||||||
struct sna_pixmap *priv;
|
|
||||||
int pad, size;
|
int pad, size;
|
||||||
|
|
||||||
DBG(("%s(%d, %d, %d, usage=%x)\n", __FUNCTION__,
|
DBG(("%s(%d, %d, %d, usage=%x)\n", __FUNCTION__,
|
||||||
|
|
@ -538,34 +565,33 @@ static PixmapPtr sna_create_pixmap(ScreenPtr screen,
|
||||||
usage = CREATE_PIXMAP_USAGE_SCRATCH_HEADER;
|
usage = CREATE_PIXMAP_USAGE_SCRATCH_HEADER;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* XXX could use last deferred free? */
|
|
||||||
|
|
||||||
pad = PixmapBytePad(width, depth);
|
pad = PixmapBytePad(width, depth);
|
||||||
size = pad * height;
|
size = pad * height;
|
||||||
if (size < 4096) {
|
if (size <= 4096) {
|
||||||
pixmap = create_pixmap(to_sna_from_screen(screen), screen,
|
pixmap = create_pixmap(to_sna_from_screen(screen), screen,
|
||||||
width, height, depth, usage);
|
width, height, depth, usage);
|
||||||
if (pixmap == NullPixmap)
|
if (pixmap == NullPixmap)
|
||||||
return NullPixmap;
|
return NullPixmap;
|
||||||
|
|
||||||
priv = sna_pixmap_attach(pixmap);
|
sna_pixmap_attach(pixmap);
|
||||||
} else {
|
} else {
|
||||||
pixmap = create_pixmap(to_sna_from_screen(screen), screen,
|
struct sna *sna = to_sna_from_screen(screen);
|
||||||
0, 0, depth, usage);
|
|
||||||
|
pixmap = create_pixmap(sna, screen, 0, 0, depth, usage);
|
||||||
if (pixmap == NullPixmap)
|
if (pixmap == NullPixmap)
|
||||||
return NullPixmap;
|
return NullPixmap;
|
||||||
|
|
||||||
|
if (sna_pixmap_attach(pixmap) == NULL) {
|
||||||
|
free(pixmap);
|
||||||
|
return create_pixmap(sna, screen,
|
||||||
|
width, height, depth,
|
||||||
|
usage);
|
||||||
|
}
|
||||||
|
|
||||||
pixmap->drawable.width = width;
|
pixmap->drawable.width = width;
|
||||||
pixmap->drawable.height = height;
|
pixmap->drawable.height = height;
|
||||||
pixmap->devKind = pad;
|
pixmap->devKind = pad;
|
||||||
pixmap->devPrivate.ptr = NULL;
|
pixmap->devPrivate.ptr = NULL;
|
||||||
|
|
||||||
priv = sna_pixmap_attach(pixmap);
|
|
||||||
if (priv == NULL) {
|
|
||||||
free(pixmap);
|
|
||||||
return create_pixmap(to_sna_from_screen(screen), screen,
|
|
||||||
width, height, depth, usage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pixmap;
|
return pixmap;
|
||||||
|
|
@ -1175,7 +1201,9 @@ sna_pixmap_create_upload(ScreenPtr screen,
|
||||||
pixmap = sna->freed_pixmap;
|
pixmap = sna->freed_pixmap;
|
||||||
sna->freed_pixmap = NULL;
|
sna->freed_pixmap = NULL;
|
||||||
|
|
||||||
priv = sna_pixmap(pixmap);
|
pixmap->usage_hint = CREATE_PIXMAP_USAGE_SCRATCH;
|
||||||
|
pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
|
||||||
|
pixmap->refcnt = 1;
|
||||||
} else {
|
} else {
|
||||||
pixmap = create_pixmap(sna, screen, 0, 0, depth,
|
pixmap = create_pixmap(sna, screen, 0, 0, depth,
|
||||||
CREATE_PIXMAP_USAGE_SCRATCH);
|
CREATE_PIXMAP_USAGE_SCRATCH);
|
||||||
|
|
@ -1187,8 +1215,13 @@ sna_pixmap_create_upload(ScreenPtr screen,
|
||||||
fbDestroyPixmap(pixmap);
|
fbDestroyPixmap(pixmap);
|
||||||
return NullPixmap;
|
return NullPixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sna_set_pixmap(pixmap, priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
priv = _sna_pixmap_reset(pixmap);
|
||||||
|
priv->header = true;
|
||||||
|
|
||||||
priv->gpu_bo = kgem_create_buffer(&sna->kgem,
|
priv->gpu_bo = kgem_create_buffer(&sna->kgem,
|
||||||
pad*height, KGEM_BUFFER_WRITE,
|
pad*height, KGEM_BUFFER_WRITE,
|
||||||
&ptr);
|
&ptr);
|
||||||
|
|
@ -1200,19 +1233,14 @@ sna_pixmap_create_upload(ScreenPtr screen,
|
||||||
|
|
||||||
priv->gpu_bo->pitch = pad;
|
priv->gpu_bo->pitch = pad;
|
||||||
|
|
||||||
priv->source_count = SOURCE_BIAS;
|
pixmap->drawable.width = width;
|
||||||
priv->cpu_bo = NULL;
|
pixmap->drawable.height = height;
|
||||||
priv->cpu_damage = priv->gpu_damage = NULL;
|
pixmap->drawable.depth = depth;
|
||||||
priv->ptr = NULL;
|
pixmap->drawable.bitsPerPixel = bpp;
|
||||||
priv->pinned = 0;
|
pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
|
||||||
priv->freed = 1;
|
pixmap->devKind = pad;
|
||||||
list_init(&priv->list);
|
pixmap->devPrivate.ptr = ptr;
|
||||||
list_init(&priv->inactive);
|
|
||||||
|
|
||||||
priv->pixmap = pixmap;
|
|
||||||
sna_set_pixmap(pixmap, priv);
|
|
||||||
|
|
||||||
miModifyPixmapHeader(pixmap, width, height, depth, bpp, pad, ptr);
|
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue