aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/present/present_request.c
blob: 68076edd7935c2686b28bf07a7b0c7487ba31286 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
 * Copyright © 2013 Keith Packard
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of the copyright holders not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  The copyright holders make no representations
 * about the suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
 * OF THIS SOFTWARE.
 */

#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif

#include "present_priv.h"
#include "randrstr.h"
#include <protocol-versions.h>

static int
proc_present_query_version(ClientPtr client)
{
    xPresentQueryVersionReply rep;
    REQUEST(xPresentQueryVersionReq);

        rep.type = X_Reply;
        rep.sequenceNumber = client->sequence;
        rep.length = 0;
        rep.majorVersion = SERVER_PRESENT_MAJOR_VERSION;
        rep.minorVersion = SERVER_PRESENT_MINOR_VERSION;


    REQUEST_SIZE_MATCH(xPresentQueryVersionReq);
    (void) stuff;
    if (client->swapped) {
        swaps(&rep.sequenceNumber);
        swapl(&rep.length);
        swapl(&rep.majorVersion);
        swapl(&rep.minorVersion);
    }
    WriteToClient(client, sizeof(rep), &rep);
    return Success;
}

#define VERIFY_FENCE_OR_NONE(fence_ptr, fence_id, client, access) do {  \
        if ((fence_id) == None)                                         \
            (fence_ptr) = NULL;                                         \
        else {                                                          \
            int __rc__ = SyncVerifyFence(&fence_ptr, fence_id, client, access); \
            if (__rc__ != Success)                                      \
                return __rc__;                                          \
        }                                                               \
    } while (0)

#define VERIFY_CRTC_OR_NONE(crtc_ptr, crtc_id, client, access) do {     \
        if ((crtc_id) == None)                                          \
            (crtc_ptr) = NULL;                                          \
        else {                                                          \
            VERIFY_RR_CRTC(crtc_id, crtc_ptr, access);                  \
        }                                                               \
    } while (0)

static int
proc_present_pixmap(ClientPtr client)
{
    REQUEST(xPresentPixmapReq);
    WindowPtr           window;
    PixmapPtr           pixmap;
    RegionPtr           valid = NULL;
    RegionPtr           update = NULL;
    SyncFence           *wait_fence;
    SyncFence           *idle_fence;
    RRCrtcPtr           target_crtc;
    int                 ret;
    int                 nnotifies;
    present_notify_ptr  notifies = NULL;

    REQUEST_AT_LEAST_SIZE(xPresentPixmapReq);
    ret = dixLookupWindow(&window, stuff->window, client, DixWriteAccess);
    if (ret != Success)
        return ret;
    ret = dixLookupResourceByType((void **) &pixmap, stuff->pixmap, RT_PIXMAP, client, DixReadAccess);
    if (ret != Success)
        return ret;

    if (window->drawable.depth != pixmap->drawable.depth)
        return BadMatch;

    VERIFY_REGION_OR_NONE(valid, stuff->valid, client, DixReadAccess);
    VERIFY_REGION_OR_NONE(update, stuff->update, client, DixReadAccess);

    VERIFY_CRTC_OR_NONE(target_crtc, stuff->target_crtc, client, DixReadAccess);

    VERIFY_FENCE_OR_NONE(wait_fence, stuff->wait_fence, client, DixReadAccess);
    VERIFY_FENCE_OR_NONE(idle_fence, stuff->idle_fence, client, DixWriteAccess);

    if (stuff->options & ~(PresentAllOptions)) {
        client->errorValue = stuff->options;
        return BadValue;
    }

    /*
     * Check to see if remainder is sane
     */
    if (stuff->divisor == 0) {
        if (stuff->remainder != 0) {
            client->errorValue = (CARD32) stuff->remainder;
            return BadValue;
        }
    } else {
        if (stuff->remainder >= stuff->divisor) {
            client->errorValue = (CARD32) stuff->remainder;
            return BadValue;
        }
    }

    nnotifies = (client->req_len << 2) - sizeof (xPresentPixmapReq);
    if (nnotifies % sizeof (xPresentNotify))
        return BadLength;

    nnotifies /= sizeof (xPresentNotify);
    if (nnotifies) {
        ret = present_create_notifies(client, nnotifies, (xPresentNotify *) (stuff + 1), &notifies);
        if (ret != Success)
            return ret;
    }

    ret = present_pixmap(window, pixmap, stuff->serial, valid, update,
                         stuff->x_off, stuff->y_off, target_crtc,
                         wait_fence, idle_fence, stuff->options,
                         stuff->target_msc, stuff->divisor, stuff->remainder, notifies, nnotifies);
    if (ret != Success)
        present_destroy_notifies(notifies, nnotifies);
    return ret;
}

static int
proc_present_notify_msc(ClientPtr client)
{
    REQUEST(xPresentNotifyMSCReq);
    WindowPtr   window;
    int         rc;

    REQUEST_SIZE_MATCH(xPresentNotifyMSCReq);
    rc = dixLookupWindow(&window, stuff->window, client, DixReadAccess);
    if (rc != Success)
        return rc;

    /*
     * Check to see if remainder is sane
     */
    if (stuff->divisor == 0) {
        if (stuff->remainder != 0) {
            client->errorValue = (CARD32) stuff->remainder;
            return BadValue;
        }
    } else {
        if (stuff->remainder >= stuff->divisor) {
            client->errorValue = (CARD32) stuff->remainder;
            return BadValue;
        }
    }

    return present_notify_msc(window, stuff->serial,
                              stuff->target_msc, stuff->divisor, stuff->remainder);
}

