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