Mercurial > sdl-ios-xcode
comparison src/video/Xext/Xv/Xv.c @ 1168:045f186426e1
Dynamically load X11 libraries like we currently do for alsa, esd, etc.
This allows you to run an SDL program on a system without Xlib, since it'll
just report the x11 target unavailable at runtime.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 05 Nov 2005 19:53:37 +0000 |
parents | c1666427297c |
children | d05306f0dc21 |
comparison
equal
deleted
inserted
replaced
1167:435c2e481299 | 1168:045f186426e1 |
---|---|
54 #include "Xvlibint.h" | 54 #include "Xvlibint.h" |
55 #include <X11/extensions/Xext.h> | 55 #include <X11/extensions/Xext.h> |
56 #include <X11/extensions/XShm.h> | 56 #include <X11/extensions/XShm.h> |
57 #include "extutil.h" | 57 #include "extutil.h" |
58 | 58 |
59 #include "../../x11/SDL_x11dyn.h" | |
60 | |
61 /* Workaround code in headers... */ | |
62 #define _XFlush p_XFlush | |
63 #define _XFlushGCCache p_XFlushGCCache | |
64 #define _XReply p_XReply | |
65 #define _XSend p_XSend | |
66 | |
59 static XExtensionInfo _xv_info_data; | 67 static XExtensionInfo _xv_info_data; |
60 static XExtensionInfo *xv_info = &_xv_info_data; | 68 static XExtensionInfo *xv_info = &_xv_info_data; |
61 static char *xv_extension_name = XvName; | 69 static char *xv_extension_name = XvName; |
62 | 70 |
63 #define XvCheckExtension(dpy, i, val) \ | 71 #define XvCheckExtension(dpy, i, val) \ |
119 | 127 |
120 LockDisplay(dpy); | 128 LockDisplay(dpy); |
121 | 129 |
122 XvGetReq(QueryExtension, req); | 130 XvGetReq(QueryExtension, req); |
123 | 131 |
124 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { | 132 if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) { |
125 UnlockDisplay(dpy); | 133 UnlockDisplay(dpy); |
126 SyncHandle(); | 134 SyncHandle(); |
127 return XvBadExtension; | 135 return XvBadExtension; |
128 } | 136 } |
129 | 137 |
169 XvGetReq(QueryAdaptors, req); | 177 XvGetReq(QueryAdaptors, req); |
170 req->window = window; | 178 req->window = window; |
171 | 179 |
172 /* READ THE REPLY */ | 180 /* READ THE REPLY */ |
173 | 181 |
174 if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { | 182 if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { |
175 UnlockDisplay(dpy); | 183 UnlockDisplay(dpy); |
176 SyncHandle(); | 184 SyncHandle(); |
177 return(XvBadReply); | 185 return(XvBadReply); |
178 } | 186 } |
179 | 187 |
181 if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) { | 189 if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) { |
182 UnlockDisplay(dpy); | 190 UnlockDisplay(dpy); |
183 SyncHandle(); | 191 SyncHandle(); |
184 return(XvBadAlloc); | 192 return(XvBadAlloc); |
185 } | 193 } |
186 _XRead (dpy, buffer, size); | 194 p_XRead (dpy, buffer, size); |
187 | 195 |
188 u.buffer = buffer; | 196 u.buffer = buffer; |
189 | 197 |
190 /* GET INPUT ADAPTORS */ | 198 /* GET INPUT ADAPTORS */ |
191 | 199 |
329 XvGetReq(QueryEncodings, req); | 337 XvGetReq(QueryEncodings, req); |
330 req->port = port; | 338 req->port = port; |
331 | 339 |
332 /* READ THE REPLY */ | 340 /* READ THE REPLY */ |
333 | 341 |
334 if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { | 342 if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { |
335 UnlockDisplay(dpy); | 343 UnlockDisplay(dpy); |
336 SyncHandle(); | 344 SyncHandle(); |
337 return(XvBadReply); | 345 return(XvBadReply); |
338 } | 346 } |
339 | 347 |
341 if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) { | 349 if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) { |
342 UnlockDisplay(dpy); | 350 UnlockDisplay(dpy); |
343 SyncHandle(); | 351 SyncHandle(); |
344 return(XvBadAlloc); | 352 return(XvBadAlloc); |
345 } | 353 } |
346 _XRead (dpy, buffer, size); | 354 p_XRead (dpy, buffer, size); |
347 | 355 |
348 u.buffer = buffer; | 356 u.buffer = buffer; |
349 | 357 |
350 /* GET ENCODINGS */ | 358 /* GET ENCODINGS */ |
351 | 359 |
617 | 625 |
618 XvGetReq(GrabPort, req); | 626 XvGetReq(GrabPort, req); |
619 req->port = port; | 627 req->port = port; |
620 req->time = time; | 628 req->time = time; |
621 | 629 |
622 if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0) | 630 if (p_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0) |
623 rep.result = GrabSuccess; | 631 rep.result = GrabSuccess; |
624 | 632 |
625 result = rep.result; | 633 result = rep.result; |
626 | 634 |
627 UnlockDisplay(dpy); | 635 UnlockDisplay(dpy); |
745 req->port = port; | 753 req->port = port; |
746 req->attribute = attribute; | 754 req->attribute = attribute; |
747 | 755 |
748 /* READ THE REPLY */ | 756 /* READ THE REPLY */ |
749 | 757 |
750 if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { | 758 if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { |
751 UnlockDisplay(dpy); | 759 UnlockDisplay(dpy); |
752 SyncHandle(); | 760 SyncHandle(); |
753 return(XvBadReply); | 761 return(XvBadReply); |
754 } | 762 } |
755 | 763 |
790 req->drw_w = drw_w; | 798 req->drw_w = drw_w; |
791 req->drw_h = drw_h; | 799 req->drw_h = drw_h; |
792 | 800 |
793 /* READ THE REPLY */ | 801 /* READ THE REPLY */ |
794 | 802 |
795 if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { | 803 if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { |
796 UnlockDisplay(dpy); | 804 UnlockDisplay(dpy); |
797 SyncHandle(); | 805 SyncHandle(); |
798 return(XvBadReply); | 806 return(XvBadReply); |
799 } | 807 } |
800 | 808 |
825 XvGetReq(QueryPortAttributes, req); | 833 XvGetReq(QueryPortAttributes, req); |
826 req->port = port; | 834 req->port = port; |
827 | 835 |
828 /* READ THE REPLY */ | 836 /* READ THE REPLY */ |
829 | 837 |
830 if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { | 838 if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { |
831 UnlockDisplay(dpy); | 839 UnlockDisplay(dpy); |
832 SyncHandle(); | 840 SyncHandle(); |
833 return ret; | 841 return ret; |
834 } | 842 } |
835 | 843 |
840 char* marker = (char*)(&ret[rep.num_attributes]); | 848 char* marker = (char*)(&ret[rep.num_attributes]); |
841 xvAttributeInfo Info; | 849 xvAttributeInfo Info; |
842 int i; | 850 int i; |
843 | 851 |
844 for(i = 0; i < rep.num_attributes; i++) { | 852 for(i = 0; i < rep.num_attributes; i++) { |
845 _XRead(dpy, (char*)(&Info), sz_xvAttributeInfo); | 853 p_XRead(dpy, (char*)(&Info), sz_xvAttributeInfo); |
846 ret[i].flags = (int)Info.flags; | 854 ret[i].flags = (int)Info.flags; |
847 ret[i].min_value = Info.min; | 855 ret[i].min_value = Info.min; |
848 ret[i].max_value = Info.max; | 856 ret[i].max_value = Info.max; |
849 ret[i].name = marker; | 857 ret[i].name = marker; |
850 _XRead(dpy, marker, Info.size); | 858 p_XRead(dpy, marker, Info.size); |
851 marker += Info.size; | 859 marker += Info.size; |
852 (*num)++; | 860 (*num)++; |
853 } | 861 } |
854 } else | 862 } else |
855 _XEatData(dpy, rep.length << 2); | 863 p_XEatData(dpy, rep.length << 2); |
856 } | 864 } |
857 | 865 |
858 UnlockDisplay(dpy); | 866 UnlockDisplay(dpy); |
859 SyncHandle(); | 867 SyncHandle(); |
860 | 868 |
880 XvGetReq(ListImageFormats, req); | 888 XvGetReq(ListImageFormats, req); |
881 req->port = port; | 889 req->port = port; |
882 | 890 |
883 /* READ THE REPLY */ | 891 /* READ THE REPLY */ |
884 | 892 |
885 if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { | 893 if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { |
886 UnlockDisplay(dpy); | 894 UnlockDisplay(dpy); |
887 SyncHandle(); | 895 SyncHandle(); |
888 return NULL; | 896 return NULL; |
889 } | 897 } |
890 | 898 |
894 if((ret = Xmalloc(size))) { | 902 if((ret = Xmalloc(size))) { |
895 xvImageFormatInfo Info; | 903 xvImageFormatInfo Info; |
896 int i; | 904 int i; |
897 | 905 |
898 for(i = 0; i < rep.num_formats; i++) { | 906 for(i = 0; i < rep.num_formats; i++) { |
899 _XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo); | 907 p_XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo); |
900 ret[i].id = Info.id; | 908 ret[i].id = Info.id; |
901 ret[i].type = Info.type; | 909 ret[i].type = Info.type; |
902 ret[i].byte_order = Info.byte_order; | 910 ret[i].byte_order = Info.byte_order; |
903 memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16); | 911 memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16); |
904 ret[i].bits_per_pixel = Info.bpp; | 912 ret[i].bits_per_pixel = Info.bpp; |
920 memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32); | 928 memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32); |
921 ret[i].scanline_order = Info.scanline_order; | 929 ret[i].scanline_order = Info.scanline_order; |
922 (*num)++; | 930 (*num)++; |
923 } | 931 } |
924 } else | 932 } else |
925 _XEatData(dpy, rep.length << 2); | 933 p_XEatData(dpy, rep.length << 2); |
926 } | 934 } |
927 | 935 |
928 UnlockDisplay(dpy); | 936 UnlockDisplay(dpy); |
929 SyncHandle(); | 937 SyncHandle(); |
930 | 938 |
954 req->width = width; | 962 req->width = width; |
955 req->height = height; | 963 req->height = height; |
956 | 964 |
957 /* READ THE REPLY */ | 965 /* READ THE REPLY */ |
958 | 966 |
959 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { | 967 if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) { |
960 UnlockDisplay(dpy); | 968 UnlockDisplay(dpy); |
961 SyncHandle(); | 969 SyncHandle(); |
962 return NULL; | 970 return NULL; |
963 } | 971 } |
964 | 972 |
970 ret->num_planes = rep.num_planes; | 978 ret->num_planes = rep.num_planes; |
971 ret->pitches = (int*)(&ret[1]); | 979 ret->pitches = (int*)(&ret[1]); |
972 ret->offsets = ret->pitches + rep.num_planes; | 980 ret->offsets = ret->pitches + rep.num_planes; |
973 ret->data = data; | 981 ret->data = data; |
974 ret->obdata = NULL; | 982 ret->obdata = NULL; |
975 _XRead(dpy, (char*)(ret->pitches), rep.num_planes << 2); | 983 p_XRead(dpy, (char*)(ret->pitches), rep.num_planes << 2); |
976 _XRead(dpy, (char*)(ret->offsets), rep.num_planes << 2); | 984 p_XRead(dpy, (char*)(ret->offsets), rep.num_planes << 2); |
977 } else | 985 } else |
978 _XEatData(dpy, rep.length << 2); | 986 p_XEatData(dpy, rep.length << 2); |
979 | 987 |
980 UnlockDisplay(dpy); | 988 UnlockDisplay(dpy); |
981 SyncHandle(); | 989 SyncHandle(); |
982 return ret; | 990 return ret; |
983 } | 991 } |
1122 switch((event->u.u.type & 0x7F) - info->codes->first_event) | 1130 switch((event->u.u.type & 0x7F) - info->codes->first_event) |
1123 { | 1131 { |
1124 case XvVideoNotify: | 1132 case XvVideoNotify: |
1125 re->xvvideo.type = event->u.u.type & 0x7f; | 1133 re->xvvideo.type = event->u.u.type & 0x7f; |
1126 re->xvvideo.serial = | 1134 re->xvvideo.serial = |
1127 _XSetLastRequestRead(dpy, (xGenericReply *)event); | 1135 p_XSetLastRequestRead(dpy, (xGenericReply *)event); |
1128 re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0); | 1136 re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0); |
1129 re->xvvideo.display = dpy; | 1137 re->xvvideo.display = dpy; |
1130 re->xvvideo.time = event->u.videoNotify.time; | 1138 re->xvvideo.time = event->u.videoNotify.time; |
1131 re->xvvideo.reason = event->u.videoNotify.reason; | 1139 re->xvvideo.reason = event->u.videoNotify.reason; |
1132 re->xvvideo.drawable = event->u.videoNotify.drawable; | 1140 re->xvvideo.drawable = event->u.videoNotify.drawable; |
1133 re->xvvideo.port_id = event->u.videoNotify.port; | 1141 re->xvvideo.port_id = event->u.videoNotify.port; |
1134 break; | 1142 break; |
1135 case XvPortNotify: | 1143 case XvPortNotify: |
1136 re->xvport.type = event->u.u.type & 0x7f; | 1144 re->xvport.type = event->u.u.type & 0x7f; |
1137 re->xvport.serial = | 1145 re->xvport.serial = |
1138 _XSetLastRequestRead(dpy, (xGenericReply *)event); | 1146 p_XSetLastRequestRead(dpy, (xGenericReply *)event); |
1139 re->xvport.send_event = ((event->u.u.type & 0x80) != 0); | 1147 re->xvport.send_event = ((event->u.u.type & 0x80) != 0); |
1140 re->xvport.display = dpy; | 1148 re->xvport.display = dpy; |
1141 re->xvport.time = event->u.portNotify.time; | 1149 re->xvport.time = event->u.portNotify.time; |
1142 re->xvport.port_id = event->u.portNotify.port; | 1150 re->xvport.port_id = event->u.portNotify.port; |
1143 re->xvport.attribute = event->u.portNotify.attribute; | 1151 re->xvport.attribute = event->u.portNotify.attribute; |