12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847 |
- /*
- *
- * Copyright © 2000 SuSE, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of SuSE not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. SuSE makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Keith Packard, SuSE, Inc.
- */
- #ifdef HAVE_DIX_CONFIG_H
- #include <dix-config.h>
- #endif
- #include "misc.h"
- #include "scrnintstr.h"
- #include "os.h"
- #include "regionstr.h"
- #include "validate.h"
- #include "windowstr.h"
- #include "input.h"
- #include "resource.h"
- #include "colormapst.h"
- #include "cursorstr.h"
- #include "dixstruct.h"
- #include "gcstruct.h"
- #include "servermd.h"
- #include "picturestr.h"
- _X_EXPORT int PictureScreenPrivateIndex = -1;
- int PictureWindowPrivateIndex;
- int PictureGeneration;
- RESTYPE PictureType;
- RESTYPE PictFormatType;
- RESTYPE GlyphSetType;
- int PictureCmapPolicy = PictureCmapPolicyDefault;
- /* Picture Private machinery */
- static int picturePrivateCount;
- void
- ResetPicturePrivateIndex(void)
- {
- picturePrivateCount = 0;
- }
- Bool
- PictureDestroyWindow(WindowPtr pWindow)
- {
- ScreenPtr pScreen = pWindow->drawable.pScreen;
- PicturePtr pPicture;
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- Bool ret;
- while ((pPicture = GetPictureWindow(pWindow))) {
- SetPictureWindow(pWindow, pPicture->pNext);
- if (pPicture->id)
- FreeResource(pPicture->id, PictureType);
- FreePicture((pointer) pPicture, pPicture->id);
- }
- pScreen->DestroyWindow = ps->DestroyWindow;
- ret = (*pScreen->DestroyWindow) (pWindow);
- ps->DestroyWindow = pScreen->DestroyWindow;
- pScreen->DestroyWindow = PictureDestroyWindow;
- return ret;
- }
- Bool
- PictureCloseScreen(int index, ScreenPtr pScreen)
- {
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- Bool ret;
- int n;
- pScreen->CloseScreen = ps->CloseScreen;
- ret = (*pScreen->CloseScreen) (index, pScreen);
- PictureResetFilters(pScreen);
- for (n = 0; n < ps->nformats; n++)
- if (ps->formats[n].type == PictTypeIndexed)
- (*ps->CloseIndexed) (pScreen, &ps->formats[n]);
- GlyphUninit(pScreen);
- SetPictureScreen(pScreen, 0);
- if (ps->PicturePrivateSizes)
- free(ps->PicturePrivateSizes);
- free(ps->formats);
- free(ps);
- return ret;
- }
- void
- PictureStoreColors(ColormapPtr pColormap, int ndef, xColorItem * pdef)
- {
- ScreenPtr pScreen = pColormap->pScreen;
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- pScreen->StoreColors = ps->StoreColors;
- (*pScreen->StoreColors) (pColormap, ndef, pdef);
- ps->StoreColors = pScreen->StoreColors;
- pScreen->StoreColors = PictureStoreColors;
- if (pColormap->class == PseudoColor || pColormap->class == GrayScale) {
- PictFormatPtr format = ps->formats;
- int nformats = ps->nformats;
- while (nformats--) {
- if (format->type == PictTypeIndexed &&
- format->index.pColormap == pColormap) {
- (*ps->UpdateIndexed) (pScreen, format, ndef, pdef);
- break;
- }
- format++;
- }
- }
- }
- static int
- visualDepth(ScreenPtr pScreen, VisualPtr pVisual)
- {
- int d, v;
- DepthPtr pDepth;
- for (d = 0; d < pScreen->numDepths; d++) {
- pDepth = &pScreen->allowedDepths[d];
- for (v = 0; v < pDepth->numVids; v++)
- if (pDepth->vids[v] == pVisual->vid)
- return pDepth->depth;
- }
- return 0;
- }
- typedef struct _formatInit {
- CARD32 format;
- CARD8 depth;
- } FormatInitRec, *FormatInitPtr;
- static int
- addFormat(FormatInitRec formats[256], int nformat, CARD32 format, CARD8 depth)
- {
- int n;
- for (n = 0; n < nformat; n++)
- if (formats[n].format == format && formats[n].depth == depth)
- return nformat;
- formats[nformat].format = format;
- formats[nformat].depth = depth;
- return ++nformat;
- }
- #define Mask(n) ((n) == 32 ? 0xffffffff : ((1 << (n))-1))
- PictFormatPtr
- PictureCreateDefaultFormats(ScreenPtr pScreen, int *nformatp)
- {
- int nformats, f;
- PictFormatPtr pFormats;
- FormatInitRec formats[1024];
- CARD32 format;
- CARD8 depth;
- VisualPtr pVisual;
- int v;
- int bpp;
- int type;
- int r, g, b;
- int d;
- DepthPtr pDepth;
- nformats = 0;
- /* formats required by protocol */
- formats[nformats].format = PICT_a1;
- formats[nformats].depth = 1;
- nformats++;
- formats[nformats].format = PICT_FORMAT(BitsPerPixel(8),
- PICT_TYPE_A, 8, 0, 0, 0);
- formats[nformats].depth = 8;
- nformats++;
- formats[nformats].format = PICT_FORMAT(BitsPerPixel(4),
- PICT_TYPE_A, 4, 0, 0, 0);
- formats[nformats].depth = 4;
- nformats++;
- formats[nformats].format = PICT_a8r8g8b8;
- formats[nformats].depth = 32;
- nformats++;
- formats[nformats].format = PICT_x8r8g8b8;
- formats[nformats].depth = 32;
- nformats++;
- /* now look through the depths and visuals adding other formats */
- for (v = 0; v < pScreen->numVisuals; v++) {
- pVisual = &pScreen->visuals[v];
- depth = visualDepth(pScreen, pVisual);
- if (!depth)
- continue;
- bpp = BitsPerPixel(depth);
- switch (pVisual->class) {
- case DirectColor:
- case TrueColor:
- r = Ones(pVisual->redMask);
- g = Ones(pVisual->greenMask);
- b = Ones(pVisual->blueMask);
- type = PICT_TYPE_OTHER;
- /*
- * Current rendering code supports only two direct formats,
- * fields must be packed together at the bottom of the pixel
- * and must be either RGB or BGR
- */
- if (pVisual->offsetBlue == 0 &&
- pVisual->offsetGreen == b && pVisual->offsetRed == b + g) {
- type = PICT_TYPE_ARGB;
- }
- else if (pVisual->offsetRed == 0 &&
- pVisual->offsetGreen == r &&
- pVisual->offsetBlue == r + g) {
- type = PICT_TYPE_ABGR;
- }
- if (type != PICT_TYPE_OTHER) {
- format = PICT_FORMAT(bpp, type, 0, r, g, b);
- nformats = addFormat(formats, nformats, format, depth);
- }
- break;
- case StaticColor:
- case PseudoColor:
- format = PICT_VISFORMAT(bpp, PICT_TYPE_COLOR, v);
- nformats = addFormat(formats, nformats, format, depth);
- break;
- case StaticGray:
- case GrayScale:
- format = PICT_VISFORMAT(bpp, PICT_TYPE_GRAY, v);
- nformats = addFormat(formats, nformats, format, depth);
- break;
- }
- }
- /*
- * Walk supported depths and add useful Direct formats
- */
- for (d = 0; d < pScreen->numDepths; d++) {
- pDepth = &pScreen->allowedDepths[d];
- bpp = BitsPerPixel(pDepth->depth);
- switch (bpp) {
- case 16:
- /* depth 12 formats */
- if (pDepth->depth >= 12) {
- nformats = addFormat(formats, nformats,
- PICT_x4r4g4b4, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_x4b4g4r4, pDepth->depth);
- }
- /* depth 15 formats */
- if (pDepth->depth >= 15) {
- nformats = addFormat(formats, nformats,
- PICT_x1r5g5b5, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_x1b5g5r5, pDepth->depth);
- }
- /* depth 16 formats */
- if (pDepth->depth >= 16) {
- nformats = addFormat(formats, nformats,
- PICT_a1r5g5b5, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_a1b5g5r5, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_r5g6b5, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_b5g6r5, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_a4r4g4b4, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_a4b4g4r4, pDepth->depth);
- }
- break;
- case 24:
- if (pDepth->depth >= 24) {
- nformats = addFormat(formats, nformats,
- PICT_r8g8b8, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_b8g8r8, pDepth->depth);
- }
- break;
- case 32:
- if (pDepth->depth >= 24) {
- nformats = addFormat(formats, nformats,
- PICT_x8r8g8b8, pDepth->depth);
- nformats = addFormat(formats, nformats,
- PICT_x8b8g8r8, pDepth->depth);
- }
- break;
- }
- }
- pFormats = malloc(nformats * sizeof(PictFormatRec));
- if (!pFormats)
- return 0;
- memset(pFormats, '\0', nformats * sizeof(PictFormatRec));
- for (f = 0; f < nformats; f++) {
- pFormats[f].id = FakeClientID(0);
- pFormats[f].depth = formats[f].depth;
- format = formats[f].format;
- pFormats[f].format = format;
- switch (PICT_FORMAT_TYPE(format)) {
- case PICT_TYPE_ARGB:
- pFormats[f].type = PictTypeDirect;
- pFormats[f].direct.alphaMask = Mask (PICT_FORMAT_A(format));
- if (pFormats[f].direct.alphaMask)
- pFormats[f].direct.alpha = (PICT_FORMAT_R(format) +
- PICT_FORMAT_G(format) +
- PICT_FORMAT_B(format));
- pFormats[f].direct.redMask = Mask (PICT_FORMAT_R(format));
- pFormats[f].direct.red = (PICT_FORMAT_G(format) +
- PICT_FORMAT_B(format));
- pFormats[f].direct.greenMask = Mask (PICT_FORMAT_G(format));
- pFormats[f].direct.green = PICT_FORMAT_B(format);
- pFormats[f].direct.blueMask = Mask (PICT_FORMAT_B(format));
- pFormats[f].direct.blue = 0;
- break;
- case PICT_TYPE_ABGR:
- pFormats[f].type = PictTypeDirect;
- pFormats[f].direct.alphaMask = Mask (PICT_FORMAT_A(format));
- if (pFormats[f].direct.alphaMask)
- pFormats[f].direct.alpha = (PICT_FORMAT_B(format) +
- PICT_FORMAT_G(format) +
- PICT_FORMAT_R(format));
- pFormats[f].direct.blueMask = Mask (PICT_FORMAT_B(format));
- pFormats[f].direct.blue = (PICT_FORMAT_G(format) +
- PICT_FORMAT_R(format));
- pFormats[f].direct.greenMask = Mask (PICT_FORMAT_G(format));
- pFormats[f].direct.green = PICT_FORMAT_R(format);
- pFormats[f].direct.redMask = Mask (PICT_FORMAT_R(format));
- pFormats[f].direct.red = 0;
- break;
- case PICT_TYPE_A:
- pFormats[f].type = PictTypeDirect;
- pFormats[f].direct.alpha = 0;
- pFormats[f].direct.alphaMask = Mask (PICT_FORMAT_A(format));
- /* remaining fields already set to zero */
- break;
- case PICT_TYPE_COLOR:
- case PICT_TYPE_GRAY:
- pFormats[f].type = PictTypeIndexed;
- pFormats[f].index.vid =
- pScreen->visuals[PICT_FORMAT_VIS(format)].vid;
- break;
- }
- }
- *nformatp = nformats;
- return pFormats;
- }
- static VisualPtr
- PictureFindVisual(ScreenPtr pScreen, VisualID visual)
- {
- int i;
- VisualPtr pVisual;
- for (i = 0, pVisual = pScreen->visuals;
- i < pScreen->numVisuals; i++, pVisual++) {
- if (pVisual->vid == visual)
- return pVisual;
- }
- return 0;
- }
- Bool
- PictureInitIndexedFormats(ScreenPtr pScreen)
- {
- PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
- PictFormatPtr format;
- int nformat;
- if (!ps)
- return FALSE;
- format = ps->formats;
- nformat = ps->nformats;
- while (nformat--) {
- if (format->type == PictTypeIndexed && !format->index.pColormap) {
- if (format->index.vid == pScreen->rootVisual)
- format->index.pColormap =
- (ColormapPtr) LookupIDByType(pScreen->defColormap,
- RT_COLORMAP);
- else {
- VisualPtr pVisual;
- pVisual = PictureFindVisual(pScreen, format->index.vid);
- if (CreateColormap(FakeClientID(0), pScreen,
- pVisual,
- &format->index.pColormap, AllocNone,
- 0) != Success) {
- return FALSE;
- }
- }
- if (!(*ps->InitIndexed) (pScreen, format))
- return FALSE;
- }
- format++;
- }
- return TRUE;
- }
- Bool
- PictureFinishInit(void)
- {
- int s;
- for (s = 0; s < screenInfo.numScreens; s++) {
- if (!GlyphFinishInit(screenInfo.screens[s]))
- return FALSE;
- if (!PictureInitIndexedFormats(screenInfo.screens[s]))
- return FALSE;
- (void) AnimCurInit(screenInfo.screens[s]);
- }
- return TRUE;
- }
- _X_EXPORT Bool
- PictureSetSubpixelOrder(ScreenPtr pScreen, int subpixel)
- {
- PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
- if (!ps)
- return FALSE;
- ps->subpixel = subpixel;
- return TRUE;
- }
- _X_EXPORT int
- PictureGetSubpixelOrder(ScreenPtr pScreen)
- {
- PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
- if (!ps)
- return SubPixelUnknown;
- return ps->subpixel;
- }
- PictFormatPtr
- PictureMatchVisual(ScreenPtr pScreen, int depth, VisualPtr pVisual)
- {
- PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
- PictFormatPtr format;
- int nformat;
- int type;
- if (!ps)
- return 0;
- format = ps->formats;
- nformat = ps->nformats;
- switch (pVisual->class) {
- case StaticGray:
- case GrayScale:
- case StaticColor:
- case PseudoColor:
- type = PictTypeIndexed;
- break;
- case TrueColor:
- case DirectColor:
- type = PictTypeDirect;
- break;
- default:
- return 0;
- }
- while (nformat--) {
- if (format->depth == depth && format->type == type) {
- if (type == PictTypeIndexed) {
- if (format->index.vid == pVisual->vid)
- return format;
- }
- else {
- if (format->direct.redMask << format->direct.red ==
- pVisual->redMask &&
- format->direct.greenMask << format->direct.green ==
- pVisual->greenMask &&
- format->direct.blueMask << format->direct.blue ==
- pVisual->blueMask) {
- return format;
- }
- }
- }
- format++;
- }
- return 0;
- }
- PictFormatPtr
- PictureMatchFormat(ScreenPtr pScreen, int depth, CARD32 f)
- {
- PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
- PictFormatPtr format;
- int nformat;
- if (!ps)
- return 0;
- format = ps->formats;
- nformat = ps->nformats;
- while (nformat--) {
- if (format->depth == depth && format->format == (f & 0xffffff))
- return format;
- format++;
- }
- return 0;
- }
- int
- PictureParseCmapPolicy(const char *name)
- {
- if (strcmp(name, "default") == 0)
- return PictureCmapPolicyDefault;
- else if (strcmp(name, "mono") == 0)
- return PictureCmapPolicyMono;
- else if (strcmp(name, "gray") == 0)
- return PictureCmapPolicyGray;
- else if (strcmp(name, "color") == 0)
- return PictureCmapPolicyColor;
- else if (strcmp(name, "all") == 0)
- return PictureCmapPolicyAll;
- else
- return PictureCmapPolicyInvalid;
- }
- _X_EXPORT Bool
- PictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
- {
- PictureScreenPtr ps;
- int n;
- CARD32 type, a, r, g, b;
- if (PictureGeneration != serverGeneration) {
- PictureType = CreateNewResourceType(FreePicture);
- if (!PictureType)
- return FALSE;
- PictFormatType = CreateNewResourceType(FreePictFormat);
- if (!PictFormatType)
- return FALSE;
- GlyphSetType = CreateNewResourceType(FreeGlyphSet);
- if (!GlyphSetType)
- return FALSE;
- PictureScreenPrivateIndex = AllocateScreenPrivateIndex();
- if (PictureScreenPrivateIndex < 0)
- return FALSE;
- PictureWindowPrivateIndex = AllocateWindowPrivateIndex();
- PictureGeneration = serverGeneration;
- #ifdef XResExtension
- RegisterResourceName(PictureType, "PICTURE");
- RegisterResourceName(PictFormatType, "PICTFORMAT");
- RegisterResourceName(GlyphSetType, "GLYPHSET");
- #endif
- }
- if (!AllocateWindowPrivate(pScreen, PictureWindowPrivateIndex, 0))
- return FALSE;
- if (!formats) {
- formats = PictureCreateDefaultFormats(pScreen, &nformats);
- if (!formats)
- return FALSE;
- }
- for (n = 0; n < nformats; n++) {
- if (!AddResource
- (formats[n].id, PictFormatType, (pointer) (formats + n))) {
- free(formats);
- return FALSE;
- }
- if (formats[n].type == PictTypeIndexed) {
- VisualPtr pVisual =
- PictureFindVisual(pScreen, formats[n].index.vid);
- if ((pVisual->class | DynamicClass) == PseudoColor)
- type = PICT_TYPE_COLOR;
- else
- type = PICT_TYPE_GRAY;
- a = r = g = b = 0;
- }
- else {
- if ((formats[n].direct.redMask |
- formats[n].direct.blueMask | formats[n].direct.greenMask) == 0)
- type = PICT_TYPE_A;
- else if (formats[n].direct.red > formats[n].direct.blue)
- type = PICT_TYPE_ARGB;
- else
- type = PICT_TYPE_ABGR;
- a = Ones(formats[n].direct.alphaMask);
- r = Ones(formats[n].direct.redMask);
- g = Ones(formats[n].direct.greenMask);
- b = Ones(formats[n].direct.blueMask);
- }
- formats[n].format = PICT_FORMAT(0, type, a, r, g, b);
- }
- ps = malloc(sizeof(PictureScreenRec));
- if (!ps) {
- free(formats);
- return FALSE;
- }
- SetPictureScreen(pScreen, ps);
- if (!GlyphInit(pScreen)) {
- SetPictureScreen(pScreen, 0);
- free(formats);
- free(ps);
- return FALSE;
- }
- ps->totalPictureSize = sizeof(PictureRec);
- ps->PicturePrivateSizes = 0;
- ps->PicturePrivateLen = 0;
- ps->formats = formats;
- ps->fallback = formats;
- ps->nformats = nformats;
- ps->filters = 0;
- ps->nfilters = 0;
- ps->filterAliases = 0;
- ps->nfilterAliases = 0;
- ps->subpixel = SubPixelUnknown;
- ps->CloseScreen = pScreen->CloseScreen;
- ps->DestroyWindow = pScreen->DestroyWindow;
- ps->StoreColors = pScreen->StoreColors;
- pScreen->DestroyWindow = PictureDestroyWindow;
- pScreen->CloseScreen = PictureCloseScreen;
- pScreen->StoreColors = PictureStoreColors;
- if (!PictureSetDefaultFilters(pScreen)) {
- PictureResetFilters(pScreen);
- SetPictureScreen(pScreen, 0);
- free(formats);
- free(ps);
- return FALSE;
- }
- return TRUE;
- }
- void
- SetPictureToDefaults(PicturePtr pPicture)
- {
- pPicture->refcnt = 1;
- pPicture->repeat = 0;
- pPicture->graphicsExposures = FALSE;
- pPicture->subWindowMode = ClipByChildren;
- pPicture->polyEdge = PolyEdgeSharp;
- pPicture->polyMode = PolyModePrecise;
- pPicture->freeCompClip = FALSE;
- pPicture->clientClipType = CT_NONE;
- pPicture->componentAlpha = FALSE;
- pPicture->repeatType = RepeatNone;
- pPicture->alphaMap = 0;
- pPicture->alphaOrigin.x = 0;
- pPicture->alphaOrigin.y = 0;
- pPicture->clipOrigin.x = 0;
- pPicture->clipOrigin.y = 0;
- pPicture->clientClip = 0;
- pPicture->transform = 0;
- pPicture->dither = None;
- pPicture->filter = PictureGetFilterId(FilterNearest, -1, TRUE);
- pPicture->filter_params = 0;
- pPicture->filter_nparams = 0;
- pPicture->serialNumber = GC_CHANGE_SERIAL_BIT;
- pPicture->stateChanges = (1 << (CPLastBit + 1)) - 1;
- pPicture->pSourcePict = 0;
- }
- PicturePtr
- AllocatePicture(ScreenPtr pScreen)
- {
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- PicturePtr pPicture;
- char *ptr;
- DevUnion *ppriv;
- unsigned int *sizes;
- unsigned int size;
- int i;
- pPicture = malloc(ps->totalPictureSize);
- if (!pPicture)
- return 0;
- ppriv = (DevUnion *) (pPicture + 1);
- pPicture->devPrivates = ppriv;
- sizes = ps->PicturePrivateSizes;
- ptr = (char *) (ppriv + ps->PicturePrivateLen);
- for (i = ps->PicturePrivateLen; --i >= 0; ppriv++, sizes++) {
- if ((size = *sizes)) {
- ppriv->ptr = (pointer) ptr;
- ptr += size;
- }
- else
- ppriv->ptr = (pointer) NULL;
- }
- return pPicture;
- }
- PicturePtr
- CreatePicture(Picture pid,
- DrawablePtr pDrawable,
- PictFormatPtr pFormat,
- Mask vmask, XID *vlist, ClientPtr client, int *error)
- {
- PicturePtr pPicture;
- PictureScreenPtr ps = GetPictureScreen(pDrawable->pScreen);
- pPicture = AllocatePicture(pDrawable->pScreen);
- if (!pPicture) {
- *error = BadAlloc;
- return 0;
- }
- pPicture->id = pid;
- pPicture->pDrawable = pDrawable;
- pPicture->pFormat = pFormat;
- pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24);
- if (pDrawable->type == DRAWABLE_PIXMAP) {
- ++((PixmapPtr) pDrawable)->refcnt;
- pPicture->pNext = 0;
- }
- else {
- pPicture->pNext = GetPictureWindow(((WindowPtr) pDrawable));
- SetPictureWindow(((WindowPtr) pDrawable), pPicture);
- }
- SetPictureToDefaults(pPicture);
- if (vmask)
- *error = ChangePicture(pPicture, vmask, vlist, 0, client);
- else
- *error = Success;
- if (*error == Success)
- *error = (*ps->CreatePicture) (pPicture);
- if (*error != Success) {
- FreePicture(pPicture, (XID) 0);
- pPicture = 0;
- }
- return pPicture;
- }
- static CARD32
- xRenderColorToCard32(xRenderColor c)
- {
- return
- (c.alpha >> 8 << 24) |
- (c.red >> 8 << 16) | (c.green & 0xff00) | (c.blue >> 8);
- }
- static unsigned int
- premultiply(unsigned int x)
- {
- unsigned int a = x >> 24;
- unsigned int t = (x & 0xff00ff) * a + 0x800080;
- t = (t + ((t >> 8) & 0xff00ff)) >> 8;
- t &= 0xff00ff;
- x = ((x >> 8) & 0xff) * a + 0x80;
- x = (x + ((x >> 8) & 0xff));
- x &= 0xff00;
- x |= t | (a << 24);
- return x;
- }
- static unsigned int
- INTERPOLATE_PIXEL_256(unsigned int x, unsigned int a,
- unsigned int y, unsigned int b)
- {
- CARD32 t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
- t >>= 8;
- t &= 0xff00ff;
- x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
- x &= 0xff00ff00;
- x |= t;
- return x;
- }
- static void
- initGradientColorTable(SourcePictPtr pGradient, int *error)
- {
- int begin_pos, end_pos;
- xFixed incr, dpos;
- int pos, current_stop;
- PictGradientStopPtr stops = pGradient->linear.stops;
- int nstops = pGradient->linear.nstops;
- /* The position where the gradient begins and ends */
- begin_pos = (stops[0].x * PICT_GRADIENT_STOPTABLE_SIZE) >> 16;
- end_pos = (stops[nstops - 1].x * PICT_GRADIENT_STOPTABLE_SIZE) >> 16;
- pos = 0; /* The position in the color table. */
- /* Up to first point */
- while (pos <= begin_pos) {
- pGradient->linear.colorTable[pos] =
- xRenderColorToCard32(stops[0].color);
- ++pos;
- }
- incr = (1 << 16) / PICT_GRADIENT_STOPTABLE_SIZE; /* the double increment. */
- dpos = incr * pos; /* The position in terms of 0-1. */
- current_stop = 0; /* We always interpolate between current and current + 1. */
- /* Gradient area */
- while (pos < end_pos) {
- unsigned int current_color =
- xRenderColorToCard32(stops[current_stop].color);
- unsigned int next_color =
- xRenderColorToCard32(stops[current_stop + 1].color);
- int dist = (int) (256 * (dpos - stops[current_stop].x)
- / (stops[current_stop + 1].x -
- stops[current_stop].x));
- int idist = 256 - dist;
- pGradient->linear.colorTable[pos] =
- premultiply(INTERPOLATE_PIXEL_256
- (current_color, idist, next_color, dist));
- ++pos;
- dpos += incr;
- if (dpos > stops[current_stop + 1].x)
- ++current_stop;
- }
- /* After last point */
- while (pos < PICT_GRADIENT_STOPTABLE_SIZE) {
- pGradient->linear.colorTable[pos] =
- xRenderColorToCard32(stops[nstops - 1].color);
- ++pos;
- }
- }
- static void
- initGradient(SourcePictPtr pGradient, int stopCount,
- xFixed * stopPoints, xRenderColor * stopColors, int *error)
- {
- int i;
- xFixed dpos;
- if (stopCount <= 0) {
- *error = BadValue;
- return;
- }
- dpos = -1;
- for (i = 0; i < stopCount; ++i) {
- if (stopPoints[i] <= dpos || stopPoints[i] > (1 << 16)) {
- *error = BadValue;
- return;
- }
- dpos = stopPoints[i];
- }
- pGradient->linear.stops = malloc(stopCount * sizeof(PictGradientStop));
- if (!pGradient->linear.stops) {
- *error = BadAlloc;
- return;
- }
- pGradient->linear.nstops = stopCount;
- for (i = 0; i < stopCount; ++i) {
- pGradient->linear.stops[i].x = stopPoints[i];
- pGradient->linear.stops[i].color = stopColors[i];
- }
- initGradientColorTable(pGradient, error);
- }
- static PicturePtr
- createSourcePicture(void)
- {
- PicturePtr pPicture;
- pPicture = malloc(sizeof(PictureRec));
- pPicture->pDrawable = 0;
- pPicture->format = PICT_a8r8g8b8;
- pPicture->pFormat = 0;
- pPicture->pNext = 0;
- pPicture->devPrivates = 0;
- SetPictureToDefaults(pPicture);
- return pPicture;
- }
- PicturePtr
- CreateSolidPicture(Picture pid, xRenderColor * color, int *error)
- {
- PicturePtr pPicture;
- pPicture = createSourcePicture();
- if (!pPicture) {
- *error = BadAlloc;
- return 0;
- }
- pPicture->id = pid;
- pPicture->pSourcePict = malloc(sizeof(PictSolidFill));
- if (!pPicture->pSourcePict) {
- *error = BadAlloc;
- free(pPicture);
- return 0;
- }
- pPicture->pSourcePict->type = SourcePictTypeSolidFill;
- pPicture->pSourcePict->solidFill.color = xRenderColorToCard32(*color);
- return pPicture;
- }
- PicturePtr
- CreateLinearGradientPicture(Picture pid, xPointFixed * p1, xPointFixed * p2,
- int nStops, xFixed * stops, xRenderColor * colors,
- int *error)
- {
- PicturePtr pPicture;
- if (nStops < 2) {
- *error = BadValue;
- return 0;
- }
- pPicture = createSourcePicture();
- if (!pPicture) {
- *error = BadAlloc;
- return 0;
- }
- if (p1->x == p2->x && p1->y == p2->y) {
- *error = BadValue;
- free(pPicture);
- return 0;
- }
- pPicture->id = pid;
- pPicture->pSourcePict = malloc(sizeof(PictLinearGradient));
- if (!pPicture->pSourcePict) {
- *error = BadAlloc;
- free(pPicture);
- return 0;
- }
- pPicture->pSourcePict->linear.type = SourcePictTypeLinear;
- pPicture->pSourcePict->linear.p1 = *p1;
- pPicture->pSourcePict->linear.p2 = *p2;
- initGradient(pPicture->pSourcePict, nStops, stops, colors, error);
- if (*error) {
- free(pPicture);
- return 0;
- }
- return pPicture;
- }
- #define FixedToDouble(x) ((x)/65536.)
- PicturePtr
- CreateRadialGradientPicture(Picture pid, xPointFixed * inner,
- xPointFixed * outer, xFixed innerRadius,
- xFixed outerRadius, int nStops, xFixed * stops,
- xRenderColor * colors, int *error)
- {
- PicturePtr pPicture;
- PictRadialGradient *radial;
- if (nStops < 2) {
- *error = BadValue;
- return 0;
- }
- pPicture = createSourcePicture();
- if (!pPicture) {
- *error = BadAlloc;
- return 0;
- }
- {
- double dx = (double) (inner->x - outer->x);
- double dy = (double) (inner->y - outer->y);
- if (sqrt(dx * dx + dy * dy) + (double) (innerRadius) >
- (double) (outerRadius)) {
- *error = BadValue;
- free(pPicture);
- return 0;
- }
- }
- pPicture->id = pid;
- pPicture->pSourcePict = malloc(sizeof(PictRadialGradient));
- if (!pPicture->pSourcePict) {
- *error = BadAlloc;
- free(pPicture);
- return 0;
- }
- radial = &pPicture->pSourcePict->radial;
- radial->type = SourcePictTypeRadial;
- {
- double x = (double) innerRadius / (double) outerRadius;
- radial->dx = (outer->x - inner->x);
- radial->dy = (outer->y - inner->y);
- radial->fx = (inner->x) - x * radial->dx;
- radial->fy = (inner->y) - x * radial->dy;
- radial->m = 1. / (1 + x);
- radial->b = -x * radial->m;
- radial->dx /= 65536.;
- radial->dy /= 65536.;
- radial->fx /= 65536.;
- radial->fy /= 65536.;
- x = outerRadius / 65536.;
- radial->a = x * x - radial->dx * radial->dx - radial->dy * radial->dy;
- }
- initGradient(pPicture->pSourcePict, nStops, stops, colors, error);
- if (*error) {
- free(pPicture);
- return 0;
- }
- return pPicture;
- }
- PicturePtr
- CreateConicalGradientPicture(Picture pid, xPointFixed * center, xFixed angle,
- int nStops, xFixed * stops, xRenderColor * colors,
- int *error)
- {
- PicturePtr pPicture;
- if (nStops < 2) {
- *error = BadValue;
- return 0;
- }
- pPicture = createSourcePicture();
- if (!pPicture) {
- *error = BadAlloc;
- return 0;
- }
- pPicture->id = pid;
- pPicture->pSourcePict = malloc(sizeof(PictConicalGradient));
- if (!pPicture->pSourcePict) {
- *error = BadAlloc;
- free(pPicture);
- return 0;
- }
- pPicture->pSourcePict->conical.type = SourcePictTypeConical;
- pPicture->pSourcePict->conical.center = *center;
- pPicture->pSourcePict->conical.angle = angle;
- initGradient(pPicture->pSourcePict, nStops, stops, colors, error);
- if (*error) {
- free(pPicture);
- return 0;
- }
- return pPicture;
- }
- #define NEXT_VAL(_type) (vlist ? (_type) *vlist++ : (_type) ulist++->val)
- #define NEXT_PTR(_type) ((_type) ulist++->ptr)
- int
- ChangePicture(PicturePtr pPicture,
- Mask vmask, XID *vlist, DevUnion *ulist, ClientPtr client)
- {
- ScreenPtr pScreen = pPicture->pDrawable ? pPicture->pDrawable->pScreen : 0;
- PictureScreenPtr ps = pScreen ? GetPictureScreen(pScreen) : 0;
- BITS32 index2;
- int error = 0;
- BITS32 maskQ;
- pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT;
- maskQ = vmask;
- while (vmask && !error) {
- index2 = (BITS32) lowbit(vmask);
- vmask &= ~index2;
- pPicture->stateChanges |= index2;
- switch (index2) {
- case CPRepeat:
- {
- unsigned int newr;
- newr = NEXT_VAL(unsigned int);
- if (newr <= RepeatReflect) {
- pPicture->repeat = (newr != RepeatNone);
- pPicture->repeatType = newr;
- }
- else {
- client->errorValue = newr;
- error = BadValue;
- }
- }
- break;
- case CPAlphaMap:
- {
- PicturePtr pAlpha;
- if (vlist) {
- Picture pid = NEXT_VAL(Picture);
- if (pid == None)
- pAlpha = 0;
- else {
- pAlpha = (PicturePtr) SecurityLookupIDByType(client,
- pid,
- PictureType,
- SecurityWriteAccess
- |
- SecurityReadAccess);
- if (!pAlpha) {
- client->errorValue = pid;
- error = BadPixmap;
- break;
- }
- if (pAlpha->pDrawable == NULL ||
- pAlpha->pDrawable->type != DRAWABLE_PIXMAP) {
- client->errorValue = pid;
- error = BadMatch;
- break;
- }
- }
- }
- else
- pAlpha = NEXT_PTR(PicturePtr);
- if (!error) {
- if (pAlpha && pAlpha->pDrawable->type == DRAWABLE_PIXMAP)
- pAlpha->refcnt++;
- if (pPicture->alphaMap)
- FreePicture((pointer) pPicture->alphaMap, (XID) 0);
- pPicture->alphaMap = pAlpha;
- }
- }
- break;
- case CPAlphaXOrigin:
- pPicture->alphaOrigin.x = NEXT_VAL(INT16);
- break;
- case CPAlphaYOrigin:
- pPicture->alphaOrigin.y = NEXT_VAL(INT16);
- break;
- case CPClipXOrigin:
- pPicture->clipOrigin.x = NEXT_VAL(INT16);
- break;
- case CPClipYOrigin:
- pPicture->clipOrigin.y = NEXT_VAL(INT16);
- break;
- case CPClipMask:
- {
- Pixmap pid;
- PixmapPtr pPixmap;
- int clipType;
- if (!pScreen)
- return BadDrawable;
- if (vlist) {
- pid = NEXT_VAL(Pixmap);
- if (pid == None) {
- clipType = CT_NONE;
- pPixmap = NullPixmap;
- }
- else {
- clipType = CT_PIXMAP;
- pPixmap = (PixmapPtr) SecurityLookupIDByType(client,
- pid,
- RT_PIXMAP,
- SecurityReadAccess);
- if (!pPixmap) {
- client->errorValue = pid;
- error = BadPixmap;
- break;
- }
- }
- }
- else {
- pPixmap = NEXT_PTR(PixmapPtr);
- if (pPixmap)
- clipType = CT_PIXMAP;
- else
- clipType = CT_NONE;
- }
- if (pPixmap) {
- if ((pPixmap->drawable.depth != 1) ||
- (pPixmap->drawable.pScreen != pScreen)) {
- error = BadMatch;
- break;
- }
- else {
- clipType = CT_PIXMAP;
- pPixmap->refcnt++;
- }
- }
- error = (*ps->ChangePictureClip) (pPicture, clipType,
- (pointer) pPixmap, 0);
- break;
- }
- case CPGraphicsExposure:
- {
- unsigned int newe;
- newe = NEXT_VAL(unsigned int);
- if (newe <= xTrue)
- pPicture->graphicsExposures = newe;
- else {
- client->errorValue = newe;
- error = BadValue;
- }
- }
- break;
- case CPSubwindowMode:
- {
- unsigned int news;
- news = NEXT_VAL(unsigned int);
- if (news == ClipByChildren || news == IncludeInferiors)
- pPicture->subWindowMode = news;
- else {
- client->errorValue = news;
- error = BadValue;
- }
- }
- break;
- case CPPolyEdge:
- {
- unsigned int newe;
- newe = NEXT_VAL(unsigned int);
- if (newe == PolyEdgeSharp || newe == PolyEdgeSmooth)
- pPicture->polyEdge = newe;
- else {
- client->errorValue = newe;
- error = BadValue;
- }
- }
- break;
- case CPPolyMode:
- {
- unsigned int newm;
- newm = NEXT_VAL(unsigned int);
- if (newm == PolyModePrecise || newm == PolyModeImprecise)
- pPicture->polyMode = newm;
- else {
- client->errorValue = newm;
- error = BadValue;
- }
- }
- break;
- case CPDither:
- pPicture->dither = NEXT_VAL(Atom);
- break;
- case CPComponentAlpha:
- {
- unsigned int newca;
- newca = NEXT_VAL(unsigned int);
- if (newca <= xTrue)
- pPicture->componentAlpha = newca;
- else {
- client->errorValue = newca;
- error = BadValue;
- }
- }
- break;
- default:
- client->errorValue = maskQ;
- error = BadValue;
- break;
- }
- }
- if (ps)
- (*ps->ChangePicture) (pPicture, maskQ);
- return error;
- }
- int
- SetPictureClipRects(PicturePtr pPicture,
- int xOrigin, int yOrigin, int nRect, xRectangle *rects)
- {
- ScreenPtr pScreen = pPicture->pDrawable->pScreen;
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- RegionPtr clientClip;
- int result;
- clientClip = RECTS_TO_REGION(nRect, rects, CT_UNSORTED);
- if (!clientClip)
- return BadAlloc;
- result = (*ps->ChangePictureClip) (pPicture, CT_REGION,
- (pointer) clientClip, 0);
- if (result == Success) {
- pPicture->clipOrigin.x = xOrigin;
- pPicture->clipOrigin.y = yOrigin;
- pPicture->stateChanges |= CPClipXOrigin | CPClipYOrigin | CPClipMask;
- pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT;
- }
- return result;
- }
- int
- SetPictureClipRegion(PicturePtr pPicture,
- int xOrigin, int yOrigin, RegionPtr pRegion)
- {
- ScreenPtr pScreen = pPicture->pDrawable->pScreen;
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- RegionPtr clientClip;
- int result;
- int type;
- if (pRegion) {
- type = CT_REGION;
- clientClip = REGION_CREATE(REGION_EXTENTS(pRegion),
- REGION_NUM_RECTS(pRegion));
- if (!clientClip)
- return BadAlloc;
- if (!REGION_COPY(clientClip, pRegion)) {
- REGION_DESTROY(clientClip);
- return BadAlloc;
- }
- }
- else {
- type = CT_NONE;
- clientClip = 0;
- }
- result = (*ps->ChangePictureClip) (pPicture, type, (pointer) clientClip, 0);
- if (result == Success) {
- pPicture->clipOrigin.x = xOrigin;
- pPicture->clipOrigin.y = yOrigin;
- pPicture->stateChanges |= CPClipXOrigin | CPClipYOrigin | CPClipMask;
- pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT;
- }
- return result;
- }
- static Bool
- transformIsIdentity(PictTransform * t)
- {
- return ((t->matrix[0][0] == t->matrix[1][1]) &&
- (t->matrix[0][0] == t->matrix[2][2]) &&
- (t->matrix[0][0] != 0) &&
- (t->matrix[0][1] == 0) &&
- (t->matrix[0][2] == 0) &&
- (t->matrix[1][0] == 0) &&
- (t->matrix[1][2] == 0) &&
- (t->matrix[2][0] == 0) && (t->matrix[2][1] == 0));
- }
- int
- SetPictureTransform(PicturePtr pPicture, PictTransform * transform)
- {
- if (transform && transformIsIdentity(transform))
- transform = 0;
- if (transform) {
- if (!pPicture->transform) {
- pPicture->transform =
- malloc(sizeof(PictTransform));
- if (!pPicture->transform)
- return BadAlloc;
- }
- *pPicture->transform = *transform;
- }
- else {
- if (pPicture->transform) {
- free(pPicture->transform);
- pPicture->transform = 0;
- }
- }
- pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT;
- if (pPicture->pDrawable != NULL) {
- int result;
- PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen);
- result = (*ps->ChangePictureTransform) (pPicture, transform);
- return result;
- }
- return Success;
- }
- static void
- ValidateOnePicture(PicturePtr pPicture)
- {
- if (pPicture->pDrawable &&
- pPicture->serialNumber != pPicture->pDrawable->serialNumber) {
- PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen);
- (*ps->ValidatePicture) (pPicture, pPicture->stateChanges);
- pPicture->stateChanges = 0;
- pPicture->serialNumber = pPicture->pDrawable->serialNumber;
- }
- }
- void
- ValidatePicture(PicturePtr pPicture)
- {
- ValidateOnePicture(pPicture);
- if (pPicture->alphaMap)
- ValidateOnePicture(pPicture->alphaMap);
- }
- int
- FreePicture(pointer value, XID pid)
- {
- PicturePtr pPicture = (PicturePtr) value;
- if (--pPicture->refcnt == 0) {
- if (pPicture->transform)
- free(pPicture->transform);
- if (!pPicture->pDrawable) {
- if (pPicture->pSourcePict) {
- if (pPicture->pSourcePict->type != SourcePictTypeSolidFill)
- free(pPicture->pSourcePict->linear.stops);
- free(pPicture->pSourcePict);
- }
- }
- else {
- ScreenPtr pScreen = pPicture->pDrawable->pScreen;
- PictureScreenPtr ps = GetPictureScreen(pScreen);
- if (pPicture->alphaMap)
- FreePicture((pointer) pPicture->alphaMap, (XID) 0);
- (*ps->DestroyPicture) (pPicture);
- (*ps->DestroyPictureClip) (pPicture);
- if (pPicture->pDrawable->type == DRAWABLE_WINDOW) {
- WindowPtr pWindow = (WindowPtr) pPicture->pDrawable;
- PicturePtr *pPrev;
- for (pPrev =
- (PicturePtr *) & ((pWindow)->
- devPrivates[PictureWindowPrivateIndex].
- ptr); *pPrev; pPrev = &(*pPrev)->pNext) {
- if (*pPrev == pPicture) {
- *pPrev = pPicture->pNext;
- break;
- }
- }
- }
- else if (pPicture->pDrawable->type == DRAWABLE_PIXMAP) {
- (*pScreen->DestroyPixmap) ((PixmapPtr) pPicture->pDrawable);
- }
- }
- free(pPicture);
- }
- return Success;
- }
- int
- FreePictFormat(pointer pPictFormat, XID pid)
- {
- return Success;
- }
- /**
- * ReduceCompositeOp is used to choose simpler ops for cases where alpha
- * channels are always one and so math on the alpha channel per pixel becomes
- * unnecessary. It may also avoid destination reads sometimes if apps aren't
- * being careful to avoid these cases.
- */
- static Bool
- ReduceCompositeOp(CARD8 op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst)
- {
- Bool no_src_alpha, no_dst_alpha;
- no_src_alpha = PICT_FORMAT_COLOR(pSrc->format) &&
- PICT_FORMAT_A(pSrc->format) == 0 &&
- pSrc->alphaMap == NULL && pMask == NULL;
- no_dst_alpha = PICT_FORMAT_COLOR(pDst->format) &&
- PICT_FORMAT_A(pDst->format) == 0 && pDst->alphaMap == NULL;
- /* TODO, maybe: Conjoint and Disjoint op reductions? */
- /* Deal with simplifications where the source alpha is always 1. */
- if (no_src_alpha) {
- switch (op) {
- case PictOpOver:
- op = PictOpSrc;
- break;
- case PictOpInReverse:
- op = PictOpDst;
- break;
- case PictOpOutReverse:
- op = PictOpClear;
- break;
- case PictOpAtop:
- op = PictOpIn;
- break;
- case PictOpAtopReverse:
- op = PictOpOverReverse;
- break;
- case PictOpXor:
- op = PictOpOut;
- break;
- default:
- break;
- }
- }
- /* Deal with simplifications when the destination alpha is always 1 */
- if (no_dst_alpha) {
- switch (op) {
- case PictOpOverReverse:
- op = PictOpDst;
- break;
- case PictOpIn:
- op = PictOpSrc;
- break;
- case PictOpOut:
- op = PictOpClear;
- break;
- case PictOpAtop:
- op = PictOpOver;
- break;
- case PictOpXor:
- op = PictOpOutReverse;
- break;
- default:
- break;
- }
- }
- /* Reduce some con/disjoint ops to the basic names. */
- switch (op) {
- case PictOpDisjointClear:
- case PictOpConjointClear:
- op = PictOpClear;
- break;
- case PictOpDisjointSrc:
- case PictOpConjointSrc:
- op = PictOpSrc;
- break;
- case PictOpDisjointDst:
- case PictOpConjointDst:
- op = PictOpDst;
- break;
- default:
- break;
- }
- return op;
- }
- void
- CompositePicture(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pMask,
- PicturePtr pDst,
- INT16 xSrc,
- INT16 ySrc,
- INT16 xMask,
- INT16 yMask,
- INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
- {
- PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen);
- ValidatePicture(pSrc);
- if (pMask)
- ValidatePicture(pMask);
- ValidatePicture(pDst);
- op = ReduceCompositeOp(op, pSrc, pMask, pDst);
- if (op == PictOpDst)
- return;
- (*ps->Composite) (op,
- pSrc,
- pMask,
- pDst,
- xSrc, ySrc, xMask, yMask, xDst, yDst, width, height);
- }
- void
- CompositeGlyphs(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pDst,
- PictFormatPtr maskFormat,
- INT16 xSrc,
- INT16 ySrc, int nlist, GlyphListPtr lists, GlyphPtr * glyphs)
- {
- PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen);
- ValidatePicture(pSrc);
- ValidatePicture(pDst);
- (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, lists,
- glyphs);
- }
- void
- CompositeRects(CARD8 op,
- PicturePtr pDst,
- xRenderColor * color, int nRect, xRectangle *rects)
- {
- PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen);
- ValidatePicture(pDst);
- (*ps->CompositeRects) (op, pDst, color, nRect, rects);
- }
- void
- CompositeTrapezoids(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pDst,
- PictFormatPtr maskFormat,
- INT16 xSrc, INT16 ySrc, int ntrap, xTrapezoid * traps)
- {
- PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen);
- ValidatePicture(pSrc);
- ValidatePicture(pDst);
- (*ps->Trapezoids) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntrap, traps);
- }
- void
- CompositeTriangles(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pDst,
- PictFormatPtr maskFormat,
- INT16 xSrc,
- INT16 ySrc, int ntriangles, xTriangle * triangles)
- {
- PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen);
- ValidatePicture(pSrc);
- ValidatePicture(pDst);
- (*ps->Triangles) (op, pSrc, pDst, maskFormat, xSrc, ySrc, ntriangles,
- triangles);
- }
- void
- CompositeTriStrip(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pDst,
- PictFormatPtr maskFormat,
- INT16 xSrc, INT16 ySrc, int npoints, xPointFixed * points)
- {
- PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen);
- ValidatePicture(pSrc);
- ValidatePicture(pDst);
- (*ps->TriStrip) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points);
- }
- void
- CompositeTriFan(CARD8 op,
- PicturePtr pSrc,
- PicturePtr pDst,
- PictFormatPtr maskFormat,
- INT16 xSrc, INT16 ySrc, int npoints, xPointFixed * points)
- {
- PictureScreenPtr ps = GetPictureScreen(pDst->pDrawable->pScreen);
- ValidatePicture(pSrc);
- ValidatePicture(pDst);
- (*ps->TriFan) (op, pSrc, pDst, maskFormat, xSrc, ySrc, npoints, points);
- }
- void
- AddTraps(PicturePtr pPicture, INT16 xOff, INT16 yOff, int ntrap, xTrap * traps)
- {
- PictureScreenPtr ps = GetPictureScreen(pPicture->pDrawable->pScreen);
- ValidatePicture(pPicture);
- (*ps->AddTraps) (pPicture, xOff, yOff, ntrap, traps);
- }
- #define MAX_FIXED_48_16 ((xFixed_48_16) 0x7fffffff)
- #define MIN_FIXED_48_16 (-((xFixed_48_16) 1 << 31))
- _X_EXPORT Bool
- PictureTransformPoint3d(PictTransformPtr transform, PictVectorPtr vector)
- {
- PictVector result;
- int i, j;
- xFixed_32_32 partial;
- xFixed_48_16 v;
- for (j = 0; j < 3; j++) {
- v = 0;
- for (i = 0; i < 3; i++) {
- partial = ((xFixed_48_16) transform->matrix[j][i] *
- (xFixed_48_16) vector->vector[i]);
- v += partial >> 16;
- }
- if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16)
- return FALSE;
- result.vector[j] = (xFixed) v;
- }
- if (!result.vector[2])
- return FALSE;
- *vector = result;
- return TRUE;
- }
- _X_EXPORT Bool
- PictureTransformPoint(PictTransformPtr transform, PictVectorPtr vector)
- {
- PictVector result;
- int i, j;
- xFixed_32_32 partial;
- xFixed_48_16 v;
- for (j = 0; j < 3; j++) {
- v = 0;
- for (i = 0; i < 3; i++) {
- partial = ((xFixed_48_16) transform->matrix[j][i] *
- (xFixed_48_16) vector->vector[i]);
- v += partial >> 16;
- }
- if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16)
- return FALSE;
- result.vector[j] = (xFixed) v;
- }
- if (!result.vector[2])
- return FALSE;
- for (j = 0; j < 2; j++) {
- partial = (xFixed_48_16) result.vector[j] << 16;
- v = partial / result.vector[2];
- if (v > MAX_FIXED_48_16 || v < MIN_FIXED_48_16)
- return FALSE;
- vector->vector[j] = (xFixed) v;
- }
- vector->vector[2] = xFixed1;
- return TRUE;
- }
|