1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci Copyright (c) 2009 Apple Inc.
3bf215546Sopenharmony_ci
4bf215546Sopenharmony_ci Permission is hereby granted, free of charge, to any person
5bf215546Sopenharmony_ci obtaining a copy of this software and associated documentation files
6bf215546Sopenharmony_ci (the "Software"), to deal in the Software without restriction,
7bf215546Sopenharmony_ci including without limitation the rights to use, copy, modify, merge,
8bf215546Sopenharmony_ci publish, distribute, sublicense, and/or sell copies of the Software,
9bf215546Sopenharmony_ci and to permit persons to whom the Software is furnished to do so,
10bf215546Sopenharmony_ci subject to the following conditions:
11bf215546Sopenharmony_ci
12bf215546Sopenharmony_ci The above copyright notice and this permission notice shall be
13bf215546Sopenharmony_ci included in all copies or substantial portions of the Software.
14bf215546Sopenharmony_ci
15bf215546Sopenharmony_ci THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16bf215546Sopenharmony_ci EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17bf215546Sopenharmony_ci MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18bf215546Sopenharmony_ci NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
19bf215546Sopenharmony_ci HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20bf215546Sopenharmony_ci WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21bf215546Sopenharmony_ci OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22bf215546Sopenharmony_ci DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci Except as contained in this notice, the name(s) of the above
25bf215546Sopenharmony_ci copyright holders shall not be used in advertising or otherwise to
26bf215546Sopenharmony_ci promote the sale, use or other dealings in this Software without
27bf215546Sopenharmony_ci prior written authorization.
28bf215546Sopenharmony_ci*/
29bf215546Sopenharmony_ci#include <stdbool.h>
30bf215546Sopenharmony_ci#include <assert.h>
31bf215546Sopenharmony_ci#include <X11/Xlibint.h>
32bf215546Sopenharmony_ci#include <X11/extensions/extutil.h>
33bf215546Sopenharmony_ci#include <X11/extensions/Xext.h>
34bf215546Sopenharmony_ci#include "glxclient.h"
35bf215546Sopenharmony_ci#include "glx_error.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_civoid
38bf215546Sopenharmony_ci__glXSendError(Display * dpy, int_fast8_t errorCode, uint_fast32_t resourceID,
39bf215546Sopenharmony_ci               uint_fast16_t minorCode, bool coreX11error)
40bf215546Sopenharmony_ci{
41bf215546Sopenharmony_ci   struct glx_display *glx_dpy = __glXInitialize(dpy);
42bf215546Sopenharmony_ci   xError error;
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci   assert(glx_dpy);
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci   LockDisplay(dpy);
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   error.type = X_Error;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   if (coreX11error) {
51bf215546Sopenharmony_ci      error.errorCode = errorCode;
52bf215546Sopenharmony_ci   }
53bf215546Sopenharmony_ci   else {
54bf215546Sopenharmony_ci      error.errorCode = glx_dpy->codes.first_error + errorCode;
55bf215546Sopenharmony_ci   }
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   error.sequenceNumber = dpy->request;
58bf215546Sopenharmony_ci   error.resourceID = resourceID;
59bf215546Sopenharmony_ci   error.minorCode = minorCode;
60bf215546Sopenharmony_ci   error.majorCode = glx_dpy->codes.major_opcode;
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   _XError(dpy, &error);
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   UnlockDisplay(dpy);
65bf215546Sopenharmony_ci}
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_civoid
68bf215546Sopenharmony_ci__glXSendErrorForXcb(Display * dpy, const xcb_generic_error_t *err)
69bf215546Sopenharmony_ci{
70bf215546Sopenharmony_ci   xError error;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   LockDisplay(dpy);
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci   error.type = X_Error;
75bf215546Sopenharmony_ci   error.errorCode = err->error_code;
76bf215546Sopenharmony_ci   error.sequenceNumber = err->sequence;
77bf215546Sopenharmony_ci   error.resourceID = err->resource_id;
78bf215546Sopenharmony_ci   error.minorCode = err->minor_code;
79bf215546Sopenharmony_ci   error.majorCode = err->major_code;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   _XError(dpy, &error);
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   UnlockDisplay(dpy);
84bf215546Sopenharmony_ci}
85