libXrender should not try to build into a pure wayland platform.
[platform/upstream/libXrender.git] / src / Filter.c
1 /*
2  *
3  * Copyright © 2002 Keith Packard
4  *
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.
14  *
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.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 #include "Xrenderint.h"
28
29 XFilters *
30 XRenderQueryFilters (Display *dpy, Drawable drawable)
31 {
32     XRenderExtDisplayInfo               *info = XRenderFindDisplay (dpy);
33     XRenderInfo                 *xri;
34     xRenderQueryFiltersReq      *req;
35     xRenderQueryFiltersReply    rep;
36     XFilters                    *filters;
37     char                        *name;
38     char                        len;
39     int                         i;
40     long                        nbytes, nbytesAlias, nbytesName;
41
42     if (!RenderHasExtension (info))
43         return NULL;
44
45     if (!XRenderQueryFormats (dpy))
46         return NULL;
47
48     xri = info->info;
49     if (xri->minor_version < 6)
50         return NULL;
51
52     LockDisplay (dpy);
53     GetReq (RenderQueryFilters, req);
54     req->reqType = info->codes->major_opcode;
55     req->renderReqType = X_RenderQueryFilters;
56     req->drawable = drawable;
57     if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
58     {
59         UnlockDisplay (dpy);
60         SyncHandle ();
61         return NULL;
62     }
63     /*
64      * Compute total number of bytes for filter names
65      */
66     nbytes = (long)rep.length << 2;
67     nbytesAlias = rep.numAliases * 2;
68     if (rep.numAliases & 1)
69         nbytesAlias += 2;
70     nbytesName = nbytes - nbytesAlias;
71
72     /*
73      * Allocate one giant block for the whole data structure
74      */
75     filters = Xmalloc (sizeof (XFilters) +
76                        rep.numFilters * sizeof (char *) +
77                        rep.numAliases * sizeof (short) +
78                        nbytesName);
79
80     if (!filters)
81     {
82         _XEatData (dpy, (unsigned long) rep.length << 2);
83         UnlockDisplay (dpy);
84         SyncHandle ();
85         return NULL;
86     }
87
88     /*
89      * Layout:
90      *  XFilters
91      *  numFilters  char * pointers to filter names
92      *  numAliases  short alias values
93      *  nbytesName  char strings
94      */
95
96     filters->nfilter = rep.numFilters;
97     filters->nalias = rep.numAliases;
98     filters->filter = (char **) (filters + 1);
99     filters->alias = (short *) (filters->filter + rep.numFilters);
100     name = (char *) (filters->alias + rep.numAliases);
101
102     /*
103      * Read the filter aliases
104      */
105     _XRead16Pad (dpy, filters->alias, 2 * rep.numAliases);
106
107     /*
108      * Read the filter names
109      */
110     for (i = 0; i < rep.numFilters; i++)
111     {
112         int     l;
113         _XRead (dpy, &len, 1);
114         l = len & 0xff;
115         filters->filter[i] = name;
116         _XRead (dpy, name, l);
117         name[l] = '\0';
118         name += l + 1;
119     }
120     i = name - (char *) (filters->alias + rep.numAliases);
121
122     if (i & 3)
123         _XEatData (dpy, 4 - (i & 3));
124
125     UnlockDisplay (dpy);
126     SyncHandle ();
127     return filters;
128 }
129
130 void
131 XRenderSetPictureFilter  (Display   *dpy,
132                           Picture   picture,
133                           const char *filter,
134                           XFixed    *params,
135                           int       nparams)
136 {
137     XRenderExtDisplayInfo               *info = XRenderFindDisplay (dpy);
138     xRenderSetPictureFilterReq  *req;
139     int                         nbytes = strlen (filter);
140
141     RenderSimpleCheckExtension (dpy, info);
142     LockDisplay(dpy);
143     GetReq(RenderSetPictureFilter, req);
144     req->reqType = info->codes->major_opcode;
145     req->renderReqType = X_RenderSetPictureFilter;
146     req->picture = picture;
147     req->nbytes = nbytes;
148     req->length += ((nbytes + 3) >> 2) + nparams;
149     Data (dpy, filter, nbytes);
150     Data (dpy, (_Xconst char *)params, nparams << 2);
151     UnlockDisplay(dpy);
152     SyncHandle();
153 }