1
/* $Xorg: pexLut.c,v 1.4 2001/02/09 02:04:14 xorgcvs Exp $ */
4
Copyright 1989, 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 1989, 1990, 1991 by Sun Microsystems, Inc.
33
Permission to use, copy, modify, and distribute this software and its
34
documentation for any purpose and without fee is hereby granted,
35
provided that the above copyright notice appear in all copies and that
36
both that copyright notice and this permission notice appear in
37
supporting documentation, and that the name of Sun Microsystems,
38
not be used in advertising or publicity pertaining to distribution
39
of the software without specific, written prior permission.
41
SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
42
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
43
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
44
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
45
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
46
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
50
/* $XFree86: xc/programs/Xserver/PEX5/dipex/objects/pexLut.c,v 3.9 2001/12/14 19:57:43 dawes Exp $ */
54
* PEXCreateLookupTable
58
* PEXGetPredefinedEntries
59
* PEXGetDefinedIndices
63
* PEXDeleteTableEntries
72
#include "pexLookup.h"
76
#define VALID_TABLETYPE(type) ((type > 0) && (type <= PEXMaxTableType))
89
/*++ PEXCreateLookupTable
92
PEXCreateLookupTable (cntxtPtr, strmPtr)
93
pexContext *cntxtPtr; /* context pointer */
94
pexCreateLookupTableReq *strmPtr; /* stream pointer */
97
ErrorCode err = Success;
98
DrawablePtr pdraw = 0;
99
diLUTHandle lutptr = 0;
101
if (!VALID_TABLETYPE(strmPtr->tableType))
102
PEX_ERR_EXIT(BadValue,strmPtr->tableType,cntxtPtr);
104
if (!LegalNewID(strmPtr->lut, cntxtPtr->client))
105
PEX_ERR_EXIT(BadIDChoice,strmPtr->lut,cntxtPtr);
107
LU_DRAWABLE(strmPtr->drawableExample, pdraw);
109
lutptr = (diLUTHandle) xalloc ((unsigned long)sizeof(ddLUTResource));
110
if (!lutptr) PEX_ERR_EXIT (BadAlloc,0,cntxtPtr);
111
lutptr->id = strmPtr->lut;
112
lutptr->lutType = strmPtr->tableType;
114
err = CreateLUT( pdraw, lutptr);
116
xfree((pointer)lutptr);
117
PEX_ERR_EXIT(err,0,cntxtPtr);
120
ADDRESOURCE (strmPtr->lut, PEXLutType, lutptr);
124
} /* end-PEXCreateLookupTable() */
126
/*++ PEXCopyLookupTable
129
PEXCopyLookupTable (cntxtPtr, strmPtr)
130
pexContext *cntxtPtr; /* Context Pointer */
131
pexCopyLookupTableReq *strmPtr; /* Stream Pointer */
133
diLUTHandle lsrc, ldest;
134
ErrorCode err = Success;
136
LU_TABLE(strmPtr->src, lsrc);
137
LU_TABLE(strmPtr->dst, ldest);
139
err = CopyLUT (lsrc, ldest);
140
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
144
} /* end-PEXCopyLookupTable() */
146
/*++ PEXFreeLookupTable
149
PEXFreeLookupTable (cntxtPtr, strmPtr)
150
pexContext *cntxtPtr; /* Context Pointer */
151
pexFreeLookupTableReq *strmPtr; /* Stream Pointer */
153
ErrorCode err = Success;
156
if ((strmPtr == NULL) || (strmPtr->id == 0)) {
157
err = PEX_ERROR_CODE(PEXLookupTableError);
158
PEX_ERR_EXIT(err,0,cntxtPtr);
161
LU_TABLE(strmPtr->id, l);
163
FreeResource(strmPtr->id, RT_NONE);
167
} /* end-PEXFreeLookupTable() */
169
/*++ PEXGetTableInfoReq
173
PEXGetTableInfo( cntxtPtr, strmPtr )
174
pexContext *cntxtPtr;
175
pexGetTableInfoReq *strmPtr;
177
ErrorCode err = Success;
179
extern ddBufferPtr pPEXBuffer;
180
pexGetTableInfoReply *reply = (pexGetTableInfoReply *)(pPEXBuffer->pHead);
182
if (!VALID_TABLETYPE(strmPtr->tableType))
183
PEX_ERR_EXIT(BadValue,strmPtr->tableType,cntxtPtr);
185
LU_DRAWABLE(strmPtr->drawableExample, pdraw);
187
SETUP_INQ(pexGetTableInfoReply);
189
err = InquireLUTInfo( pdraw, strmPtr->tableType,
190
(pexTableInfo *)&(reply->definableEntries));
191
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
194
WritePEXReplyToClient( cntxtPtr, strmPtr,
195
sizeof(pexGetTableInfoReply) + reply->length,
199
} /* end-PEXGetTableInfo() */
201
/*++ PEXGetPredefinedEntries
205
PEXGetPredefinedEntries( cntxtPtr, strmPtr )
206
pexContext *cntxtPtr;
207
pexGetPredefinedEntriesReq *strmPtr;
209
ErrorCode err = Success;
210
extern ddBufferPtr pPEXBuffer;
211
DrawablePtr pdraw = 0;
212
ddULONG numEntries = (ddULONG)(strmPtr->count);
214
if (!VALID_TABLETYPE(strmPtr->tableType))
215
PEX_ERR_EXIT(BadValue,strmPtr->tableType,cntxtPtr);
217
LU_DRAWABLE(strmPtr->drawableExample, pdraw);
219
SETUP_INQ(pexGetPredefinedEntriesReply);
221
err = InquireLUTPredEntries( pdraw, strmPtr->tableType,
222
strmPtr->start, strmPtr->count,
223
&numEntries, pPEXBuffer);
224
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
227
SETUP_VAR_REPLY(pexGetPredefinedEntriesReply);
228
reply->numEntries = numEntries;
229
WritePEXBufferReply(pexGetPredefinedEntriesReply);
233
} /* end-PEXGetPredefinedEntries() */
235
/*++ PEXGetDefinedIndices
239
PEXGetDefinedIndices( cntxtPtr, strmPtr)
240
pexContext *cntxtPtr;
241
pexGetDefinedIndicesReq *strmPtr;
243
ErrorCode err = Success;
245
extern ddBufferPtr pPEXBuffer;
246
ddULONG numIndices = 0;
248
LU_TABLE(strmPtr->id, pf);
250
SETUP_INQ(pexGetDefinedIndicesReply);
252
err = InquireLUTIndices( pf, &numIndices, pPEXBuffer);
253
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
256
SETUP_VAR_REPLY(pexGetDefinedIndicesReply);
257
reply->numIndices = numIndices;
258
WritePEXBufferReply(pexGetDefinedIndicesReply);
262
} /* end-PEXGetDefinedIndices() */
264
/*++ PEXGetTableEntry
268
PEXGetTableEntry( cntxtPtr, strmPtr )
269
pexContext *cntxtPtr;
270
pexGetTableEntryReq *strmPtr;
272
ErrorCode err = Success;
274
extern ddBufferPtr pPEXBuffer;
277
LU_TABLE(strmPtr->lut, pf);
279
SETUP_INQ(pexGetTableEntryReply);
281
err = InquireLUTEntry( pf, strmPtr->index, strmPtr->valueType,
282
&status, pPEXBuffer);
283
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
286
* If this is a font table, we have to convert font handles to font ids.
289
if (pf->lutType == PEXTextFontLUT) {
291
pexTextFontEntry *ptfe = (pexTextFontEntry *)(pPEXBuffer->pBuf);
292
pexFont *ptr = (pexFont *)(ptfe + 1);
293
for (i=0; i<ptfe->numFonts; i++, ptr++)
294
*ptr = ((diFontHandle) *ptr)->id;
298
SETUP_VAR_REPLY(pexGetTableEntryReply);
299
reply->status = status;
300
reply->tableType = pf->lutType;
301
WritePEXBufferReply(pexGetTableEntryReply);
305
} /* end-PEXGetTableEntry() */
307
/*++ PEXGetTableEntries
310
PEXGetTableEntries( cntxtPtr, strmPtr )
311
pexContext *cntxtPtr;
312
pexGetTableEntriesReq *strmPtr;
314
ErrorCode err = Success;
317
extern ddBuffer *pPEXBuffer;
319
LU_TABLE(strmPtr->lut, pf);
321
SETUP_INQ(pexGetTableEntriesReply);
323
err = InquireLUTEntries( pf, strmPtr->start, strmPtr->count,
324
strmPtr->valueType, &numEntries, pPEXBuffer);
325
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
328
* If this is a font table, we have to convert font handles to font ids.
331
if (pf->lutType == PEXTextFontLUT) {
333
pexTextFontEntry *ptfe = (pexTextFontEntry *)(pPEXBuffer->pBuf);
334
for (i=0; i<strmPtr->count; i++) {
335
pexFont *ptr = (pexFont *)(ptfe + 1);
336
for (j=0; j<ptfe->numFonts; j++, ptr++)
337
*ptr = ((diFontHandle) *ptr)->id;
338
ptfe = (pexTextFontEntry *) ptr;
343
SETUP_VAR_REPLY(pexGetTableEntriesReply);
344
reply->tableType = pf->lutType;
345
reply->numEntries = numEntries;
346
WritePEXBufferReply(pexGetTableEntriesReply);
350
} /* end-PEXGetTableEntries() */
352
/*++ PEXSetTableEntries
356
PEXSetTableEntries( cntxtPtr, strmPtr )
357
pexContext *cntxtPtr;
358
pexSetTableEntriesReq *strmPtr;
360
ErrorCode err = Success;
363
LU_TABLE(strmPtr->lut, pf);
364
CHECK_FP_FORMAT(strmPtr->fpFormat);
367
If this is a font table, lookup font id's and stuff pointers into
368
the that longword, so ddpex gets its handles instead of ids.
370
if (pf->lutType == PEXTextFontLUT) {
373
pexTextFontEntry *ptfe = (pexTextFontEntry *)(strmPtr + 1);
374
for (i=0; i<strmPtr->count; i++) {
375
pexFont *ptr = (pexFont *)(ptfe + 1);
376
for (j=0; j<ptfe->numFonts; j++, ptr++) {
377
LU_PEXFONT(*ptr, fh);
380
ptfe = (pexTextFontEntry *) ptr;
384
err = SetLUTEntries( pf, strmPtr->start, strmPtr->count,
385
(ddPointer)(strmPtr + 1));
386
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
389
} /* end-PEXSetTableEntries() */
391
/*++ PEXDeleteTableEntries
395
PEXDeleteTableEntries( cntxtPtr, strmPtr )
396
pexContext *cntxtPtr;
397
pexDeleteTableEntriesReq *strmPtr;
399
ErrorCode err = Success;
402
LU_TABLE(strmPtr->lut, pf);
403
err = DeleteLUTEntries (pf, strmPtr->start, strmPtr->count);
404
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
407
} /* end-PEXDeleteTableEntries() */
409
/*++ PEXChangeTableValues
412
PEXChangeTableValues (cntxtPtr, strmPtr)
413
pexContext *cntxtPtr; /* context pointer */
414
pexChangeTableValuesReq *strmPtr; /* stream pointer */
416
ErrorCode err = Success;
419
LU_TABLE(strmPtr->lut, pf);
420
CHECK_FP_FORMAT(strmPtr->fpFormat);
423
If this is a font table, lookup font id's and stuff pointers into
424
the that longword, so ddpex gets its handles instead of ids.
426
if ( (pf->lutType == PEXTextFontLUT) &&
427
(strmPtr->TableMask == PEXLUTVTextFontGroup) )
431
pexTextFontEntry *ptfe = (pexTextFontEntry *)(strmPtr + 1);
432
pexFont *ptr = (pexFont *)(ptfe + 1);
433
for (j=0; j<ptfe->numFonts; j++, ptr++) {
434
LU_PEXFONT(*ptr, fh);
439
/* call to change table values routine goes here, this is a shell
440
for this routine but should contain all necessary information
441
to process the request
443
err = ChangeTableValues ( pf, strmPtr->length, strmPtr->index,
444
strmPtr->TableMask, (ddPointer)(strmPtr + 1));
446
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
449
} /* end-PEXChangeTableValues() */
451
/*++ PEXGetTableValues
454
PEXGetTableValues( cntxtPtr, strmPtr )
455
pexContext *cntxtPtr;
456
pexGetTableValuesReq *strmPtr;
458
ErrorCode err = Success;
462
extern ddBuffer *pPEXBuffer;
464
CHECK_FP_FORMAT(strmPtr->fpFormat);
465
LU_TABLE(strmPtr->lut, pf);
467
SETUP_INQ(pexGetTableValuesReply);
469
/* Place holder for ddpex interface
470
err = GetLUTValues( pf, strmPtr->index, strmPtr->TableMask,
471
strmPtr->valueType, &numValues, &status, pPEXBuffer);
474
if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
477
* If this is a font table, we have to convert font handles to font ids.
480
if ( (pf->lutType == PEXTextFontLUT) &&
481
(strmPtr->TableMask == PEXLUTVTextFontGroup) )
484
pexTextFontEntry *ptfe = (pexTextFontEntry *)(pPEXBuffer->pBuf);
485
pexFont *ptr = (pexFont *)(ptfe + 1);
486
for (j=0; j<ptfe->numFonts; j++, ptr++)
487
*ptr = ((diFontHandle) *ptr)->id;
491
SETUP_VAR_REPLY(pexGetTableValuesReply);
492
reply->tableType = pf->lutType;
493
reply->numValues = numValues;
494
reply->status = status;
495
WritePEXBufferReply(pexGetTableValuesReply);
499
} /* end-PEXGetTableValues() */