optimize to avoid using malloc/free for blit_ctxt; reset filter and transform of pixman images

This commit is contained in:
Vincent Wei
2021-06-03 18:33:31 +08:00
parent 2efb66cae0
commit cac16f1324
10 changed files with 70 additions and 110 deletions
+4 -8
View File
@@ -216,7 +216,10 @@ typedef struct GAL_Surface {
#ifdef _MGUSE_PIXMAN
pixman_image_t *pix_img; /* The pixman image object for this surface */
void *blit_ctxt; /* blitting context */
pixman_image_t *msk_img;
uint16_t pix_op;
uint16_t pix_filter;
uint32_t pix_alpha_bits;
#endif
#if IS_COMPOSITING_SCHEMA
@@ -818,13 +821,6 @@ static inline BOOL GAL_CheckPixmanFormats (GAL_Surface *src, GAL_Surface *dst)
return FALSE;
}
typedef struct GAL_BlittingContext {
uint16_t op;
uint16_t filter;
uint32_t alpha_bits;
pixman_image_t *msk_img;
} GAL_BlittingContext;
int GAL_SetupBlitting (GAL_Surface *src, GAL_Surface *dst, DWORD ops);
int GAL_CleanupBlitting (GAL_Surface *src, GAL_Surface *dst);
+1 -1
View File
@@ -1303,7 +1303,7 @@ static void transit_to_layer (CompositorCtxt* ctxt, MG_Layer* to_layer)
}
}
_DBG_PRINTF ("Average time to composite the layers: %u (times: %u)\n", total_time_ms / total_times, total_times);
_DBG_PRINTF ("Average time to composite the layers: %ums (times: %u)\n", total_time_ms / total_times, total_times);
}
CompositorOps __mg_fallback_compositor = {
+21 -33
View File
@@ -332,39 +332,37 @@ int GAL_CalculateBlit(GAL_Surface *surface)
int GAL_SetupBlitting (GAL_Surface *src, GAL_Surface *dst, DWORD ops)
{
if (GAL_CheckPixmanFormats (src, dst)) {
GAL_BlittingContext* ctxt;
src->blit_ctxt = malloc (sizeof (GAL_BlittingContext));
if (src->blit_ctxt == NULL)
return -1;
ctxt = src->blit_ctxt;
if ((src->flags & GAL_SRCALPHA) && src->format->alpha != GAL_ALPHA_OPAQUE) {
memset (&ctxt->alpha_bits, src->format->alpha, sizeof(uint32_t));
ctxt->msk_img = pixman_image_create_bits_no_clear (PIXMAN_a8, 1, 1,
&ctxt->alpha_bits, 4);
if (ctxt->msk_img)
pixman_image_set_repeat (ctxt->msk_img, PIXMAN_REPEAT_NORMAL);
memset (&src->pix_alpha_bits, src->format->alpha, sizeof(uint32_t));
src->msk_img = pixman_image_create_bits_no_clear (PIXMAN_a8, 1, 1,
&src->pix_alpha_bits, 4);
if (src->msk_img)
pixman_image_set_repeat (src->msk_img, PIXMAN_REPEAT_NORMAL);
}
else
ctxt->msk_img = NULL;
src->msk_img = NULL;
ops &= COLOR_BLEND_FLAGS_MASK;
if (ops == COLOR_BLEND_LEGACY) {
if ((src->flags & GAL_SRCPIXELALPHA) && src->format->Amask && src != dst) {
ctxt->op = PIXMAN_OP_OVER;
src->pix_op = PIXMAN_OP_OVER;
}
else {
ctxt->op = PIXMAN_OP_SRC;
src->pix_op = PIXMAN_OP_SRC;
}
}
else {
ctxt->op = ops;
src->pix_op = ops;
}
if (ctxt->op > PIXMAN_OP_HSL_LUMINOSITY ||
ctxt->op < PIXMAN_OP_CLEAR) {
ctxt->op = PIXMAN_OP_SRC;
if (src->pix_op > PIXMAN_OP_HSL_LUMINOSITY ||
src->pix_op < PIXMAN_OP_CLEAR) {
src->pix_op = PIXMAN_OP_SRC;
}
/* reset transform and filter */
pixman_image_set_transform (src->pix_img, NULL);
pixman_image_set_filter (src->pix_img, PIXMAN_FILTER_NEAREST, NULL, 0);
}
return 0;
@@ -372,12 +370,9 @@ int GAL_SetupBlitting (GAL_Surface *src, GAL_Surface *dst, DWORD ops)
int GAL_CleanupBlitting (GAL_Surface *src, GAL_Surface *dst)
{
if (src->blit_ctxt) {
GAL_BlittingContext* ctxt = src->blit_ctxt;
if (ctxt->msk_img)
pixman_image_unref (ctxt->msk_img);
free (src->blit_ctxt);
src->blit_ctxt = NULL;
if (src->msk_img) {
pixman_image_unref (src->msk_img);
src->msk_img = NULL;
}
return 0;
@@ -390,15 +385,8 @@ static int GAL_PixmanBlit (struct GAL_Surface *src, GAL_Rect *srcrect,
pixman_image_t *msk_img;
pixman_op_t op;
if (src->blit_ctxt) {
GAL_BlittingContext* ctxt = src->blit_ctxt;
msk_img = ctxt->msk_img;
op = (pixman_op_t)ctxt->op;
}
else {
msk_img = NULL;
op = PIXMAN_OP_SRC;
}
msk_img = src->msk_img;
op = (pixman_op_t)src->pix_op;
_DBG_PRINTF ("srcrect: %d, %d, %dx%d; dstrect: %d, %d, %dx%d\n",
srcrect->x, srcrect->y, srcrect->w, srcrect->h,
+5 -12
View File
@@ -1524,12 +1524,12 @@ GAL_loblit GAL_CalculateBlitN(GAL_Surface *surface, int blit_index)
}
} else {
/* Now the meat, choose the blitter we want */
int a_need = 0;
if(dstfmt->Amask)
int a_need = 0;
if (dstfmt->Amask)
a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
table = normal_blit[srcfmt->BytesPerPixel-1];
for ( which=0; table[which].srcR; ++which ) {
if ( srcfmt->Rmask == table[which].srcR &&
for (which=0; table[which].srcR; ++which) {
if (srcfmt->Rmask == table[which].srcR &&
srcfmt->Gmask == table[which].srcG &&
srcfmt->Bmask == table[which].srcB &&
dstfmt->BytesPerPixel == table[which].dstbpp &&
@@ -1538,7 +1538,7 @@ GAL_loblit GAL_CalculateBlitN(GAL_Surface *surface, int blit_index)
dstfmt->Bmask == table[which].dstB &&
(a_need & table[which].alpha) == a_need &&
(CPU_Flags()&table[which].cpu_flags) ==
table[which].cpu_flags )
table[which].cpu_flags)
break;
}
sdata->aux_data = table[which].aux_data;
@@ -1547,13 +1547,6 @@ GAL_loblit GAL_CalculateBlitN(GAL_Surface *surface, int blit_index)
blitfun = BlitNtoNCopyAlpha;
}
#ifdef DEBUG_ASM
if ( (blitfun == GAL_BlitNtoN) || (blitfun == GAL_BlitNto1) )
fprintf(stderr, "Using C blit\n");
else
fprintf(stderr, "Using optimized C blit\n");
#endif /* DEBUG_ASM */
return(blitfun);
}
+1 -1
View File
@@ -796,7 +796,7 @@ static GAL_Surface* create_surface_from_buffer (_THIS,
surface->pixels_off = 0;
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
#if IS_COMPOSITING_SCHEMA
surface->shared_header = NULL;
+25 -44
View File
@@ -273,44 +273,38 @@ int GAL_SetupStretchBlit (GAL_Surface *src, GAL_Rect *srcrect,
double rotation;
pixman_f_transform_t ftransform;
pixman_transform_t transform;
GAL_BlittingContext* ctxt;
src->blit_ctxt = malloc (sizeof (GAL_BlittingContext));
if (src->blit_ctxt == NULL)
return -1;
ctxt = src->blit_ctxt;
if ((src->flags & GAL_SRCALPHA) && src->format->alpha != GAL_ALPHA_OPAQUE) {
memset (&ctxt->alpha_bits, src->format->alpha, sizeof(uint32_t));
ctxt->msk_img = pixman_image_create_bits_no_clear (PIXMAN_a8, 1, 1,
&ctxt->alpha_bits, 4);
if (ctxt->msk_img)
pixman_image_set_repeat (ctxt->msk_img, PIXMAN_REPEAT_NORMAL);
memset (&src->pix_alpha_bits, src->format->alpha, sizeof(uint32_t));
src->msk_img = pixman_image_create_bits_no_clear (PIXMAN_a8, 1, 1,
&src->pix_alpha_bits, 4);
if (src->msk_img)
pixman_image_set_repeat (src->msk_img, PIXMAN_REPEAT_NORMAL);
}
else
ctxt->msk_img = NULL;
src->msk_img = NULL;
ctxt->filter = ops >> SCALING_FILTER_SHIFT;
if (ctxt->filter > PIXMAN_FILTER_CONVOLUTION) {
ctxt->filter = PIXMAN_FILTER_FAST;
src->pix_filter = ops >> SCALING_FILTER_SHIFT;
if (src->pix_filter > PIXMAN_FILTER_CONVOLUTION) {
src->pix_filter = PIXMAN_FILTER_FAST;
}
ops &= COLOR_BLEND_FLAGS_MASK;
if (ops == COLOR_BLEND_LEGACY) {
if ((src->flags & GAL_SRCPIXELALPHA) && src->format->Amask && src != dst) {
ctxt->op = PIXMAN_OP_OVER;
src->pix_op = PIXMAN_OP_OVER;
}
else {
ctxt->op = PIXMAN_OP_SRC;
src->pix_op = PIXMAN_OP_SRC;
}
}
else {
ctxt->op = ops;
src->pix_op = ops;
}
if (ctxt->op > PIXMAN_OP_HSL_LUMINOSITY ||
ctxt->op < PIXMAN_OP_CLEAR) {
ctxt->op = PIXMAN_OP_SRC;
if (src->pix_op > PIXMAN_OP_HSL_LUMINOSITY ||
src->pix_op < PIXMAN_OP_CLEAR) {
src->pix_op = PIXMAN_OP_SRC;
}
pixman_f_transform_init_identity (&ftransform);
@@ -350,7 +344,7 @@ int GAL_SetupStretchBlit (GAL_Surface *src, GAL_Rect *srcrect,
pixman_image_set_filter (src_img, (pixman_filter_t)filter, NULL, 0);
}
#else
pixman_image_set_filter (src->pix_img, (pixman_filter_t)ctxt->filter, NULL, 0);
pixman_image_set_filter (src->pix_img, (pixman_filter_t)src->pix_filter, NULL, 0);
#endif
}
@@ -359,21 +353,15 @@ int GAL_SetupStretchBlit (GAL_Surface *src, GAL_Rect *srcrect,
int GAL_CleanupStretchBlit (GAL_Surface *src, GAL_Surface *dst)
{
if (src->blit_ctxt) {
pixman_transform_t transform;
GAL_BlittingContext* ctxt = src->blit_ctxt;
if (ctxt->msk_img)
pixman_image_unref (ctxt->msk_img);
free (src->blit_ctxt);
src->blit_ctxt = NULL;
pixman_transform_init_identity (&transform);
pixman_image_set_transform (src->pix_img, &transform);
pixman_image_set_filter (src->pix_img, PIXMAN_FILTER_FAST, NULL, 0);
pixman_image_set_clip_region32 (dst->pix_img, NULL);
if (src->msk_img) {
pixman_image_unref (src->msk_img);
src->msk_img = NULL;
}
pixman_image_set_transform (src->pix_img, NULL);
pixman_image_set_filter (src->pix_img, PIXMAN_FILTER_NEAREST, NULL, 0);
pixman_image_set_clip_region32 (dst->pix_img, NULL);
return 0;
}
@@ -390,15 +378,8 @@ int GAL_StretchBlt (GAL_Surface *src, GAL_Rect *srcrect,
return GAL_StretchBltLegacy (src, srcrect, dst, dstrect,
ops & COLOR_BLEND_FLAGS_MASK);
if (src->blit_ctxt) {
GAL_BlittingContext* ctxt = src->blit_ctxt;
msk_img = ctxt->msk_img;
op = (pixman_op_t)ctxt->op;
}
else {
msk_img = NULL;
op = PIXMAN_OP_SRC;
}
msk_img = src->msk_img;
op = (pixman_op_t)src->pix_op;
_DBG_PRINTF ("srcrect: %d,%d, %dx%d; dstrect: %d,%d, %dx%d; cliprect: %d,%d, %dx%d\n",
srcrect->x, srcrect->y, srcrect->w, srcrect->h,
+1 -1
View File
@@ -105,7 +105,7 @@ GAL_Surface * GAL_CreateCursorSurface (GAL_VideoDevice *video,
surface->format_version = 0;
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
surface->shared_header = NULL;
surface->dirty_info = NULL;
+5 -5
View File
@@ -138,7 +138,7 @@ GAL_Surface * GAL_CreateSharedRGBSurface (GAL_VideoDevice *video,
surface->format_version = 0;
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
surface->shared_header = NULL;
surface->dirty_info = NULL;
@@ -278,7 +278,7 @@ error:
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
surface->shared_header = NULL;
surface->dirty_info = NULL;
@@ -328,7 +328,7 @@ void GAL_FreeSharedSurfaceData (GAL_Surface *surface)
surface->pixels = NULL;
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
surface->shared_header = NULL;
surface->dirty_info = NULL;
@@ -424,7 +424,7 @@ GAL_Surface * GAL_AttachSharedRGBSurface (int fd, size_t map_size,
surface->format_version = 0;
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
GAL_SetClipRect (surface, NULL);
@@ -481,7 +481,7 @@ void GAL_DettachSharedSurfaceData (GAL_Surface *surface)
surface->pixels = NULL;
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
surface->shared_header = NULL;
surface->dirty_info = NULL;
+6 -4
View File
@@ -144,7 +144,7 @@ GAL_Surface * GAL_CreateRGBSurface (Uint32 flags,
surface->format_version = 0;
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
#if IS_COMPOSITING_SCHEMA
surface->shared_header = NULL;
@@ -1870,13 +1870,15 @@ void GAL_FreeSurface (GAL_Surface *surface)
#ifdef _MGUSE_PIXMAN
if (surface->pix_img) {
_WRN_PRINTF ("There is not cleaned up blitting pixel image: %p\n", surface->pix_img);
pixman_image_unref (surface->pix_img);
surface->pix_img = NULL;
}
if (surface->blit_ctxt) {
_WRN_PRINTF ("There is not cleaned up blitting context: %p\n", surface->blit_ctxt);
if (surface->msk_img) {
_WRN_PRINTF ("There is not cleaned up blitting mask image: %p\n", surface->msk_img);
pixman_image_unref (surface->msk_img);
surface->msk_img = NULL;
}
#endif
+1 -1
View File
@@ -1257,7 +1257,7 @@ static GAL_Surface *Slave_CreateSurface (GAL_VideoDevice *this,
surface->format_version = 0;
#ifdef _MGUSE_PIXMAN
surface->pix_img = NULL;
surface->blit_ctxt = NULL;
surface->msk_img = NULL;
#endif
#if IS_COMPOSITING_SCHEMA
surface->shared_header = NULL;