diff options
Diffstat (limited to 'src/sna/sna_render.c')
-rw-r--r-- | src/sna/sna_render.c | 145 |
1 files changed, 102 insertions, 43 deletions
diff --git a/src/sna/sna_render.c b/src/sna/sna_render.c index c534f612..0a2856e3 100644 --- a/src/sna/sna_render.c +++ b/src/sna/sna_render.c @@ -1637,11 +1637,10 @@ sna_render_picture_convert(struct sna *sna, PixmapPtr pixmap, int16_t x, int16_t y, int16_t w, int16_t h, - int16_t dst_x, int16_t dst_y) + int16_t dst_x, int16_t dst_y, + bool fixup_alpha) { - pixman_image_t *src, *dst; BoxRec box; - void *ptr; #if NO_CONVERT return -1; @@ -1691,52 +1690,113 @@ sna_render_picture_convert(struct sna *sna, return 0; } - if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ)) - return 0; + if (fixup_alpha && is_gpu(&pixmap->drawable)) { + ScreenPtr screen = pixmap->drawable.pScreen; + PixmapPtr tmp; + PicturePtr src, dst; + int error; - src = pixman_image_create_bits(picture->format, - pixmap->drawable.width, - pixmap->drawable.height, - pixmap->devPrivate.ptr, - pixmap->devKind); - if (!src) - return 0; + assert(PICT_FORMAT_BPP(picture->format) == pixmap->drawable.bitsPerPixel); + channel->pict_format = PICT_FORMAT(PICT_FORMAT_BPP(picture->format), + PICT_FORMAT_TYPE(picture->format), + PICT_FORMAT_BPP(picture->format) - PIXMAN_FORMAT_DEPTH(picture->format), + PICT_FORMAT_R(picture->format), + PICT_FORMAT_G(picture->format), + PICT_FORMAT_B(picture->format)); - if (PICT_FORMAT_RGB(picture->format) == 0) { - channel->pict_format = PIXMAN_a8; - DBG(("%s: converting to a8 from %08x\n", + DBG(("%s: converting to %08x from %08x using composite alpha-fixup\n", __FUNCTION__, picture->format)); + + tmp = screen->CreatePixmap(screen, w, h, pixmap->drawable.bitsPerPixel, 0); + if (tmp == NULL) + return 0; + + dst = CreatePicture(0, &tmp->drawable, + PictureMatchFormat(screen, + pixmap->drawable.bitsPerPixel, + channel->pict_format), + 0, NULL, serverClient, &error); + if (dst == NULL) { + screen->DestroyPixmap(tmp); + return 0; + } + + src = CreatePicture(0, &pixmap->drawable, + PictureMatchFormat(screen, + pixmap->drawable.depth, + picture->format), + 0, NULL, serverClient, &error); + if (dst == NULL) { + FreePicture(dst, 0); + screen->DestroyPixmap(tmp); + return 0; + } + + ValidatePicture(src); + ValidatePicture(dst); + + sna_composite(PictOpSrc, src, NULL, dst, + box.x1, box.y1, + 0, 0, + 0, 0, + w, h); + FreePicture(dst, 0); + FreePicture(src, 0); + + channel->bo = sna_pixmap_get_bo(tmp); + kgem_bo_reference(channel->bo); + screen->DestroyPixmap(tmp); } else { - channel->pict_format = PIXMAN_a8r8g8b8; - DBG(("%s: converting to a8r8g8b8 from %08x\n", - __FUNCTION__, picture->format)); - } + pixman_image_t *src, *dst; + void *ptr; - channel->bo = kgem_create_buffer_2d(&sna->kgem, - w, h, PIXMAN_FORMAT_BPP(channel->pict_format), - KGEM_BUFFER_WRITE_INPLACE, - &ptr); - if (!channel->bo) { - pixman_image_unref(src); - return 0; - } + if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ)) + return 0; - dst = pixman_image_create_bits(channel->pict_format, - w, h, ptr, channel->bo->pitch); - if (!dst) { - kgem_bo_destroy(&sna->kgem, channel->bo); + src = pixman_image_create_bits(picture->format, + pixmap->drawable.width, + pixmap->drawable.height, + pixmap->devPrivate.ptr, + pixmap->devKind); + if (!src) + return 0; + + if (PICT_FORMAT_RGB(picture->format) == 0) { + channel->pict_format = PIXMAN_a8; + DBG(("%s: converting to a8 from %08x\n", + __FUNCTION__, picture->format)); + } else { + channel->pict_format = PIXMAN_a8r8g8b8; + DBG(("%s: converting to a8r8g8b8 from %08x\n", + __FUNCTION__, picture->format)); + } + + channel->bo = kgem_create_buffer_2d(&sna->kgem, + w, h, PIXMAN_FORMAT_BPP(channel->pict_format), + KGEM_BUFFER_WRITE_INPLACE, + &ptr); + if (!channel->bo) { + pixman_image_unref(src); + return 0; + } + + dst = pixman_image_create_bits(channel->pict_format, + w, h, ptr, channel->bo->pitch); + if (!dst) { + kgem_bo_destroy(&sna->kgem, channel->bo); + pixman_image_unref(src); + return 0; + } + + pixman_image_composite(PictOpSrc, src, NULL, dst, + box.x1, box.y1, + 0, 0, + 0, 0, + w, h); + pixman_image_unref(dst); pixman_image_unref(src); - return 0; } - pixman_image_composite(PictOpSrc, src, NULL, dst, - box.x1, box.y1, - 0, 0, - 0, 0, - w, h); - pixman_image_unref(dst); - pixman_image_unref(src); - channel->width = w; channel->height = h; @@ -1745,11 +1805,10 @@ sna_render_picture_convert(struct sna *sna, channel->offset[0] = x - dst_x - box.x1; channel->offset[1] = y - dst_y - box.y1; - DBG(("%s: offset=(%d, %d), size=(%d, %d) ptr[0]=%08x\n", + DBG(("%s: offset=(%d, %d), size=(%d, %d)\n", __FUNCTION__, channel->offset[0], channel->offset[1], - channel->width, channel->height, - *(uint32_t*)ptr)); + channel->width, channel->height)); return 1; } |