1 // Copyright 2022 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 libWaylandClient_hpp 16 #define libWaylandClient_hpp 17 18 #include <wayland-client.h> 19 20 struct LibWaylandClientExports 21 { LibWaylandClientExportsLibWaylandClientExports22 LibWaylandClientExports() {} 23 LibWaylandClientExports(void *libwl); 24 25 int (*wl_display_dispatch)(wl_display *d) = nullptr; 26 wl_registry *(*wl_display_get_registry)(wl_display *d) = nullptr; 27 int (*wl_display_roundtrip)(wl_display *d) = nullptr; 28 wl_callback *(*wl_display_sync)(wl_display *d) = nullptr; 29 30 int (*wl_registry_add_listener)(wl_registry *r, 31 const wl_registry_listener *l, void *data) = nullptr; 32 void *(*wl_registry_bind)(wl_registry *r, uint32_t name, const wl_interface *i, uint32_t version) = nullptr; 33 34 void (*wl_buffer_destroy)(wl_buffer *b) = nullptr; 35 wl_shm_pool *(*wl_shm_create_pool)(wl_shm *shm, int32_t fd, int32_t size) = nullptr; 36 wl_buffer *(*wl_shm_pool_create_buffer)(wl_shm_pool *p, int32_t offset, int32_t width, int32_t height, int32_t stride, uint32_t format) = nullptr; 37 void (*wl_shm_pool_destroy)(wl_shm_pool *p) = nullptr; 38 39 void (*wl_surface_attach)(wl_surface *s, wl_buffer *b, int32_t x, int32_t y) = nullptr; 40 void (*wl_surface_damage)(wl_surface *s, int32_t x, int32_t y, int32_t width, int32_t height) = nullptr; 41 void (*wl_surface_commit)(wl_surface *s) = nullptr; 42 43 const wl_interface *wl_shm_interface = nullptr; 44 }; 45 46 class LibWaylandClient 47 { 48 public: isPresent()49 bool isPresent() 50 { 51 return loadExports() != nullptr; 52 } 53 54 LibWaylandClientExports *operator->(); 55 56 private: 57 LibWaylandClientExports *loadExports(); 58 }; 59 60 extern LibWaylandClient libWaylandClient; 61 62 #endif // libWaylandClient_hpp 63