static int
proc_present_select_input (ClientPtr client)
{
    REQUEST(xPresentSelectInputReq);
    WindowPtr window;
    int rc;

    REQUEST_SIZE_MATCH(xPresentSelectInputReq);

    LEGAL_NEW_RESOURCE(stuff->eid, client);

    rc = dixLookupWindow(&window, stuff->window, client, DixGetAttrAccess);
    if (rc != Success)
        return rc;

    if (stuff->eventMask & ~PresentAllEvents) {
        client->errorValue = stuff->eventMask;
        return BadValue;
    }
    return present_select_input(client, stuff->eid, window, stuff->eventMask);
}

static int
proc_present_query_capabilities (ClientPtr client)
{
    WindowPtr   window;
    RRCrtcPtr   crtc = NULL;
    int         r;
    xPresentQueryCapabilitiesReply rep;
    REQUEST(xPresentQueryCapabilitiesReq);
        rep.type = X_Reply;
        rep.sequenceNumber = client->sequence;
        rep.length = 0;

    REQUEST_SIZE_MATCH(xPresentQueryCapabilitiesReq);
    r = dixLookupWindow(&window, stuff->target, client, DixGetAttrAccess);
    switch (r) {
    case Success:
        crtc = present_get_crtc(window);
        break;
    case BadWindow:
        VERIFY_RR_CRTC(stuff->target, crtc, DixGetAttrAccess);
        break;
    default:
        return r;
    }

    rep.capabilities = present_query_capabilities(crtc);

    if (client->swapped) {
        swaps(&rep.sequenceNumber);
        swapl(&rep.length);
        swapl(&rep.capabilities);
    }
    WriteToClient(client, sizeof(rep), &rep);
    return Success;
}

int (*proc_present_vector[PresentNumberRequests]) (ClientPtr) = {
    proc_present_query_version,            /* 0 */
    proc_present_pixmap,                   /* 1 */
    proc_present_notify_msc,               /* 2 */
    proc_present_select_input,             /* 3 */
    proc_present_query_capabilities,       /* 4 */
};

int
proc_present_dispatch(ClientPtr client)
{
    REQUEST(xReq);
    if (stuff->data >= PresentNumberRequests || !proc_present_vector[stuff->data])
        return BadRequest;
    return (*proc_present_vector[stuff->data]) (client);
}

static int
sproc_present_query_version(ClientPtr client)
{
    REQUEST(xPresentQueryVersionReq);
    REQUEST_SIZE_MATCH(xPresentQueryVersionReq);

    swaps(&stuff->length);
    swapl(&stuff->majorVersion);
    swapl(&stuff->minorVersion);
    return (*proc_present_vector[stuff->presentReqType]) (client);
}

static int
sproc_present_pixmap(ClientPtr client)
{
    REQUEST(xPresentPixmapReq);
    REQUEST_AT_LEAST_SIZE(xPresentPixmapReq);

    swaps(&stuff->length);
    swapl(&stuff->window);
    swapl(&stuff->pixmap);
    swapl(&stuff->valid);
    swapl(&stuff->update);
    swaps(&stuff->x_off);
    swaps(&stuff->y_off);
    swapll(&stuff->target_msc);
    swapll(&stuff->divisor);
    swapll(&stuff->remainder);
    swapl(&stuff->idle_fence);
    return (*proc_present_vector[stuff->presentReqType]) (client);
}

static int
sproc_present_notify_msc(ClientPtr client)
{
    REQUEST(xPresentNotifyMSCReq);
    REQUEST_SIZE_MATCH(xPresentNotifyMSCReq);

    swaps(&stuff->length);
    swapl(&stuff->window);
    swapll(&stuff->target_msc);
    swapll(&stuff->divisor);
    swapll(&stuff->remainder);
    return (*proc_present_vector[stuff->presentReqType]) (client);
}

static int
sproc_present_select_input (ClientPtr client)
{
    REQUEST(xPresentSelectInputReq);
    REQUEST_SIZE_MATCH(xPresentSelectInputReq);

    swaps(&stuff->length);
    swapl(&stuff->window);
    swapl(&stuff->eventMask);
    return (*proc_present_vector[stuff->presentReqType]) (client);
}

static int
sproc_present_query_capabilities (ClientPtr client)
{
    REQUEST(xPresentQueryCapabilitiesReq);
    REQUEST_SIZE_MATCH(xPresentQueryCapabilitiesReq);
    swaps(&stuff->length);
    swapl(&stuff->target);
    return (*proc_present_vector[stuff->presentReqType]) (client);
}

int (*sproc_present_vector[PresentNumberRequests]) (ClientPtr) = {
    sproc_present_query_version,           /* 0 */
    sproc_present_pixmap,                  /* 1 */
    sproc_present_notify_msc,              /* 2 */
    sproc_present_select_input,            /* 3 */
    sproc_present_query_capabilities,      /* 4 */
};

int
sproc_present_dispatch(ClientPtr client)
{
    REQUEST(xReq);
    if (stuff->data >= PresentNumberRequests || !sproc_present_vector[stuff->data])
        return BadRequest;
    return (*sproc_present_vector[stuff->data]) (client);
}