1 /**************************************************************************
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
7 Contact: Boram Park <boram1288.park@samsung.com>
8 Sangjin LEE <lsj119@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
39 #include <sys/types.h>
40 #include <sys/fcntl.h>
51 #include <X11/Xatom.h>
53 #include <windowstr.h>
55 #include <X11/extensions/Xrandr.h>
56 #include <X11/extensions/randrproto.h>
59 #include "xdbg_types.h"
60 #include "xdbg_evlog_randr.h"
61 #include "xdbg_evlog.h"
64 _EvlogRequestRandr (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
66 xReq *req = evinfo->req.ptr;
70 case X_RRGetScreenSizeRange:
72 xRRGetScreenSizeRangeReq *stuff = (xRRGetScreenSizeRangeReq *)req;
74 (unsigned int)stuff->window);
79 case X_RRSetScreenSize:
81 xRRSetScreenSizeReq *stuff = (xRRSetScreenSizeReq *)req;
82 REPLY (": XID(0x%x) size(%dx%d)",
83 (unsigned int)stuff->window,
87 if (detail_level >= EVLOG_PRINT_DETAIL)
89 REPLY (" milliSize(%ldx%ld)",
90 (long int)stuff->widthInMillimeters,
91 (long int)stuff->heightInMillimeters);
97 case X_RRGetScreenResources:
99 xRRGetScreenResourcesReq *stuff = (xRRGetScreenResourcesReq *)req;
100 REPLY (": XID(0x%x)",
101 (unsigned int)stuff->window);
106 case X_RRGetOutputInfo:
108 xRRGetOutputInfoReq *stuff = (xRRGetOutputInfoReq *)req;
109 REPLY (": XID(0x%x)",
110 (unsigned int)stuff->output);
112 if (detail_level >= EVLOG_PRINT_DETAIL)
114 REPLY (" config_timestamp(%lums)",
115 (unsigned long)stuff->configTimestamp);
121 case X_RRListOutputProperties:
123 xRRListOutputPropertiesReq *stuff = (xRRListOutputPropertiesReq *)req;
124 REPLY (": XID(0x%x)",
125 (unsigned int)stuff->output);
130 case X_RRQueryOutputProperty:
132 xRRQueryOutputPropertyReq *stuff = (xRRQueryOutputPropertyReq *)req;
133 REPLY (": XID(0x%x)",
134 (unsigned int)stuff->output);
137 reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
142 case X_RRConfigureOutputProperty:
144 xRRConfigureOutputPropertyReq *stuff = (xRRConfigureOutputPropertyReq *)req;
145 REPLY (": XID(0x%x)",
146 (unsigned int)stuff->output);
149 reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
151 if (detail_level >= EVLOG_PRINT_DETAIL)
153 REPLY (" pending(%s) range(%s)",
154 stuff->pending ? "YES" : "NO",
155 stuff->range ? "YES" : "NO");
161 case X_RRChangeOutputProperty:
163 xRRChangeOutputPropertyReq *stuff = (xRRChangeOutputPropertyReq *)req;
164 REPLY (": XID(0x%x)",
165 (unsigned int)stuff->output);
168 reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
170 reply = xDbgGetAtom(stuff->type, evinfo, reply, len);
172 if (detail_level >= EVLOG_PRINT_DETAIL)
179 case PropModeReplace: mode = "PropModeReplace"; break;
180 case PropModePrepend: mode = "PropModePrepend"; break;
181 case PropModeAppend: mode = "PropModeAppend"; break;
182 default: mode = dmode; snprintf (dmode, 10, "%d", stuff->mode); break;
186 REPLY ("%67s mode(%s) format(%d) nUnits(%ld)",
190 (long int)stuff->nUnits);
196 case X_RRDeleteOutputProperty:
198 xRRDeleteOutputPropertyReq *stuff = (xRRDeleteOutputPropertyReq *)req;
199 REPLY (": XID(0x%x)",
200 (unsigned int)stuff->output);
203 reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
208 case X_RRGetOutputProperty:
210 xRRGetOutputPropertyReq *stuff = (xRRGetOutputPropertyReq *)req;
211 REPLY (": XID(0x%x)",
212 (unsigned int)stuff->output);
215 reply = xDbgGetAtom(stuff->property, evinfo, reply, len);
217 reply = xDbgGetAtom(stuff->type, evinfo, reply, len);
219 if (detail_level >= EVLOG_PRINT_DETAIL)
221 REPLY (" longOffset(%ld) longLength(%ld)",
222 (long int)stuff->longOffset,
223 (long int)stuff->longLength);
229 case X_RRGetCrtcInfo:
231 xRRGetCrtcInfoReq *stuff = (xRRGetCrtcInfoReq *)req;
232 REPLY (": XID(0x%x)",
233 (unsigned int)stuff->crtc);
235 if (detail_level >= EVLOG_PRINT_DETAIL)
237 REPLY (" config_timestamp(%lums)",
238 (unsigned long)stuff->configTimestamp);
244 case X_RRSetCrtcConfig:
246 xRRSetCrtcConfigReq *stuff = (xRRSetCrtcConfigReq *)req;
247 REPLY (": XID(0x%x) coord(%d,%d) ",
248 (unsigned int)stuff->crtc,
252 if (detail_level >= EVLOG_PRINT_DETAIL)
254 const char *rotation;
256 switch (stuff->rotation & 0xf)
258 case RR_Rotate_0: rotation = "RR_Rotate_0"; break;
259 case RR_Rotate_90: rotation = "RR_Rotate_90"; break;
260 case RR_Rotate_180: rotation = "RR_Rotate_180"; break;
261 case RR_Rotate_270: rotation = "RR_Rotate_270"; break;
262 default: rotation = "Invaild Rotation"; break;
266 REPLY ("%67s timestamp(%lums) config_timestamp(%lums) RRmode(0x%x) rotation(%s)",
268 (unsigned long)stuff->timestamp,
269 (unsigned long)stuff->configTimestamp,
270 (unsigned int)stuff->mode,
277 case X_RRGetScreenResourcesCurrent:
279 xRRGetScreenResourcesCurrentReq *stuff = (xRRGetScreenResourcesCurrentReq *)req;
280 REPLY (": XID(0x%x)",
281 (unsigned int)stuff->window);
295 _EvlogEventRandr (EvlogInfo *evinfo, int first_base, int detail_level, char *reply, int *len)
297 xEvent *evt = evinfo->evt.ptr;
299 switch ((evt->u.u.type & 0x7F) - first_base)
301 case RRScreenChangeNotify:
303 xRRScreenChangeNotifyEvent *stuff = (xRRScreenChangeNotifyEvent *) evt;
304 REPLY (": Root(0x%x) Window(0x%x)",
305 (unsigned int)stuff->root,
306 (unsigned int)stuff->window);
308 if (detail_level >= EVLOG_PRINT_DETAIL)
310 const char *rotation;
312 switch (stuff->rotation & 0xf)
314 case RR_Rotate_0: rotation = "RR_Rotate_0"; break;
315 case RR_Rotate_90: rotation = "RR_Rotate_90"; break;
316 case RR_Rotate_180: rotation = "RR_Rotate_180"; break;
317 case RR_Rotate_270: rotation = "RR_Rotate_270"; break;
318 default: rotation = "Invaild Rotation"; break;
321 REPLY (" sizeID(%d) subPixel(%d) Pixel(%d,%d) Milli(%d,%d)",
323 stuff->subpixelOrder,
324 stuff->widthInPixels,
325 stuff->heightInPixels,
326 stuff->widthInMillimeters,
327 stuff->heightInMillimeters);
330 REPLY ("%67s rotation(%s) sequence_num(%d) timestamp(%lums) config_timestamp(%lums)",
333 stuff->sequenceNumber,
334 (unsigned long)stuff->timestamp,
335 (unsigned long)stuff->configTimestamp);
343 switch(evt->u.u.detail)
345 case RRNotify_CrtcChange:
347 xRRCrtcChangeNotifyEvent *stuff = (xRRCrtcChangeNotifyEvent *) evt;
348 REPLY (": XID(0x%x) Crtc(0x%x) RRmode(0x%x) new_size(%udx%ud) new_coord(%d,%d)",
349 (unsigned int)stuff->window,
350 (unsigned int)stuff->crtc,
351 (unsigned int)stuff->mode,
357 if (detail_level >= EVLOG_PRINT_DETAIL)
359 const char *rotation;
361 switch (stuff->rotation & 0xf)
363 case RR_Rotate_0: rotation = "RR_Rotate_0"; break;
364 case RR_Rotate_90: rotation = "RR_Rotate_90"; break;
365 case RR_Rotate_180: rotation = "RR_Rotate_180"; break;
366 case RR_Rotate_270: rotation = "RR_Rotate_270"; break;
367 default: rotation = "Invaild Rotation"; break;
371 REPLY ("%67s rotation(%s) sequence_num(%d) timestamp(%lums)",
374 stuff->sequenceNumber,
375 (unsigned long)stuff->timestamp);
381 case RRNotify_OutputChange:
383 xRROutputChangeNotifyEvent *stuff = (xRROutputChangeNotifyEvent *) evt;
384 REPLY (": XID(0x%x) Output(0x%x) Crtc(0x%x) RRmode(0x%x)",
385 (unsigned int)stuff->window,
386 (unsigned int)stuff->output,
387 (unsigned int)stuff->crtc,
388 (unsigned int)stuff->mode);
390 if (detail_level >= EVLOG_PRINT_DETAIL)
392 const char *rotation, *connection, *subpixelOrder;
393 char dconnection[10], dsubpixelOrder[10];
395 switch (stuff->rotation & 0xf)
397 case RR_Rotate_0: rotation = "RR_Rotate_0"; break;
398 case RR_Rotate_90: rotation = "RR_Rotate_90"; break;
399 case RR_Rotate_180: rotation = "RR_Rotate_180"; break;
400 case RR_Rotate_270: rotation = "RR_Rotate_270"; break;
401 default: rotation = "Invaild Rotation"; break;
404 switch (stuff->connection)
406 case RR_Connected: connection = "RR_Connected"; break;
407 case RR_Disconnected: connection = "RR_Disconnected"; break;
408 case RR_UnknownConnection: connection = "RR_UnknownConnection"; break;
409 default: connection = dconnection; snprintf (dconnection, 10, "%d", stuff->connection); break;
412 switch (stuff->subpixelOrder)
414 case SubPixelUnknown: subpixelOrder = "SubPixelUnknown"; break;
415 case SubPixelHorizontalRGB: subpixelOrder = "SubPixelHorizontalRGB"; break;
416 case SubPixelHorizontalBGR: subpixelOrder = "SubPixelHorizontalBGR"; break;
417 case SubPixelVerticalRGB: subpixelOrder = "SubPixelVerticalRGB"; break;
418 case SubPixelVerticalBGR: subpixelOrder = "SubPixelVerticalBGR"; break;
419 case SubPixelNone: subpixelOrder = "SubPixelNone"; break;
420 default: subpixelOrder = dsubpixelOrder; snprintf (dsubpixelOrder, 10, "%d", stuff->connection); break;
423 REPLY (" sequence_num(%d)",
424 stuff->sequenceNumber);
427 REPLY ("%67s timestamp(%lums) config_timestamp(%lums) rotation(%s) connection(%s) subpixel_order(%s)",
429 (unsigned long)stuff->timestamp,
430 (unsigned long)stuff->configTimestamp,
439 case RRNotify_OutputProperty:
441 xRROutputPropertyNotifyEvent *stuff = (xRROutputPropertyNotifyEvent *) evt;
442 REPLY (": XID(0x%x) Output(0x%x)",
443 (unsigned int)stuff->window,
444 (unsigned int)stuff->output);
447 reply = xDbgGetAtom(stuff->atom, evinfo, reply, len);
449 if (detail_level >= EVLOG_PRINT_DETAIL)
454 switch (stuff->state)
456 case PropertyNewValue: state = "PropertyNewValue"; break;
457 case PropertyDelete: state = "PropertyDelete"; break;
458 default: state = dstate; snprintf (dstate, 10, "%d", stuff->state); break;
462 REPLY ("%67s sequence_num(%d) timestamp(%lums) state(%s)",
464 stuff->sequenceNumber,
465 (unsigned long)stuff->timestamp,
472 case RRNotify_ProviderChange:
474 xRRProviderChangeNotifyEvent *stuff = (xRRProviderChangeNotifyEvent *) evt;
475 REPLY (": XID(0x%x) Provider(0x%x)",
476 (unsigned int)stuff->window,
477 (unsigned int)stuff->provider);
479 if (detail_level >= EVLOG_PRINT_DETAIL)
481 REPLY (" sequence_num(%d) timestamp(%lums)",
482 stuff->sequenceNumber,
483 (unsigned long)stuff->timestamp);
489 case RRNotify_ProviderProperty:
491 xRRProviderPropertyNotifyEvent *stuff = (xRRProviderPropertyNotifyEvent *) evt;
492 REPLY (": XID(0x%x) Provider(0x%x)",
493 (unsigned int)stuff->window,
494 (unsigned int)stuff->provider);
497 reply = xDbgGetAtom(stuff->atom, evinfo, reply, len);
499 if (detail_level >= EVLOG_PRINT_DETAIL)
504 switch (stuff->state)
506 case PropertyNewValue: state = "PropertyNewValue"; break;
507 case PropertyDelete: state = "PropertyDelete"; break;
508 default: state = dstate; snprintf (dstate, 10, "%d", stuff->state); break;
511 REPLY (" sequence_num(%d) timestamp(%lums) state(%s)",
512 stuff->sequenceNumber,
513 (unsigned long)stuff->timestamp,
520 case RRNotify_ResourceChange:
522 xRRResourceChangeNotifyEvent *stuff = (xRRResourceChangeNotifyEvent *) evt;
523 REPLY (": XID(0x%x)",
524 (unsigned int)stuff->window);
526 if (detail_level >= EVLOG_PRINT_DETAIL)
528 REPLY (" sequence_num(%d) timestamp(%lums)",
529 stuff->sequenceNumber,
530 (unsigned long)stuff->timestamp);
549 _EvlogReplyRandr (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
551 xGenericReply *rep = evinfo->rep.ptr;
553 switch (evinfo->rep.reqData)
555 case X_RRGetScreenSizeRange:
557 if (evinfo->rep.isStart)
559 xRRGetScreenSizeRangeReply *stuff = (xRRGetScreenSizeRangeReply *)rep;
560 REPLY (": minSize(%dx%d) maxSize(%dx%d)",
574 case X_RRGetScreenResources:
576 static int nCrtcs, nOutputs, nModes, nbytesNames;
578 if (evinfo->rep.isStart)
580 xRRGetScreenResourcesReply *stuff = (xRRGetScreenResourcesReply *)rep;
581 REPLY (": Timestamp(%ldms) ConfigTimestamp(%ldms) nCrtcs(%d) nOutputs(%d) nModes(%d) nbytesNames(%d)",
582 (long int)stuff->timestamp,
583 (long int)stuff->configTimestamp,
589 nCrtcs = stuff->nCrtcs;
590 nOutputs = stuff->nOutputs;
591 nModes = stuff->nModes;
592 nbytesNames = stuff->nbytesNames;
596 RRCrtc *crtcs = (RRCrtc *)rep;
597 RROutput *outputs = (RROutput *)(crtcs + nCrtcs);
598 xRRModeInfo *modeinfos = (xRRModeInfo *)(outputs + nOutputs);
599 CARD8 *names = (CARD8 *)(modeinfos + nModes);
600 char temp[64] = {0, };
603 names[nbytesNames] = '\0';
607 for (i = 0 ; i < nCrtcs ; i++)
609 REPLY ("0x%x", (unsigned int)crtcs[i]);
617 for (i = 0 ; i < nOutputs ; i++)
619 REPLY ("0x%x", (unsigned int)outputs[i]);
620 if(i != nOutputs - 1)
627 for (i = 0 ; i < nModes ; i++)
629 REPLY ("0x%x %dx%d", (unsigned int)modeinfos[i].id, modeinfos[i].width, modeinfos[i].height);
637 int min = MIN (sizeof (temp) - 1, nbytesNames);
638 strncpy (temp, (char *)names, min);
650 case X_RRGetOutputInfo:
652 static int nCrtcs, nModes, nClones, namelength;
653 if (evinfo->rep.isStart)
655 xRRGetOutputInfoReply *stuff = (xRRGetOutputInfoReply *)rep;
656 REPLY (": Timestamp(%ldms) Crtc(0x%x) mmSize(%ldx%ld) nCrtcs(%d) nModes(%d) nPreferred(%d) nClones(%d)",
657 (long int)stuff->timestamp,
658 (unsigned int)stuff->crtc,
659 (long int)stuff->mmWidth,
660 (long int)stuff->mmHeight,
666 nCrtcs = stuff->nCrtcs;
667 nModes = stuff->nModes;
668 nClones = stuff->nClones;
669 namelength = stuff->nameLength;
673 RRCrtc *crtcs = (RRCrtc *) rep;
674 RRMode *modes = (RRMode *) (crtcs + nCrtcs);
675 RROutput *clones = (RROutput *) (modes + nModes);
676 char *name = (char *) (clones + nClones);
679 name[namelength] = '\0';
683 for (i = 0 ; i < nCrtcs ; i++)
685 REPLY ("0x%x", (unsigned int)crtcs[i]);
693 for (i = 0 ; i < nModes ; i++)
695 REPLY ("0x%x", (unsigned int)modes[i]);
703 for (i = 0 ; i < nClones ; i++)
705 REPLY ("0x%x", (unsigned int)clones[i]);
720 case X_RRListOutputProperties:
722 if (evinfo->rep.isStart)
724 xRRListOutputPropertiesReply *stuff = (xRRListOutputPropertiesReply *)rep;
725 REPLY (": nAtoms(%d)",
730 Atom *stuff = (Atom *)rep;
733 REPLY ("Properties:");
734 for (i = 0 ; i < evinfo->rep.size / sizeof(Atom) ; i++)
736 reply = xDbgGetAtom(stuff[i], evinfo, reply, len);
737 if(i != evinfo->rep.size / sizeof(Atom) - 1)
745 case X_RRGetOutputProperty:
747 if (evinfo->rep.isStart)
749 xRRGetOutputPropertyReply *stuff = (xRRGetOutputPropertyReply *)rep;
751 reply = xDbgGetAtom(stuff->propertyType, evinfo, reply, len);
753 REPLY (" bytesAfter(%ld) nItems(%ld)",
754 (long int)stuff->bytesAfter,
755 (long int)stuff->nItems);
765 case X_RRGetCrtcInfo:
767 static int nOutput, nPossibleOutput;
769 if (evinfo->rep.isStart)
771 xRRGetCrtcInfoReply *stuff = (xRRGetCrtcInfoReply *)rep;
772 REPLY (" Timestamp(%ldms) coord(%d,%d %dx%d) RRmode(0x%x) rot(%d) rots(%d) nOutput(%d) nPossibleOutput(%d)",
773 (long int)stuff->timestamp,
778 (unsigned int)stuff->mode,
782 stuff->nPossibleOutput);
784 nOutput = stuff->nOutput;
785 nPossibleOutput = stuff->nPossibleOutput;
789 RROutput *outputs = (RROutput *) rep;
790 RROutput *possible = (RROutput *) (outputs + nOutput);
795 for (i = 0 ; i < nOutput ; i++)
797 REPLY ("0x%x", (unsigned int)outputs[i]);
805 for (i = 0 ; i < nPossibleOutput ; i++)
807 REPLY ("0x%x", (unsigned int)possible[i]);
808 if(i != nPossibleOutput - 1)
817 case X_RRSetCrtcConfig:
819 if (evinfo->rep.isStart)
821 xRRSetCrtcConfigReply *stuff = (xRRSetCrtcConfigReply *)rep;
823 REPLY (" newTimestamp(%ldms)",
824 (long int)stuff->newTimestamp);
834 case X_RRGetScreenResourcesCurrent:
836 static int nCrtcs, nOutputs, nModes, nbytesNames;
838 if (evinfo->rep.isStart)
840 xRRGetScreenResourcesReply *stuff = (xRRGetScreenResourcesReply *)rep;
842 REPLY (" Timestamp(%ldms) ConfigTimestamp(%ldms) nCrtcs(%d) nOutputs(%d) nModes(%d) nbytesNames(%d)",
843 (long int)stuff->timestamp,
844 (long int)stuff->configTimestamp,
850 nCrtcs = stuff->nCrtcs;
851 nOutputs = stuff->nOutputs;
852 nModes = stuff->nModes;
853 nbytesNames = stuff->nbytesNames;
857 RRCrtc *crtcs = (RRCrtc *)rep;
858 RROutput *outputs = (RROutput *)(crtcs + nCrtcs);
859 xRRModeInfo *modeinfos = (xRRModeInfo *)(outputs + nOutputs);
860 CARD8 *names = (CARD8 *)(modeinfos + nModes);
861 char temp[64] = {0, };
866 for (i = 0 ; i < nCrtcs ; i++)
868 REPLY ("0x%x", (unsigned int)crtcs[i]);
876 for (i = 0 ; i < nOutputs ; i++)
878 REPLY ("0x%x", (unsigned int)outputs[i]);
879 if(i != nOutputs - 1)
886 for (i = 0 ; i < nModes ; i++)
888 REPLY ("0x%x %dx%d", (unsigned int)modeinfos[i].id, modeinfos[i].width, modeinfos[i].height);
896 int min = MIN (sizeof (temp) - 1, nbytesNames);
897 strncpy (temp, (char *)names, min);
916 xDbgEvlogRandrGetBase (ExtensionInfo *extinfo)
919 RETURN_IF_FAIL (extinfo != NULL);
921 extinfo->req_func = _EvlogRequestRandr;
922 extinfo->evt_func = _EvlogEventRandr;
923 extinfo->rep_func = _EvlogReplyRandr;
925 ExtensionEntry *xext = CheckExtension (RANDR_NAME);
926 RETURN_IF_FAIL (xext != NULL);
927 RETURN_IF_FAIL (extinfo != NULL);
929 extinfo->opcode = xext->base;
930 extinfo->evt_base = xext->eventBase;
931 extinfo->err_base = xext->errorBase;
932 extinfo->req_func = _EvlogRequestRandr;
933 extinfo->evt_func = _EvlogEventRandr;
934 extinfo->rep_func = _EvlogReplyRandr;