2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Sangjin Lee <lsj119@samsung.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Soft-
8 * ware"), to deal in the Software without restriction, including without
9 * limitation the rights to use, copy, modify, merge, publish, distribute,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, provided that the above copyright
12 * notice(s) and this permission notice appear in all copies of the Soft-
13 * ware and that both the above copyright notice(s) and this permission
14 * notice appear in supporting documentation.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
18 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
19 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
20 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
21 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
24 * MANCE OF THIS SOFTWARE.
26 * Except as contained in this notice, the name of a copyright holder shall
27 * not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization of
29 * the copyright holder.
32 * Sangjin Lee (lsj119@samsung.com)
36 #include <sys/types.h>
38 #include <X11/Xlibint.h>
39 #include <X11/extensions/Xext.h>
40 #include <X11/extensions/extutil.h>
41 #include <X11/extensions/hwcproto.h>
44 static char hwcExtensionName[] = HWC_NAME;
45 static XExtensionInfo *hwcInfo;
48 HWCCloseDisplay(Display *dpy, XExtCodes *codes);
50 HWCError(Display *display, xError *err, XExtCodes *codes, int *ret_code);
52 HWCWireToCookie(Display *dpy,XGenericEventCookie *cookie, xEvent *event);
54 HWCCopyCookie(Display *dpy, XGenericEventCookie *in, XGenericEventCookie *out);
56 static /* const */ XExtensionHooks hwcExtensionHooks = {
61 NULL, /* create_font */
63 HWCCloseDisplay, /* close_display */
64 NULL, /* wire_to_event */
65 NULL, /* event_to_wire */
67 NULL, /* error_string */
70 static XExtDisplayInfo *
71 HWCFindDisplay (Display *dpy)
73 XExtDisplayInfo *dpyinfo;
76 if (!(hwcInfo = XextCreateExtension()))
80 if (!(dpyinfo = XextFindDisplay (hwcInfo, dpy)))
82 dpyinfo = XextAddDisplay (hwcInfo,dpy,hwcExtensionName,&hwcExtensionHooks,0,NULL);
84 if (dpyinfo->codes) /* NULL if HWC doesn't exist on the server */
86 XESetWireToEventCookie(dpy, dpyinfo->codes->major_opcode, HWCWireToCookie);
87 XESetCopyEventCookie(dpy, dpyinfo->codes->major_opcode, HWCCopyCookie);
95 HWCCloseDisplay(Display *dpy, XExtCodes *codes)
97 return XextRemoveDisplay (hwcInfo, dpy);
101 HWCError(Display *display, xError *err, XExtCodes *codes, int *ret_code)
107 HWCWireToCookie(Display *dpy, XGenericEventCookie *cookie, xEvent *event)
109 XExtDisplayInfo *info = HWCFindDisplay(dpy);
110 xGenericEvent* ge = (xGenericEvent*)event;
112 if (ge->extension != info->codes->major_opcode)
114 fprintf(stderr, "HWCWireToCookie: wrong extension opcode %d\n",
119 cookie->type = ge->type;
120 cookie->serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
121 cookie->send_event = ((event->u.u.type & 0x80) != 0);
122 cookie->display = dpy;
123 cookie->extension = ge->extension;
124 cookie->evtype = ge->evtype;
129 case HWCConfigureNotify:
131 xHWCConfigureNotify *in = (xHWCConfigureNotify*)event;
132 HWCConfigureNotifyCookie* data;
134 cookie->data = data = malloc(sizeof(HWCConfigureNotifyCookie));
135 data->evtype = HWCConfigureNotify;
136 data->maxLayer = in->maxLayer;
140 printf("HWCWireToCookie: Unknown generic event. type %d\n", ge->evtype);
147 HWCCopyCookie(Display *dpy, XGenericEventCookie *in, XGenericEventCookie *out)
149 XExtDisplayInfo *info = HWCFindDisplay(dpy);
151 if (in->extension != info->codes->major_opcode)
153 fprintf(stderr,"HWCCopyCookie: wrong extension opcode %d\n",
163 case HWCConfigureNotify:
165 HWCConfigureNotifyCookie *_in, *_out;
167 _in = (HWCConfigureNotifyCookie *)in->data;
168 _out = malloc(sizeof(HWCConfigureNotifyCookie));
170 out->data = (void*)_out;
174 fprintf(stderr, "HWCCopyCookie: Failed to copy evtype %d", in->evtype);
182 HWCQueryVersion(Display * dpy, int *major, int *minor)
184 XExtDisplayInfo *info = HWCFindDisplay(dpy);
185 xHWCQueryVersionReply rep;
186 xHWCQueryVersionReq *req;
188 XextCheckExtension(dpy, info, hwcExtensionName, False);
191 GetReq(HWCQueryVersion, req);
192 req->reqType = info->codes->major_opcode;
193 req->hwcReqType = X_HWCQueryVersion;
194 req->majorVersion = HWC_MAJOR;
195 req->minorVersion = HWC_MINOR;
196 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
201 *major = rep.majorVersion;
202 *minor = rep.minorVersion;
210 HWCOpen(Display * dpy, Window window, int *maxLayer)
212 XExtDisplayInfo *info = HWCFindDisplay(dpy);
216 XextCheckExtension(dpy, info, hwcExtensionName, False);
219 GetReq(HWCOpen, req);
220 req->reqType = info->codes->major_opcode;
221 req->hwcReqType = X_HWCOpen;
222 req->window = window;
224 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
230 *maxLayer = rep.maxLayer;
239 HWCSetDrawables(Display * dpy, Window window, Drawable *drawables, XRectangle *srcRect, XRectangle *dstRect, int count)
241 XExtDisplayInfo *info = HWCFindDisplay(dpy);
242 xHWCSetDrawablesReq *req;
246 XextSimpleCheckExtension(dpy, info, hwcExtensionName);
249 GetReqExtra(HWCSetDrawables, count * SIZEOF(xHWCDrawInfo), req);
251 req->reqType = info->codes->major_opcode;
252 req->hwcReqType = X_HWCSetDrawables;
253 req->window = window;
255 p = (xHWCDrawInfo *) & req[1];
256 for (i = 0; i < count; i++)
258 p[i].drawable = drawables[i];
259 p[i].srcX = srcRect[i].x;
260 p[i].srcY = srcRect[i].y;
261 p[i].srcWidth = srcRect[i].width;
262 p[i].srcHeight = srcRect[i].height;
263 p[i].dstX = dstRect[i].x;
264 p[i].dstY = dstRect[i].y;
265 p[i].dstWidth = dstRect[i].width;
266 p[i].dstHeight = dstRect[i].height;
274 HWCSelectInput(Display * dpy, Window window, int mask)
276 XExtDisplayInfo *info = HWCFindDisplay(dpy);
277 xHWCSelectInputReq *req;
279 XextSimpleCheckExtension(dpy, info, hwcExtensionName);
282 GetReq(HWCSelectInput, req);
283 req->reqType = info->codes->major_opcode;
284 req->hwcReqType = X_HWCSelectInput;
285 req->window = window;
286 req->eventMask = mask;