Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Nicolas Capens | a36c990 | 2015-04-13 03:51:45 -0400 | [diff] [blame] | 15 | #ifndef libX11_hpp |
| 16 | #define libX11_hpp |
| 17 | |
| 18 | #define Bool int |
| 19 | #include <X11/Xlib.h> |
| 20 | #include <X11/Xutil.h> |
| 21 | #include <X11/extensions/XShm.h> |
| 22 | |
| 23 | struct LibX11exports |
| 24 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 25 | LibX11exports(void *libX11, void *libXext); |
Nicolas Capens | a36c990 | 2015-04-13 03:51:45 -0400 | [diff] [blame] | 26 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 27 | Display *(*XOpenDisplay)(char *display_name); |
| 28 | Status (*XGetWindowAttributes)(Display *display, Window w, XWindowAttributes *window_attributes_return); |
| 29 | Screen *(*XDefaultScreenOfDisplay)(Display *display); |
| 30 | int (*XWidthOfScreen)(Screen *screen); |
| 31 | int (*XHeightOfScreen)(Screen *screen); |
| 32 | int (*XPlanesOfScreen)(Screen *screen); |
| 33 | GC (*XDefaultGC)(Display *display, int screen_number); |
| 34 | int (*XDefaultDepth)(Display *display, int screen_number); |
| 35 | Status (*XMatchVisualInfo)(Display *display, int screen, int depth, int screen_class, XVisualInfo *vinfo_return); |
| 36 | Visual *(*XDefaultVisual)(Display *display, int screen_number); |
| 37 | int (*(*XSetErrorHandler)(int (*handler)(Display*, XErrorEvent*)))(Display*, XErrorEvent*); |
| 38 | int (*XSync)(Display *display, Bool discard); |
| 39 | XImage *(*XCreateImage)(Display *display, Visual *visual, unsigned int depth, int format, int offset, char *data, unsigned int width, unsigned int height, int bitmap_pad, int bytes_per_line); |
| 40 | int (*XCloseDisplay)(Display *display); |
| 41 | int (*XPutImage)(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height); |
Nicolas Capens | bba05f3 | 2017-09-15 14:59:38 -0400 | [diff] [blame] | 42 | int (*XDrawString)(Display *display, Drawable d, GC gc, int x, int y, char *string, int length); |
Nicolas Capens | a36c990 | 2015-04-13 03:51:45 -0400 | [diff] [blame] | 43 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 44 | Bool (*XShmQueryExtension)(Display *display); |
| 45 | XImage *(*XShmCreateImage)(Display *display, Visual *visual, unsigned int depth, int format, char *data, XShmSegmentInfo *shminfo, unsigned int width, unsigned int height); |
| 46 | Bool (*XShmAttach)(Display *display, XShmSegmentInfo *shminfo); |
| 47 | Bool (*XShmDetach)(Display *display, XShmSegmentInfo *shminfo); |
| 48 | int (*XShmPutImage)(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height, bool send_event); |
Nicolas Capens | a36c990 | 2015-04-13 03:51:45 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
Chris Forbes | c296806 | 2019-03-19 16:48:03 -0700 | [diff] [blame] | 51 | #undef Bool // b/127920555 |
Nicolas Capens | a36c990 | 2015-04-13 03:51:45 -0400 | [diff] [blame] | 52 | |
| 53 | class LibX11 |
| 54 | { |
| 55 | public: |
Nicolas Capens | 82196a2 | 2015-04-20 13:50:37 -0400 | [diff] [blame] | 56 | operator bool() |
| 57 | { |
| 58 | return loadExports(); |
| 59 | } |
| 60 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 61 | LibX11exports *operator->(); |
Nicolas Capens | 82196a2 | 2015-04-20 13:50:37 -0400 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | LibX11exports *loadExports(); |
Nicolas Capens | a36c990 | 2015-04-13 03:51:45 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | extern LibX11 libX11; |
| 68 | |
| 69 | #endif // libX11_hpp |