3 * Copyright © 2002 Keith Packard
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Keith Packard not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission. Keith Packard makes no
12 * representations about the suitability of this software for any purpose. It
13 * is provided "as is" without express or implied warranty.
15 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
27 #include "Xrenderint.h"
31 XRenderQueryFilters (Display *dpy, Drawable drawable)
33 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
35 xRenderQueryFiltersReq *req;
36 xRenderQueryFiltersReply rep;
41 unsigned long nbytes, nbytesAlias, nbytesName;
43 if (!RenderHasExtension (info))
46 if (!XRenderQueryFormats (dpy))
50 if (xri->minor_version < 6)
54 GetReq (RenderQueryFilters, req);
55 req->reqType = info->codes->major_opcode;
56 req->renderReqType = X_RenderQueryFilters;
57 req->drawable = drawable;
58 if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
66 * Limit each component of combined size to 1/4 the max, which is far
67 * more than they should ever possibly need.
69 if ((rep.length < (INT_MAX >> 2)) &&
70 (rep.numFilters < ((INT_MAX / 4) / sizeof (char *))) &&
71 (rep.numAliases < ((INT_MAX / 4) / sizeof (short)))) {
73 * Compute total number of bytes for filter names
75 nbytes = (unsigned long)rep.length << 2;
76 nbytesAlias = rep.numAliases * 2;
77 if (rep.numAliases & 1)
79 nbytesName = nbytes - nbytesAlias;
82 * Allocate one giant block for the whole data structure
84 filters = Xmalloc (sizeof (XFilters) +
85 (rep.numFilters * sizeof (char *)) +
86 (rep.numAliases * sizeof (short)) +
93 _XEatDataWords(dpy, rep.length);
102 * numFilters char * pointers to filter names
103 * numAliases short alias values
104 * nbytesName char strings
107 filters->nfilter = rep.numFilters;
108 filters->nalias = rep.numAliases;
109 filters->filter = (char **) (filters + 1);
110 filters->alias = (short *) (filters->filter + rep.numFilters);
111 name = (char *) (filters->alias + rep.numAliases);
114 * Read the filter aliases
116 _XRead16Pad (dpy, filters->alias, 2 * rep.numAliases);
119 * Read the filter names
121 for (i = 0; i < rep.numFilters; i++)
124 _XRead (dpy, &len, 1);
126 filters->filter[i] = name;
127 _XRead (dpy, name, l);
131 i = name - (char *) (filters->alias + rep.numAliases);
134 _XEatData (dpy, 4 - (i & 3));
142 XRenderSetPictureFilter (Display *dpy,
148 XRenderExtDisplayInfo *info = XRenderFindDisplay (dpy);
149 xRenderSetPictureFilterReq *req;
150 int nbytes = strlen (filter);
152 RenderSimpleCheckExtension (dpy, info);
154 GetReq(RenderSetPictureFilter, req);
155 req->reqType = info->codes->major_opcode;
156 req->renderReqType = X_RenderSetPictureFilter;
157 req->picture = picture;
158 req->nbytes = nbytes;
159 req->length += ((nbytes + 3) >> 2) + nparams;
160 Data (dpy, filter, nbytes);
161 Data (dpy, (_Xconst char *)params, nparams << 2);