1 // Copyright 2021 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 15 #ifndef libXCB_hpp 16 #define libXCB_hpp 17 18 #include <xcb/xcb.h> 19 20 struct LibXcbExports 21 { LibXcbExportsLibXcbExports22 LibXcbExports() {} 23 LibXcbExports(void *lib); 24 25 xcb_void_cookie_t (*xcb_create_gc)(xcb_connection_t *c, xcb_gcontext_t cid, xcb_drawable_t drawable, uint32_t value_mask, const void *value_list) = nullptr; 26 int (*xcb_flush)(xcb_connection_t *c) = nullptr; 27 xcb_void_cookie_t (*xcb_free_gc)(xcb_connection_t *c, xcb_gcontext_t gc) = nullptr; 28 uint32_t (*xcb_generate_id)(xcb_connection_t *c) = nullptr; 29 xcb_get_geometry_cookie_t (*xcb_get_geometry)(xcb_connection_t *c, xcb_drawable_t drawable) = nullptr; 30 xcb_get_geometry_reply_t *(*xcb_get_geometry_reply)(xcb_connection_t *c, xcb_get_geometry_cookie_t cookie, xcb_generic_error_t **e) = nullptr; 31 xcb_void_cookie_t (*xcb_put_image)(xcb_connection_t *c, uint8_t format, xcb_drawable_t drawable, xcb_gcontext_t gc, uint16_t width, uint16_t height, int16_t dst_x, int16_t dst_y, uint8_t left_pad, uint8_t depth, uint32_t data_len, const uint8_t *data) = nullptr; 32 }; 33 34 class LibXCB 35 { 36 public: isPresent()37 bool isPresent() 38 { 39 return loadExports() != nullptr; 40 } 41 42 LibXcbExports *operator->(); 43 44 private: 45 LibXcbExports *loadExports(); 46 }; 47 48 extern LibXCB libXCB; 49 50 #endif // libXCB_hpp 51