From 035d55b64a22b761ad0d0cfb21b90c84497044ec Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 16 Mar 2006 00:31:12 +0000 Subject: Hack to make photo-to-photo copies cheaper in the common case of no alpha --- ChangeLog | 8 ++++++++ generic/tkImgPhoto.c | 29 +++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index c1e594b..137766a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-03-16 Donal K. Fellows + + * generic/tkImgPhoto.c (ImgPhotoCmd, Tk_PhotoPutBlock) + (Tk_PhotoPutZoomedBlock): Added hack to detect copying of a photo with + a simple alpha channel and skip calling ToggleComplexAlphaIfNeeded. + This should speed up many photo-to-photo copies, keeping the cost of + the alpha channel down. + 2006-03-15 Donal K. Fellows * generic/tkImgPhoto.c (Tk_PhotoPutBlock, Tk_PhotoPutZoomedBlock): Try diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c index 62c2192..83f5237 100644 --- a/generic/tkImgPhoto.c +++ b/generic/tkImgPhoto.c @@ -17,7 +17,7 @@ * Department of Computer Science, * Australian National University. * - * RCS: @(#) $Id: tkImgPhoto.c,v 1.61 2006/03/15 23:20:27 dkf Exp $ + * RCS: @(#) $Id: tkImgPhoto.c,v 1.62 2006/03/16 00:31:13 dkf Exp $ */ #include "tkInt.h" @@ -186,6 +186,13 @@ typedef struct PhotoMaster { #define COMPLEX_ALPHA 4 /* + * Flag to OR with the compositing rule to indicate that the source, despite + * having an alpha channel, has simple alpha. + */ + +#define SOURCE_IS_SIMPLE_ALPHA_PHOTO 0x10000000 + +/* * The following data structure represents all of the instances of a photo * image in windows on a given screen that are using the same colormap. */ @@ -822,6 +829,15 @@ ImgPhotoCmd( } /* + * Hack to pass through the message that the place we're coming from + * has a simple alpha channel. + */ + + if (!(((PhotoMaster *) srcHandle)->flags & COMPLEX_ALPHA)) { + options.compositingRule |= SOURCE_IS_SIMPLE_ALPHA_PHOTO; + } + + /* * Fill in default values for unspecified parameters. */ @@ -4341,9 +4357,11 @@ Tk_PhotoPutBlock( unsigned char *srcPtr, *srcLinePtr; unsigned char *destPtr, *destLinePtr; int pitch; + int sourceIsSimplePhoto = compRule & SOURCE_IS_SIMPLE_ALPHA_PHOTO; XRectangle rect; masterPtr = (PhotoMaster *) handle; + compRule &= ~SOURCE_IS_SIMPLE_ALPHA_PHOTO; if ((masterPtr->userWidth != 0) && ((x + width) > masterPtr->userWidth)) { width = masterPtr->userWidth - x; @@ -4395,6 +4413,7 @@ Tk_PhotoPutBlock( alphaOffset = blockPtr->offset[3]; if ((alphaOffset >= blockPtr->pixelSize) || (alphaOffset < 0)) { alphaOffset = 0; + sourceIsSimplePhoto = 1; } else { alphaOffset -= blockPtr->offset[0]; } @@ -4600,7 +4619,7 @@ Tk_PhotoPutBlock( * Check if display code needs alpha blending... */ - if (alphaOffset != 0 || masterPtr->flags & COMPLEX_ALPHA) { + if (!sourceIsSimplePhoto || masterPtr->flags & COMPLEX_ALPHA) { /* * Note that we skip in the single pixel case if we can. This speeds * up code that builds up large simple-alpha images by single pixels, @@ -4684,7 +4703,7 @@ Tk_PhotoPutZoomedBlock( unsigned char *destPtr, *destLinePtr; int pitch; int xRepeat, yRepeat; - int blockXSkip, blockYSkip; + int blockXSkip, blockYSkip, sourceIsSimplePhoto; XRectangle rect; if (zoomX==1 && zoomY==1 && subsampleX==1 && subsampleY==1) { @@ -4692,6 +4711,7 @@ Tk_PhotoPutZoomedBlock( compRule); } + sourceIsSimplePhoto = compRule & SOURCE_IS_SIMPLE_ALPHA_PHOTO; masterPtr = (PhotoMaster *) handle; if (zoomX <= 0 || zoomY <= 0) { @@ -4746,6 +4766,7 @@ Tk_PhotoPutZoomedBlock( alphaOffset = blockPtr->offset[3]; if ((alphaOffset >= blockPtr->pixelSize) || (alphaOffset < 0)) { alphaOffset = 0; + sourceIsSimplePhoto = 1; } else { alphaOffset -= blockPtr->offset[0]; } @@ -4895,7 +4916,7 @@ Tk_PhotoPutZoomedBlock( * Check if display code needs alpha blending... */ - if (alphaOffset != 0 || masterPtr->flags & COMPLEX_ALPHA) { + if (!sourceIsSimplePhoto || masterPtr->flags & COMPLEX_ALPHA) { /* * Note that we skip in the single pixel case if we can. This speeds * up code that builds up large simple-alpha images by single pixels, -- cgit v0.12