1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 12 дек. 2016 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef UI_WS_IDISPLAY_H_ 23 #define UI_WS_IDISPLAY_H_ 24 25 #include <data/cstorage.h> 26 #include <data/cvector.h> 27 #include <rendering/backend.h> 28 #include <rendering/factory.h> 29 #include <core/ipc/Library.h> 30 31 namespace lsp 32 { 33 namespace ws 34 { 35 class INativeWindow; 36 class IR3DBackend; 37 38 typedef struct R3DBackendInfo 39 { 40 LSPString library; 41 LSPString uid; 42 LSPString display; 43 } R3DBackendInfo; 44 45 /** Display 46 * 47 */ 48 class IDisplay 49 { 50 protected: 51 typedef struct dtask_t 52 { 53 taskid_t nID; 54 timestamp_t nTime; 55 task_handler_t pHandler; 56 void *pArg; 57 } dtask_t; 58 59 typedef struct r3d_library_t: public R3DBackendInfo 60 { 61 r3d_factory_t *builtin; // Built-in factory 62 size_t local_id; // Local identifier 63 } r3d_library_t; 64 65 protected: 66 taskid_t nTaskID; 67 cstorage<dtask_t> sTasks; 68 dtask_t sMainTask; 69 cvector<r3d_library_t> s3DLibs; // List of libraries that provide 3D backends 70 cvector<IR3DBackend> s3DBackends; // List of all 3D backend instances 71 ipc::Library s3DLibrary; // Current backend library used 72 r3d_factory_t *s3DFactory; // Pointer to the factory object 73 ssize_t nCurrent3D; // Current 3D backend 74 ssize_t nPending3D; // Pending 3D backend 75 76 protected: 77 friend class IR3DBackend; 78 79 bool taskid_exists(taskid_t id); 80 void deregister_backend(IR3DBackend *lib); 81 status_t switch_r3d_backend(r3d_library_t *backend); 82 status_t commit_r3d_factory(const LSPString *path, r3d_factory_t *factory); 83 void detach_r3d_backends(); 84 void call_main_task(timestamp_t time); 85 86 public: 87 explicit IDisplay(); 88 virtual ~IDisplay(); 89 90 public: 91 virtual int init(int argc, const char **argv); 92 virtual void destroy(); 93 94 virtual int main(); 95 virtual status_t main_iteration(); 96 virtual void quit_main(); 97 98 virtual size_t screens(); 99 virtual size_t default_screen(); 100 101 virtual void sync(); 102 103 virtual status_t screen_size(size_t screen, ssize_t *w, ssize_t *h); 104 105 public: 106 /** 107 * Enumerate backends 108 * @param id backend number starting with 0 109 * @return backend descriptor or NULL if backend with such identifier does not exist 110 */ 111 const R3DBackendInfo *enum_backend(size_t id) const; 112 113 /** 114 * Get currently used backend for 3D rendering 115 * @return selected backend descriptor 116 */ 117 const R3DBackendInfo *current_backend() const; 118 119 /** 120 * Get currently used backend identifier for 3D rendering 121 * @return selected backend identifier 122 */ 123 ssize_t current_backend_id() const; 124 125 /** 126 * Select backend for rendering by specifying it's descriptor 127 * This function does not chnage the backend immediately, 128 * instead of this the backend switch operation is performed in the 129 * main loop 130 * @param backend backend for rendering 131 * @return status of operation 132 */ 133 status_t select_backend(const R3DBackendInfo *backend); 134 135 /** 136 * Select backend for rendering by specifying it's descriptor identifier 137 * This function does not chnage the backend immediately, 138 * instead of this the backend switch operation is performed in the 139 * main loop 140 * @param id backend's descriptor identifier 141 * @return status of operation 142 */ 143 status_t select_backend_id(size_t id); 144 145 /** 146 * Lookup the specified directory for existing 3D backends 147 * @param path the directory to perform lookup 148 */ 149 void lookup_r3d_backends(const io::Path *path); 150 151 /** 152 * Lookup the specified directory for existing 3D backends 153 * @param path the directory to perform lookup 154 */ 155 void lookup_r3d_backends(const char *path); 156 157 /** 158 * Lookup the specified directory for existing 3D backends 159 * @param path the directory to perform lookup 160 */ 161 void lookup_r3d_backends(const LSPString *path); 162 163 /** 164 * Try to register the library as a 3D backend 165 * @param path the path to the library 166 * @return status of operation 167 */ 168 status_t register_r3d_backend(const io::Path *path); 169 170 /** 171 * Try to register the library as a 3D backend 172 * @param path the path to the library 173 * @return status of operation 174 */ 175 status_t register_r3d_backend(const char *path); 176 177 /** 178 * Try to register the library as a 3D backend 179 * @param path the path to the library 180 * @return status of operation 181 */ 182 status_t register_r3d_backend(const LSPString *path); 183 184 185 /** Create native window 186 * 187 * @return native window 188 */ 189 virtual INativeWindow *create_window(); 190 191 /** Create window at the specified screen 192 * 193 * @param screen screen 194 * @return status native window 195 */ 196 virtual INativeWindow *create_window(size_t screen); 197 198 /** Create native window as child of specified window handle 199 * 200 * @return native window as child of specified window handle 201 */ 202 virtual INativeWindow *create_window(void *handle); 203 204 /** 205 * Wrap window handle 206 * @param handle handle to wrap 207 * @return native window as wrapper of the handle 208 */ 209 virtual INativeWindow *wrap_window(void *handle); 210 211 /** 212 * Create 3D backend for graphics 213 * @return pointer to created backend 214 */ 215 virtual IR3DBackend *create_r3D_backend(INativeWindow *parent); 216 217 /** Create surface for drawing 218 * 219 * @param width surface width 220 * @param height surface height 221 * @return surface or NULL on error 222 */ 223 virtual ISurface *create_surface(size_t width, size_t height); 224 225 /** Submit task for execution 226 * 227 * @param time time when the task should be triggered (timestamp in milliseconds) 228 * @param handler task handler 229 * @param arg task handler argument 230 * @return submitted task identifier or negative error code 231 */ 232 virtual taskid_t submit_task(timestamp_t time, task_handler_t handler, void *arg); 233 234 /** Cancel submitted task 235 * 236 * @param id task identifier to cancel 237 * @return status of operation 238 */ 239 virtual status_t cancel_task(taskid_t id); 240 241 /** 242 * Associate data source with the specified clipboard 243 * @param id clipboard identifier 244 * @param src data source to use 245 * @return status of operation 246 */ 247 virtual status_t set_clipboard(size_t id, IDataSource *src); 248 249 /** 250 * Sink clipboard data source to the specified handler. 251 * After the data source has been processed, release() should 252 * be called on data source 253 * @param id clipboard identifier 254 * @return pointer to data source or NULL 255 */ 256 virtual status_t get_clipboard(size_t id, IDataSink *dst); 257 258 /** 259 * Reject drag request because drag is not supported at the current position 260 * @return status of operation 261 */ 262 virtual status_t reject_drag(); 263 264 /** 265 * Accept drag request 266 * @param sink the sink that will handle data transfer 267 * @param action drag action 268 * @param internal true if we want to receive notifications inside of the drag rectangle 269 * @param r parameters of the drag rectangle, can be NULL 270 * @return status of operation 271 */ 272 virtual status_t accept_drag(IDataSink *sink, drag_t action, bool internal, const realize_t *r); 273 274 /** 275 * Get currently pending content type of a drag 276 * @return NULL-terminated list of pending content types, 277 * may be NULL if there is no currently pending Drag&Drop request 278 */ 279 virtual const char * const *get_drag_ctypes(); 280 281 /** 282 * Set callback which will be called after each main iteration 283 * @param handler callback handler routine 284 * @param arg additional argument 285 */ 286 void set_main_callback(task_handler_t handler, void *arg); 287 }; 288 289 } /* namespace ws */ 290 } /* namespace lsp */ 291 292 #endif /* UI_IDISPLAY_H_ */ 293