xref: /OK3568_Linux_fs/external/xserver/randr/rrdispatch.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright © 2006 Keith Packard
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun  * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun  * the above copyright notice appear in all copies and that both that copyright
7*4882a593Smuzhiyun  * notice and this permission notice appear in supporting documentation, and
8*4882a593Smuzhiyun  * that the name of the copyright holders not be used in advertising or
9*4882a593Smuzhiyun  * publicity pertaining to distribution of the software without specific,
10*4882a593Smuzhiyun  * written prior permission.  The copyright holders make no representations
11*4882a593Smuzhiyun  * about the suitability of this software for any purpose.  It is provided "as
12*4882a593Smuzhiyun  * is" without express or implied warranty.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15*4882a593Smuzhiyun  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16*4882a593Smuzhiyun  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17*4882a593Smuzhiyun  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18*4882a593Smuzhiyun  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19*4882a593Smuzhiyun  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20*4882a593Smuzhiyun  * OF THIS SOFTWARE.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #include "randrstr.h"
24*4882a593Smuzhiyun #include "protocol-versions.h"
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun Bool
RRClientKnowsRates(ClientPtr pClient)27*4882a593Smuzhiyun RRClientKnowsRates(ClientPtr pClient)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun     rrClientPriv(pClient);
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun     return version_compare(pRRClient->major_version, pRRClient->minor_version,
32*4882a593Smuzhiyun                            1, 1) >= 0;
33*4882a593Smuzhiyun }
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun static int
ProcRRQueryVersion(ClientPtr client)36*4882a593Smuzhiyun ProcRRQueryVersion(ClientPtr client)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun     xRRQueryVersionReply rep = {
39*4882a593Smuzhiyun         .type = X_Reply,
40*4882a593Smuzhiyun         .sequenceNumber = client->sequence,
41*4882a593Smuzhiyun         .length = 0
42*4882a593Smuzhiyun     };
43*4882a593Smuzhiyun     REQUEST(xRRQueryVersionReq);
44*4882a593Smuzhiyun     rrClientPriv(client);
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xRRQueryVersionReq);
47*4882a593Smuzhiyun     pRRClient->major_version = stuff->majorVersion;
48*4882a593Smuzhiyun     pRRClient->minor_version = stuff->minorVersion;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun     if (version_compare(stuff->majorVersion, stuff->minorVersion,
51*4882a593Smuzhiyun                         SERVER_RANDR_MAJOR_VERSION,
52*4882a593Smuzhiyun                         SERVER_RANDR_MINOR_VERSION) < 0) {
53*4882a593Smuzhiyun         rep.majorVersion = stuff->majorVersion;
54*4882a593Smuzhiyun         rep.minorVersion = stuff->minorVersion;
55*4882a593Smuzhiyun     }
56*4882a593Smuzhiyun     else {
57*4882a593Smuzhiyun         rep.majorVersion = SERVER_RANDR_MAJOR_VERSION;
58*4882a593Smuzhiyun         rep.minorVersion = SERVER_RANDR_MINOR_VERSION;
59*4882a593Smuzhiyun     }
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun     if (client->swapped) {
62*4882a593Smuzhiyun         swaps(&rep.sequenceNumber);
63*4882a593Smuzhiyun         swapl(&rep.length);
64*4882a593Smuzhiyun         swapl(&rep.majorVersion);
65*4882a593Smuzhiyun         swapl(&rep.minorVersion);
66*4882a593Smuzhiyun     }
67*4882a593Smuzhiyun     WriteToClient(client, sizeof(xRRQueryVersionReply), &rep);
68*4882a593Smuzhiyun     return Success;
69*4882a593Smuzhiyun }
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun static int
ProcRRSelectInput(ClientPtr client)72*4882a593Smuzhiyun ProcRRSelectInput(ClientPtr client)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun     REQUEST(xRRSelectInputReq);
75*4882a593Smuzhiyun     rrClientPriv(client);
76*4882a593Smuzhiyun     RRTimesPtr pTimes;
77*4882a593Smuzhiyun     WindowPtr pWin;
78*4882a593Smuzhiyun     RREventPtr pRREvent, *pHead;
79*4882a593Smuzhiyun     XID clientResource;
80*4882a593Smuzhiyun     int rc;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xRRSelectInputReq);
83*4882a593Smuzhiyun     rc = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess);
84*4882a593Smuzhiyun     if (rc != Success)
85*4882a593Smuzhiyun         return rc;
86*4882a593Smuzhiyun     rc = dixLookupResourceByType((void **) &pHead, pWin->drawable.id,
87*4882a593Smuzhiyun                                  RREventType, client, DixWriteAccess);
88*4882a593Smuzhiyun     if (rc != Success && rc != BadValue)
89*4882a593Smuzhiyun         return rc;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun     if (stuff->enable & (RRScreenChangeNotifyMask |
92*4882a593Smuzhiyun                          RRCrtcChangeNotifyMask |
93*4882a593Smuzhiyun                          RROutputChangeNotifyMask |
94*4882a593Smuzhiyun                          RROutputPropertyNotifyMask |
95*4882a593Smuzhiyun                          RRProviderChangeNotifyMask |
96*4882a593Smuzhiyun                          RRProviderPropertyNotifyMask |
97*4882a593Smuzhiyun                          RRResourceChangeNotifyMask)) {
98*4882a593Smuzhiyun         ScreenPtr pScreen = pWin->drawable.pScreen;
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun         rrScrPriv(pScreen);
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun         pRREvent = NULL;
103*4882a593Smuzhiyun         if (pHead) {
104*4882a593Smuzhiyun             /* check for existing entry. */
105*4882a593Smuzhiyun             for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next)
106*4882a593Smuzhiyun                 if (pRREvent->client == client)
107*4882a593Smuzhiyun                     break;
108*4882a593Smuzhiyun         }
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun         if (!pRREvent) {
111*4882a593Smuzhiyun             /* build the entry */
112*4882a593Smuzhiyun             pRREvent = (RREventPtr) malloc(sizeof(RREventRec));
113*4882a593Smuzhiyun             if (!pRREvent)
114*4882a593Smuzhiyun                 return BadAlloc;
115*4882a593Smuzhiyun             pRREvent->next = 0;
116*4882a593Smuzhiyun             pRREvent->client = client;
117*4882a593Smuzhiyun             pRREvent->window = pWin;
118*4882a593Smuzhiyun             pRREvent->mask = stuff->enable;
119*4882a593Smuzhiyun             /*
120*4882a593Smuzhiyun              * add a resource that will be deleted when
121*4882a593Smuzhiyun              * the client goes away
122*4882a593Smuzhiyun              */
123*4882a593Smuzhiyun             clientResource = FakeClientID(client->index);
124*4882a593Smuzhiyun             pRREvent->clientResource = clientResource;
125*4882a593Smuzhiyun             if (!AddResource(clientResource, RRClientType, (void *) pRREvent))
126*4882a593Smuzhiyun                 return BadAlloc;
127*4882a593Smuzhiyun             /*
128*4882a593Smuzhiyun              * create a resource to contain a pointer to the list
129*4882a593Smuzhiyun              * of clients selecting input.  This must be indirect as
130*4882a593Smuzhiyun              * the list may be arbitrarily rearranged which cannot be
131*4882a593Smuzhiyun              * done through the resource database.
132*4882a593Smuzhiyun              */
133*4882a593Smuzhiyun             if (!pHead) {
134*4882a593Smuzhiyun                 pHead = (RREventPtr *) malloc(sizeof(RREventPtr));
135*4882a593Smuzhiyun                 if (!pHead ||
136*4882a593Smuzhiyun                     !AddResource(pWin->drawable.id, RREventType,
137*4882a593Smuzhiyun                                  (void *) pHead)) {
138*4882a593Smuzhiyun                     FreeResource(clientResource, RT_NONE);
139*4882a593Smuzhiyun                     return BadAlloc;
140*4882a593Smuzhiyun                 }
141*4882a593Smuzhiyun                 *pHead = 0;
142*4882a593Smuzhiyun             }
143*4882a593Smuzhiyun             pRREvent->next = *pHead;
144*4882a593Smuzhiyun             *pHead = pRREvent;
145*4882a593Smuzhiyun         }
146*4882a593Smuzhiyun         /*
147*4882a593Smuzhiyun          * Now see if the client needs an event
148*4882a593Smuzhiyun          */
149*4882a593Smuzhiyun         if (pScrPriv) {
150*4882a593Smuzhiyun             pTimes = &((RRTimesPtr) (pRRClient + 1))[pScreen->myNum];
151*4882a593Smuzhiyun             if (CompareTimeStamps(pTimes->setTime,
152*4882a593Smuzhiyun                                   pScrPriv->lastSetTime) != 0 ||
153*4882a593Smuzhiyun                 CompareTimeStamps(pTimes->configTime,
154*4882a593Smuzhiyun                                   pScrPriv->lastConfigTime) != 0) {
155*4882a593Smuzhiyun                 if (pRREvent->mask & RRScreenChangeNotifyMask) {
156*4882a593Smuzhiyun                     RRDeliverScreenEvent(client, pWin, pScreen);
157*4882a593Smuzhiyun                 }
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun                 if (pRREvent->mask & RRCrtcChangeNotifyMask) {
160*4882a593Smuzhiyun                     int i;
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun                     for (i = 0; i < pScrPriv->numCrtcs; i++) {
163*4882a593Smuzhiyun                         RRDeliverCrtcEvent(client, pWin, pScrPriv->crtcs[i]);
164*4882a593Smuzhiyun                     }
165*4882a593Smuzhiyun                 }
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun                 if (pRREvent->mask & RROutputChangeNotifyMask) {
168*4882a593Smuzhiyun                     int i;
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun                     for (i = 0; i < pScrPriv->numOutputs; i++) {
171*4882a593Smuzhiyun                         RRDeliverOutputEvent(client, pWin,
172*4882a593Smuzhiyun                                              pScrPriv->outputs[i]);
173*4882a593Smuzhiyun                     }
174*4882a593Smuzhiyun                 }
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun                 /* We don't check for RROutputPropertyNotifyMask, as randrproto.txt doesn't
177*4882a593Smuzhiyun                  * say if there ought to be notifications of changes to output properties
178*4882a593Smuzhiyun                  * if those changes occurred before the time RRSelectInput is called.
179*4882a593Smuzhiyun                  */
180*4882a593Smuzhiyun             }
181*4882a593Smuzhiyun         }
182*4882a593Smuzhiyun     }
183*4882a593Smuzhiyun     else if (stuff->enable == 0) {
184*4882a593Smuzhiyun         /* delete the interest */
185*4882a593Smuzhiyun         if (pHead) {
186*4882a593Smuzhiyun             RREventPtr pNewRREvent = 0;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun             for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) {
189*4882a593Smuzhiyun                 if (pRREvent->client == client)
190*4882a593Smuzhiyun                     break;
191*4882a593Smuzhiyun                 pNewRREvent = pRREvent;
192*4882a593Smuzhiyun             }
193*4882a593Smuzhiyun             if (pRREvent) {
194*4882a593Smuzhiyun                 FreeResource(pRREvent->clientResource, RRClientType);
195*4882a593Smuzhiyun                 if (pNewRREvent)
196*4882a593Smuzhiyun                     pNewRREvent->next = pRREvent->next;
197*4882a593Smuzhiyun                 else
198*4882a593Smuzhiyun                     *pHead = pRREvent->next;
199*4882a593Smuzhiyun                 free(pRREvent);
200*4882a593Smuzhiyun             }
201*4882a593Smuzhiyun         }
202*4882a593Smuzhiyun     }
203*4882a593Smuzhiyun     else {
204*4882a593Smuzhiyun         client->errorValue = stuff->enable;
205*4882a593Smuzhiyun         return BadValue;
206*4882a593Smuzhiyun     }
207*4882a593Smuzhiyun     return Success;
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun int (*ProcRandrVector[RRNumberRequests]) (ClientPtr) = {
211*4882a593Smuzhiyun     ProcRRQueryVersion,         /* 0 */
212*4882a593Smuzhiyun /* we skip 1 to make old clients fail pretty immediately */
213*4882a593Smuzhiyun         NULL,                   /* 1 ProcRandrOldGetScreenInfo */
214*4882a593Smuzhiyun /* V1.0 apps share the same set screen config request id */
215*4882a593Smuzhiyun         ProcRRSetScreenConfig,  /* 2 */
216*4882a593Smuzhiyun         NULL,                   /* 3 ProcRandrOldScreenChangeSelectInput */
217*4882a593Smuzhiyun /* 3 used to be ScreenChangeSelectInput; deprecated */
218*4882a593Smuzhiyun         ProcRRSelectInput,      /* 4 */
219*4882a593Smuzhiyun         ProcRRGetScreenInfo,    /* 5 */
220*4882a593Smuzhiyun /* V1.2 additions */
221*4882a593Smuzhiyun         ProcRRGetScreenSizeRange,       /* 6 */
222*4882a593Smuzhiyun         ProcRRSetScreenSize,    /* 7 */
223*4882a593Smuzhiyun         ProcRRGetScreenResources,       /* 8 */
224*4882a593Smuzhiyun         ProcRRGetOutputInfo,    /* 9 */
225*4882a593Smuzhiyun         ProcRRListOutputProperties,     /* 10 */
226*4882a593Smuzhiyun         ProcRRQueryOutputProperty,      /* 11 */
227*4882a593Smuzhiyun         ProcRRConfigureOutputProperty,  /* 12 */
228*4882a593Smuzhiyun         ProcRRChangeOutputProperty,     /* 13 */
229*4882a593Smuzhiyun         ProcRRDeleteOutputProperty,     /* 14 */
230*4882a593Smuzhiyun         ProcRRGetOutputProperty,        /* 15 */
231*4882a593Smuzhiyun         ProcRRCreateMode,       /* 16 */
232*4882a593Smuzhiyun         ProcRRDestroyMode,      /* 17 */
233*4882a593Smuzhiyun         ProcRRAddOutputMode,    /* 18 */
234*4882a593Smuzhiyun         ProcRRDeleteOutputMode, /* 19 */
235*4882a593Smuzhiyun         ProcRRGetCrtcInfo,      /* 20 */
236*4882a593Smuzhiyun         ProcRRSetCrtcConfig,    /* 21 */
237*4882a593Smuzhiyun         ProcRRGetCrtcGammaSize, /* 22 */
238*4882a593Smuzhiyun         ProcRRGetCrtcGamma,     /* 23 */
239*4882a593Smuzhiyun         ProcRRSetCrtcGamma,     /* 24 */
240*4882a593Smuzhiyun /* V1.3 additions */
241*4882a593Smuzhiyun         ProcRRGetScreenResourcesCurrent,        /* 25 */
242*4882a593Smuzhiyun         ProcRRSetCrtcTransform, /* 26 */
243*4882a593Smuzhiyun         ProcRRGetCrtcTransform, /* 27 */
244*4882a593Smuzhiyun         ProcRRGetPanning,       /* 28 */
245*4882a593Smuzhiyun         ProcRRSetPanning,       /* 29 */
246*4882a593Smuzhiyun         ProcRRSetOutputPrimary, /* 30 */
247*4882a593Smuzhiyun         ProcRRGetOutputPrimary, /* 31 */
248*4882a593Smuzhiyun /* V1.4 additions */
249*4882a593Smuzhiyun         ProcRRGetProviders,     /* 32 */
250*4882a593Smuzhiyun         ProcRRGetProviderInfo,  /* 33 */
251*4882a593Smuzhiyun         ProcRRSetProviderOffloadSink, /* 34 */
252*4882a593Smuzhiyun         ProcRRSetProviderOutputSource, /* 35 */
253*4882a593Smuzhiyun         ProcRRListProviderProperties,    /* 36 */
254*4882a593Smuzhiyun         ProcRRQueryProviderProperty,     /* 37 */
255*4882a593Smuzhiyun         ProcRRConfigureProviderProperty, /* 38 */
256*4882a593Smuzhiyun         ProcRRChangeProviderProperty, /* 39 */
257*4882a593Smuzhiyun         ProcRRDeleteProviderProperty, /* 40 */
258*4882a593Smuzhiyun         ProcRRGetProviderProperty,    /* 41 */
259*4882a593Smuzhiyun /* V1.5 additions */
260*4882a593Smuzhiyun         ProcRRGetMonitors,            /* 42 */
261*4882a593Smuzhiyun         ProcRRSetMonitor,             /* 43 */
262*4882a593Smuzhiyun         ProcRRDeleteMonitor,          /* 44 */
263*4882a593Smuzhiyun /* V1.6 additions */
264*4882a593Smuzhiyun         ProcRRCreateLease,            /* 45 */
265*4882a593Smuzhiyun         ProcRRFreeLease,              /* 46 */
266*4882a593Smuzhiyun };
267