1
/* $Xorg: miLUTProcs.ci,v 1.4 2001/02/09 02:04:13 xorgcvs Exp $ */
4
Copyright 1990, 1991, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included
13
in all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall
24
not be used in advertising or otherwise to promote the sale, use or
25
other dealings in this Software without prior written authorization
29
Copyright 1990, 1991 by Sun Microsystems, Inc.
32
Permission to use, copy, modify, and distribute this software and its
33
documentation for any purpose and without fee is hereby granted,
34
provided that the above copyright notice appear in all copies and that
35
both that copyright notice and this permission notice appear in
36
supporting documentation, and that the name of Sun Microsystems
37
not be used in advertising or publicity pertaining to distribution
38
of the software without specific, written prior permission.
40
SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
41
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
42
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
43
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
50
#ifndef MILUT_PROCS_CI
51
#define MILUT_PROCS_CI
55
/* this file is a template for defining the lut procedures */
56
/* it uses a bunch of macros (blah) but allows easier porting */
57
/* the following macros must be defined in the file which includes
58
* this one before this file is included:
59
* LUT_TYPE the table type
60
* LUT_TABLE_START pointer to the first entry in the table
61
* LUT_PDE_ENTRIES the beginning of the predefined entries table
62
* LUT_SET_PDE_ENTRY macro which sets an entry to a predefined
64
* LUT_SET_DEFAULT_VALUES macro which sets an entry to the default
66
* data structure names:
67
* DD_LUT_ENTRY_STR devPriv data structure def
68
* MI_LUT_ENTRY_STR table entry data structure def
69
* PEX_LUT_ENTRY_STR pex data structure def
70
* renderer dynamics changes bit:
75
* table info dependent on drawable type (SI only supports one type):
76
* LUT_0_DEFINABLE_ENTRIES
77
* LUT_0_NUM_PREDEFINED
78
* LUT_0_PREDEFINED_MIN
79
* LUT_0_PREDEFINED_MAX
81
* procedure definition flags:
82
* define the ones whose definitions you want to use from this file
83
* procedure definition names:
84
* define the names of the procedures to use for the lut
87
extern ddpex4rtn miDealWithDynamics(); /* in level4/miDynamics.c */
89
/* get pointer to first legal entry in the table */
90
#define FIRST_ENTRY( pheader ) \
91
LUT_TABLE_START(pheader)
93
#define SET_TABLE_INFO( drawType, pInfo ) \
96
(pInfo)->definableEntries = \
97
LUT_0_DEFINABLE_ENTRIES; \
98
(pInfo)->numPredefined = \
99
LUT_0_NUM_PREDEFINED; \
100
(pInfo)->predefinedMin = \
101
LUT_0_PREDEFINED_MIN; \
102
(pInfo)->predefinedMax = \
103
LUT_0_PREDEFINED_MAX; \
106
/* the following procedure definitions are useful for all SI lut types */
107
/* replace them in the mi*LUT.c files if these are not appropriate */
109
/* don't use special procs for these - use the general ones called
110
* directly by diPEX */
113
extern ddpex43rtn FreeLUT();
114
#define LUT_FREE FreeLUT
115
#endif /* LUT_USE_FREE */
117
#ifdef LUT_USE_INQ_PREDEF
118
extern ddpex43rtn InquireLUTPredEntries();
119
#define LUT_INQ_PREDEF InquireLUTPredEntries
120
#endif /* LUT_USE_INQ_PREDEF */
122
#ifdef LUT_USE_INQ_ENTRIES
123
extern ddpex43rtn InquireLUTEntries();
124
#define LUT_INQ_ENTRIES InquireLUTEntries
125
#endif /* LUT_USE_INQ_ENTRIES */
128
The default entry: uninitialized, non-static, this scratch
129
structure is kept around so that we can fill it with default
130
data and return its address from routines like those made
131
from LUT_INQ_ENTRY_ADDRESS
133
static MI_LUT_ENTRY_STR def_entry;
139
LUT_COPY (pSrcLUT, pDestLUT)
141
diLUTHandle pSrcLUT; /* source lookup table */
142
diLUTHandle pDestLUT; /* destination lookup table */
145
MILUT_DEFINE_HEADER(pSrcLUT, srcHeader);
146
MILUT_DEFINE_HEADER(pDestLUT, destHeader);
147
MI_LUT_ENTRY_STR *pentry;
152
ErrorF( "\ncopy src lut %d type %d\n", pSrcLUT->id, pSrcLUT->lutType);
153
ErrorF( "\ncopy dest lut %d type %d\n", pDestLUT->id, pDestLUT->lutType);
156
/* set all entries to undefined */
157
pentry = LUT_TABLE_START(destHeader);
158
MILUT_SET_STATUS(pentry, MILUT_ALLOC_ENTS(destHeader), MILUT_UNDEFINED, MI_FALSE);
161
mibcopy(LUT_TABLE_START(srcHeader), LUT_TABLE_START(destHeader),
162
sizeof(MI_LUT_ENTRY_STR) * MILUT_ALLOC_ENTS(srcHeader));
164
MILUT_NUM_ENTS(destHeader) = MILUT_NUM_ENTS(srcHeader);
166
err = destHeader->ops[MILUT_REQUEST_OP(milut_mod_call_back)](pDestLUT,
167
MILUT_START_INDEX(destHeader), MILUT_DEF_ENTS(destHeader), MILUT_COPY_MOD);
168
/* check err here if your call back proc can return an error */
172
#endif /* LUT_USE_COPY */
174
#ifdef LUT_USE_INQ_INFO
176
LUT_INQ_INFO (pDrawable, pLUTinfo)
178
DrawablePtr pDrawable;/* pointer to example drawable */
180
ddTableInfo *pLUTinfo; /* table information */
185
ErrorF( "\ninquire info, table type %d \n", LUT_TYPE );
188
MI_WHICHDRAW(pDrawable, drawtype);
189
SET_TABLE_INFO( drawtype, pLUTinfo );
193
#endif /* LUT_USE_INQ_INFO */
195
#ifdef LUT_USE_INQ_IND
197
LUT_INQ_IND (pLUT, pNumIndices, pBuffer)
199
diLUTHandle pLUT; /* lut handle */
201
ddULONG *pNumIndices; /* number of indices in list */
202
ddBufferPtr pBuffer; /* list of table indices */
204
MILUT_DEFINE_HEADER(pLUT, pheader);
205
register ddUSHORT macks; /* number of definable entries */
206
register ddTableIndex *pb;
207
MI_LUT_ENTRY_STR *pentry;
210
ErrorF( "\n inquire indices lut %d type %d\n", pLUT->id, pLUT->lutType);
213
PU_CHECK_BUFFER_SIZE(pBuffer,MILUT_NUM_ENTS(pheader) * sizeof(ddTableIndex));
214
*pNumIndices = MILUT_NUM_ENTS(pheader);
215
pBuffer->dataSize = *pNumIndices * sizeof(ddTableIndex);
216
pb = (ddTableIndex *)(pBuffer->pBuf);
218
pentry = FIRST_ENTRY(pheader);
220
for ( macks = MILUT_DEF_ENTS(pheader);
221
macks > 0; macks--, pentry++ )
222
if (pentry->entry_info.status != MILUT_UNDEFINED)
223
*pb++ = pentry->entry_info.index;
227
#endif /* LUT_USE_INQ_IND */
229
#ifdef LUT_USE_INQ_ENTRY
231
LUT_INQ_ENTRY (pLUT, index, valueType, pStatus, pBuffer)
233
diLUTHandle pLUT; /* lut handle */
234
ddTableIndex index; /* index of entry to get */
235
ddUSHORT valueType; /* SET or REALIZED */
237
ddUSHORT *pStatus; /* entry status */
238
ddBufferPtr pBuffer; /* table entry */
240
MILUT_DEFINE_HEADER(pLUT, pheader);
241
MI_LUT_ENTRY_STR *pentry, *plast;
245
ErrorF( "\ninquire entry lut %d type %d\n", pLUT->id, pLUT->lutType);
248
PU_CHECK_BUFFER_SIZE(pBuffer, sizeof(PEX_LUT_ENTRY_STR));
250
pentry = FIRST_ENTRY(pheader);
251
plast = pentry + MILUT_DEF_ENTS(pheader);
253
MILUT_GET_ENTRY(index, pentry, plast);
255
if ((pentry == NULL) || (pentry->entry_info.status == MILUT_UNDEFINED))
257
*pStatus = PEXDefaultEntry;
258
pentry = FIRST_ENTRY(pheader);
259
MILUT_GET_ENTRY(MILUT_DEFAULT_INDEX(pheader), pentry, plast);
262
/* default entry doesn't exist - get the default values */
263
LUT_SET_DEFAULT_VALUES(&def_entry);
266
else if (pentry->entry_info.status == MILUT_UNDEFINED)
268
/* default entry is undefined - get default values */
269
LUT_SET_DEFAULT_VALUES(&def_entry);
273
*pStatus = PEXDefinedEntry;
277
pheader->ops[MILUT_REQUEST_OP(milut_copy_mi_to_pex)](pheader, valueType, pentry, &pb);
279
pBuffer->dataSize = pb - pBuffer->pBuf;
283
#endif /* LUT_USE_INQ_ENTRY */
285
#ifdef LUT_USE_SET_ENTRIES
287
LUT_SET_ENTRIES (pLUT, start, numEntries, pEntries)
289
diLUTHandle pLUT; /* lut handle */
290
ddTableIndex start; /* index of first entry to set */
291
ddUSHORT numEntries; /* number of entries to set */
292
ddPointer pEntries; /* list of entries */
294
MILUT_DEFINE_HEADER(pLUT, pheader);
295
MI_LUT_ENTRY_STR *pentry, *plast, *psave;
296
PEX_LUT_ENTRY_STR *psrc;
298
int freecount1 = 0, freecount2;
303
ErrorF( "\nset entries lut %d type %d\n", pLUT->id, pLUT->lutType);
306
psrc = (PEX_LUT_ENTRY_STR *) pEntries;
307
pentry = FIRST_ENTRY(pheader);
308
plast = pentry + MILUT_DEF_ENTS(pheader);
310
/* check for a place to put the entries and check them for errors */
311
/* this is set up to work for tables with contiguous index
312
* values most efficiently. it will work for sparse tables, too
314
for (i = start; i < (start + numEntries); i++)
316
/* starting at current pentry, see if entry 'i' is after it */
318
MILUT_GET_ENTRY(i, pentry, plast);
322
/* make sure the entry wasn't before pentry
323
* by starting at the beginning and looking until where
326
pentry = FIRST_ENTRY(pheader);
327
MILUT_GET_ENTRY(i, pentry, psave);
330
/* no entry defined with this index
331
* put one in by looking for the first
332
* undefined entry. this has no intelligence
335
pentry = FIRST_ENTRY(pheader);
336
plast = pentry + MILUT_DEF_ENTS(pheader);
337
freecount2 = freecount1;
338
while ((pentry < plast) &&
339
((pentry->entry_info.status != MILUT_UNDEFINED) || freecount2))
341
if (pentry->entry_info.status == MILUT_UNDEFINED)
346
/* couldn't find a place for it */
349
/* keep count of free places found so far */
353
/* check the entry and increment the source pointer */
354
if ((err = pheader->ops[MILUT_REQUEST_OP(milut_entry_check)](pheader, &psrc)) != Success)
358
psrc = (PEX_LUT_ENTRY_STR *) pEntries;
359
for (i = start; i < (start + numEntries); i++)
361
/* starting at current pentry, see if entry 'i' is after it */
363
MILUT_GET_ENTRY(i, pentry, plast);
367
/* make sure the entry wasn't before pentry
368
* by starting at the beginning and looking until where
371
pentry = FIRST_ENTRY(pheader);
372
MILUT_GET_ENTRY(i, pentry, psave);
375
/* no entry defined with this index
376
* put one in by looking for the first
377
* undefined entry. this has no intelligence
380
pentry = FIRST_ENTRY(pheader);
381
plast = pentry + MILUT_DEF_ENTS(pheader);
382
while ((pentry < plast) &&
383
(pentry->entry_info.status != MILUT_UNDEFINED))
386
/* this shouldn't happen since it was
387
* checked above, but just in case..
388
* this is where one of those ASSURE
389
* tests can be useful
395
if (pentry->entry_info.status == MILUT_UNDEFINED)
396
MILUT_NUM_ENTS(pheader)++;
397
pentry->entry_info.status = MILUT_DEFINED;
398
pentry->entry_info.index = i;
400
ps = (ddPointer)psrc;
401
pheader->ops[MILUT_REQUEST_OP(milut_copy_pex_to_mi)](pheader, &ps, pentry);
403
psrc = (PEX_LUT_ENTRY_STR *)ps;
406
err = pheader->ops[MILUT_REQUEST_OP(milut_mod_call_back)](pLUT,
407
start, numEntries, MILUT_SET_MOD);
409
/* check err here if your call back proc can return an error */
413
#endif /* LUT_USE_SET_ENTRIES */
415
#ifdef LUT_USE_DEL_ENTRIES
417
LUT_DEL_ENTRIES (pLUT, start, numEntries)
419
diLUTHandle pLUT; /* lut handle */
420
ddUSHORT start; /* index of first entry to delete */
421
ddUSHORT numEntries; /* number of entries in range */
424
MILUT_DEFINE_HEADER(pLUT, pheader);
425
MI_LUT_ENTRY_STR *pentry, *plast, *psave;
429
ErrorF( "\ndelete entries lut %d type %d\n", pLUT->id, pLUT->lutType);
432
pentry = FIRST_ENTRY(pheader);
433
plast = pentry + MILUT_DEF_ENTS(pheader);
435
/* invoke the call back before deleting the entries and changing
438
err = pheader->ops[MILUT_REQUEST_OP(milut_mod_call_back)](pLUT,
439
start, numEntries, MILUT_DEL_MOD);
441
/* loop through and set each entry to undefined
442
* this works most efficiently if the entries are stored
443
* in the lut contiguously since MILUT_GET_ENTRY starts
444
* where pentry points then searches forward colour_approxarly
446
for (; numEntries > 0; start++, numEntries--)
449
MILUT_GET_ENTRY(start, pentry, plast);
453
/* make sure the entry wasn't before pentry */
454
pentry = FIRST_ENTRY(pheader);
455
MILUT_GET_ENTRY(start, pentry, psave);
460
if (pentry->entry_info.status != MILUT_UNDEFINED)
462
MILUT_NUM_ENTS(pheader)--;
463
pentry->entry_info.status = MILUT_UNDEFINED;
470
/* check err here if your call back proc can return an error */
474
#endif /* LUT_USE_DEL_ENTRIES */
476
#ifdef LUT_USE_INQ_ENTRY_ADDRESS
478
LUT_INQ_ENTRY_ADDRESS (LUTtype, pLUT, index, pStatus, ppEntry)
480
ddUSHORT LUTtype; /* lookup table type use this if pLUT is NULL */
481
diLUTHandle pLUT; /* lut handle */
482
ddTableIndex index; /* index of entry to get */
484
ddUSHORT *pStatus; /* entry status */
485
ddPointer *ppEntry; /* table entry */
487
miLUTHeader *pheader;
488
MI_LUT_ENTRY_STR *pentry, *plast;
491
ErrorF( "\ninquire entry address lut type %d\n", LUTtype);
498
/* get the default values */
499
LUT_SET_DEFAULT_VALUES(&def_entry);
500
*ppEntry = (ddPointer)&def_entry;
504
pheader = MILUT_HEADER(pLUT);
505
pentry = FIRST_ENTRY(pheader);
506
plast = pentry + MILUT_DEF_ENTS(pheader);
508
MILUT_GET_ENTRY(index, pentry, plast);
509
if ((pentry == NULL) || (pentry->entry_info.status == MILUT_UNDEFINED))
511
/* get the default entry */
512
*pStatus = PEXDefaultEntry;
513
pentry = FIRST_ENTRY(pheader);
514
MILUT_GET_ENTRY(MILUT_DEFAULT_INDEX(pheader), pentry, plast);
517
/* default entry doesn't exist - get the default values */
518
LUT_SET_DEFAULT_VALUES(&def_entry);
519
*ppEntry = (ddPointer)&def_entry;
521
else if (pentry->entry_info.status == MILUT_UNDEFINED)
523
/* default entry is undefined - get default values */
524
LUT_SET_DEFAULT_VALUES(&def_entry);
525
*ppEntry = (ddPointer)&def_entry;
527
else /* the default entry is good */
528
*ppEntry = (ddPointer)pentry;
529
} else /* the entry was found and is defined */
531
*pStatus = PEXDefinedEntry;
532
*ppEntry = (ddPointer)pentry;
537
#endif /* LUT_USE_INQ_ENTRY_ADDRESS */
539
#ifdef LUT_USE_MOD_CALL_BACK
541
LUT_MOD_CALL_BACK(pLUT, start, numEntries, mod)
543
ddTableIndex start; /* index of first entry to set */
544
ddUSHORT numEntries; /* number of entries to set */
545
ddUSHORT mod; /* modification: copy, set, delete */
547
MILUT_DEFINE_HEADER(pLUT, pheader);
549
ddRendererPtr *pprend;
550
diWKSHandle *phandle;
554
/* set change flags in renderer so ValidateRenderer will
555
* know to update the ddContext with changes
556
* add to here and calls to hardware, etc. to realize
559
pprend = (ddRendererPtr *)pheader->rendRefList->pList;
560
for (i=0; i<pheader->rendRefList->numObj; i++, pprend++)
561
(*pprend)->tablesChanges |= LUT_REND_DYN_BIT;
563
/* for view luts: this wks list only identifies the wks for
564
* which this is the current view. The wks is not included
565
* in the list of the requested view lut
567
if (pheader->wksRefList->numObj)
569
phandle = (diWKSHandle *)pheader->wksRefList->pList;
570
for (i=0; i<pheader->wksRefList->numObj; i++, phandle++)
572
pwks = (miWksPtr)((*phandle)->deviceData);
573
pwks->pRend->tablesChanges |= LUT_REND_DYN_BIT;
580
if (pheader->wksRefList->numObj)
581
err = miDealWithDynamics( DYNAMIC, pheader->wksRefList );
586
#endif /* LUT_USE_MOD_CALL_BACK */
589
#ifdef LUT_USE_CREATE
591
LUT_CREATE (pLUT, pheader)
593
diLUTHandle pLUT; /* lut handle */
594
miLUTHeader *pheader; /* lut header */
598
MI_LUT_ENTRY_STR *pentry;
599
DD_LUT_ENTRY_STR *pdeentry;
602
ErrorF( "\ncreate lut %d type %d\n", pLUT->id, pLUT->lutType);
605
MILUT_START_INDEX(pheader) = LUT_START_INDEX;
606
MILUT_DEFAULT_INDEX(pheader) = LUT_DEFAULT_INDEX;
607
MILUT_NUM_ENTS(pheader) = 0;
608
SET_TABLE_INFO( pheader->drawType, &(pheader->tableInfo) );
610
if (MILUT_ALLOC_ENTS(pheader) == 0)
612
LUT_TABLE_START(pheader) = NULL;
614
else if ( (LUT_TABLE_START(pheader) = (MI_LUT_ENTRY_STR *)
615
xalloc(MILUT_ALLOC_ENTS(pheader) * sizeof(MI_LUT_ENTRY_STR)) )
618
MILUT_DESTROY_HEADER(pheader);
622
pentry = LUT_TABLE_START(pheader);
623
MILUT_SET_STATUS(pentry, MILUT_ALLOC_ENTS(pheader), MILUT_UNDEFINED, MI_TRUE);
625
/* if there are predefined entries, put them in */
626
if (MILUT_PRENUM(pheader))
628
pentry = LUT_TABLE_START(pheader) + MILUT_PREMIN(pheader);
629
pdeentry = &(LUT_PDE_ENTRIES);
631
for (i=MILUT_PREMIN(pheader);
632
i<=MILUT_PREMAX(pheader); i++, pentry++, pdeentry++)
634
pentry->entry_info.status = MILUT_PREDEFINED;
635
pentry->entry_info.index = i;
636
LUT_SET_PDE_ENTRY(pentry, pdeentry);
637
pheader->numDefined++;
641
pheader->ops[MILUT_REQUEST_OP(PEX_CreateLookupTable)] = LUT_CREATE;
642
pheader->ops[MILUT_REQUEST_OP(PEX_CopyLookupTable)] = LUT_COPY;
643
pheader->ops[MILUT_REQUEST_OP(PEX_FreeLookupTable)] = LUT_FREE;
644
pheader->ops[MILUT_REQUEST_OP(PEX_GetTableInfo)] = LUT_INQ_INFO;
645
pheader->ops[MILUT_REQUEST_OP(PEX_GetPredefinedEntries)] = LUT_INQ_PREDEF;
646
pheader->ops[MILUT_REQUEST_OP(PEX_GetDefinedIndices)] = LUT_INQ_IND;
647
pheader->ops[MILUT_REQUEST_OP(PEX_GetTableEntry)] = LUT_INQ_ENTRY;
648
pheader->ops[MILUT_REQUEST_OP(PEX_GetTableEntries)] = LUT_INQ_ENTRIES;
649
pheader->ops[MILUT_REQUEST_OP(PEX_SetTableEntries)] = LUT_SET_ENTRIES;
650
pheader->ops[MILUT_REQUEST_OP(PEX_DeleteTableEntries)] = LUT_DEL_ENTRIES;
651
pheader->ops[MILUT_REQUEST_OP(milut_InquireEntryAddress)] = LUT_INQ_ENTRY_ADDRESS;
652
pheader->ops[MILUT_REQUEST_OP(milut_entry_check)] = LUT_ENTRY_CHECK;
653
pheader->ops[MILUT_REQUEST_OP(milut_copy_pex_to_mi)] = LUT_COPY_PEX_MI;
654
pheader->ops[MILUT_REQUEST_OP(milut_copy_mi_to_pex)] = LUT_COPY_MI_PEX;
655
pheader->ops[MILUT_REQUEST_OP(milut_mod_call_back)] = LUT_MOD_CALL_BACK;
657
pLUT->deviceData = (ddPointer) pheader;
660
#endif /* LUT_USE_CREATE */
662
#endif /* MILUT_PROCS_CI */