| 1 | /* |
| 2 | * Copyright © 2008 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <[email protected]> |
| 25 | * Zhigang Gong <[email protected]> |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | #ifndef GLAMOR_H |
| 30 | #define GLAMOR_H |
| 31 | |
| 32 | #include <scrnintstr.h> |
| 33 | #include <pixmapstr.h> |
| 34 | #include <gcstruct.h> |
| 35 | #include <picturestr.h> |
| 36 | #include <fb.h> |
| 37 | #include <fbpict.h> |
| 38 | #ifdef GLAMOR_FOR_XORG |
| 39 | #include <xf86xv.h> |
| 40 | #endif |
| 41 | |
| 42 | struct glamor_context; |
| 43 | struct gbm_bo; |
| 44 | struct gbm_device; |
| 45 | |
| 46 | /* |
| 47 | * glamor_pixmap_type : glamor pixmap's type. |
| 48 | * @MEMORY: pixmap is in memory. |
| 49 | * @TEXTURE_DRM: pixmap is in a texture created from a DRM buffer. |
| 50 | * @SEPARATE_TEXTURE: The texture is created from a DRM buffer, but |
| 51 | * the format is incompatible, so this type of pixmap |
| 52 | * will never fallback to DDX layer. |
| 53 | * @DRM_ONLY: pixmap is in a external DRM buffer. |
| 54 | * @TEXTURE_ONLY: pixmap is in an internal texture. |
| 55 | */ |
| 56 | typedef enum glamor_pixmap_type { |
| 57 | GLAMOR_MEMORY = 0, /* Newly calloc()ed pixmaps are memory. */ |
| 58 | GLAMOR_TEXTURE_DRM, |
| 59 | GLAMOR_DRM_ONLY, |
| 60 | GLAMOR_TEXTURE_ONLY, |
| 61 | } glamor_pixmap_type_t; |
| 62 | |
| 63 | typedef Bool (*GetDrawableModifiersFuncPtr) (DrawablePtr draw, |
| 64 | uint32_t format, |
| 65 | uint32_t *num_modifiers, |
| 66 | uint64_t **modifiers); |
| 67 | |
| 68 | #define GLAMOR_EGL_EXTERNAL_BUFFER 3 |
| 69 | #define GLAMOR_USE_EGL_SCREEN (1 << 0) |
| 70 | #define GLAMOR_NO_DRI3 (1 << 1) |
| 71 | #define GLAMOR_VALID_FLAGS (GLAMOR_USE_EGL_SCREEN \ |
| 72 | | GLAMOR_NO_DRI3) |
| 73 | |
| 74 | /* until we need geometry shaders GL3.1 should suffice. */ |
| 75 | #define GLAMOR_GL_CORE_VER_MAJOR 3 |
| 76 | #define GLAMOR_GL_CORE_VER_MINOR 1 |
| 77 | |
| 78 | /* @glamor_init: Initialize glamor internal data structure. |
| 79 | * |
| 80 | * @screen: Current screen pointer. |
| 81 | * @flags: Please refer the flags description above. |
| 82 | * |
| 83 | * @GLAMOR_USE_EGL_SCREEN: |
| 84 | * If you are using EGL layer, then please set this bit |
| 85 | * on, otherwise, clear it. |
| 86 | * |
| 87 | * @GLAMOR_NO_DRI3 |
| 88 | * Disable the built-in DRI3 support |
| 89 | * |
| 90 | * This function initializes necessary internal data structure |
| 91 | * for glamor. And before calling into this function, the OpenGL |
| 92 | * environment should be ready. Should be called before any real |
| 93 | * glamor rendering or texture allocation functions. And should |
| 94 | * be called after the DDX's screen initialization or at the last |
| 95 | * step of the DDX's screen initialization. |
| 96 | */ |
| 97 | extern _X_EXPORT Bool glamor_init(ScreenPtr screen, unsigned int flags); |
| 98 | extern _X_EXPORT void glamor_fini(ScreenPtr screen); |
| 99 | |
| 100 | /* This function is used to free the glamor private screen's |
| 101 | * resources. If the DDX driver is not set GLAMOR_USE_SCREEN, |
| 102 | * then, DDX need to call this function at proper stage, if |
| 103 | * it is the xorg DDX driver,then it should be called at free |
| 104 | * screen stage not the close screen stage. The reason is after |
| 105 | * call to this function, the xorg DDX may need to destroy the |
| 106 | * screen pixmap which must be a glamor pixmap and requires |
| 107 | * the internal data structure still exist at that time. |
| 108 | * Otherwise, the glamor internal structure will not be freed.*/ |
| 109 | extern _X_EXPORT Bool glamor_close_screen(ScreenPtr screen); |
| 110 | |
| 111 | extern _X_EXPORT uint32_t glamor_get_pixmap_texture(PixmapPtr pixmap); |
| 112 | |
| 113 | extern _X_EXPORT Bool glamor_set_pixmap_texture(PixmapPtr pixmap, |
| 114 | unsigned int tex); |
| 115 | |
| 116 | extern _X_EXPORT void glamor_set_pixmap_type(PixmapPtr pixmap, |
| 117 | glamor_pixmap_type_t type); |
| 118 | |
| 119 | extern _X_EXPORT void glamor_clear_pixmap(PixmapPtr pixmap); |
| 120 | |
| 121 | extern _X_EXPORT void glamor_block_handler(ScreenPtr screen); |
| 122 | |
| 123 | /* This function should be called after glamor_init, |
| 124 | * but before adding a glamor GLX provider */ |
| 125 | extern _X_EXPORT void glamor_set_glvnd_vendor(ScreenPtr screen, |
| 126 | const char *vendor); |
| 127 | extern _X_EXPORT const char *glamor_get_glvnd_vendor(ScreenPtr screen); |
| 128 | |
| 129 | extern _X_EXPORT PixmapPtr glamor_create_pixmap(ScreenPtr screen, int w, int h, |
| 130 | int depth, unsigned int usage); |
| 131 | extern _X_EXPORT Bool glamor_destroy_pixmap(PixmapPtr pixmap); |
| 132 | |
| 133 | #define GLAMOR_CREATE_PIXMAP_CPU 0x100 |
| 134 | #define GLAMOR_CREATE_PIXMAP_FIXUP 0x101 |
| 135 | #define GLAMOR_CREATE_FBO_NO_FBO 0x103 |
| 136 | #define GLAMOR_CREATE_NO_LARGE 0x105 |
| 137 | #define GLAMOR_CREATE_PIXMAP_NO_TEXTURE 0x106 |
| 138 | #define GLAMOR_CREATE_FORMAT_CBCR 0x107 |
| 139 | |
| 140 | /* @glamor_egl_exchange_buffers: Exchange the underlying buffers(KHR image,fbo). |
| 141 | * |
| 142 | * @front: front pixmap. |
| 143 | * @back: back pixmap. |
| 144 | * |
| 145 | * Used by the DRI2 page flip. This function will exchange the KHR images and |
| 146 | * fbos of the two pixmaps. |
| 147 | * */ |
| 148 | extern _X_EXPORT void glamor_egl_exchange_buffers(PixmapPtr front, |
| 149 | PixmapPtr back); |
| 150 | |
| 151 | extern _X_EXPORT void glamor_pixmap_exchange_fbos(PixmapPtr front, |
| 152 | PixmapPtr back); |
| 153 | |
| 154 | /* The DDX is not supposed to call these four functions */ |
| 155 | extern _X_EXPORT void glamor_enable_dri3(ScreenPtr screen); |
| 156 | extern _X_EXPORT int glamor_egl_fds_from_pixmap(ScreenPtr, PixmapPtr, int *, |
| 157 | uint32_t *, uint32_t *, |
| 158 | uint64_t *); |
| 159 | extern _X_EXPORT int glamor_egl_fd_name_from_pixmap(ScreenPtr, PixmapPtr, |
| 160 | CARD16 *, CARD32 *); |
| 161 | |
| 162 | extern _X_EXPORT struct gbm_device *glamor_egl_get_gbm_device(ScreenPtr screen); |
| 163 | extern _X_EXPORT int glamor_egl_fd_from_pixmap(ScreenPtr, PixmapPtr, CARD16 *, CARD32 *); |
| 164 | |
| 165 | /* @glamor_supports_pixmap_import_export: Returns whether |
| 166 | * glamor_fds_from_pixmap(), glamor_name_from_pixmap(), and |
| 167 | * glamor_pixmap_from_fds() are supported. |
| 168 | * |
| 169 | * @screen: Current screen pointer. |
| 170 | * |
| 171 | * To have DRI3 support enabled, glamor and glamor_egl need to be |
| 172 | * initialized. glamor also has to be compiled with gbm support. |
| 173 | * |
| 174 | * The EGL layer needs to have the following extensions working: |
| 175 | * |
| 176 | * .EGL_KHR_surfaceless_context |
| 177 | * */ |
| 178 | extern _X_EXPORT Bool glamor_supports_pixmap_import_export(ScreenPtr screen); |
| 179 | |
| 180 | /* @glamor_fds_from_pixmap: Get a dma-buf fd from a pixmap. |
| 181 | * |
| 182 | * @screen: Current screen pointer. |
| 183 | * @pixmap: The pixmap from which we want the fd. |
| 184 | * @fds, @strides, @offsets: Pointers to fill info of each plane. |
| 185 | * @modifier: Pointer to fill the modifier of the buffer. |
| 186 | * |
| 187 | * the pixmap and the buffer associated by the fds will share the same |
| 188 | * content. The caller is responsible to close the returned file descriptors. |
| 189 | * Returns the number of planes, -1 on error. |
| 190 | * */ |
| 191 | extern _X_EXPORT int glamor_fds_from_pixmap(ScreenPtr screen, |
| 192 | PixmapPtr pixmap, |
| 193 | int *fds, |
| 194 | uint32_t *strides, uint32_t *offsets, |
| 195 | uint64_t *modifier); |
| 196 | |
| 197 | /* @glamor_fd_from_pixmap: Get a dma-buf fd from a pixmap. |
| 198 | * |
| 199 | * @screen: Current screen pointer. |
| 200 | * @pixmap: The pixmap from which we want the fd. |
| 201 | * @stride, @size: Pointers to fill the stride and size of the |
| 202 | * buffer associated to the fd. |
| 203 | * |
| 204 | * the pixmap and the buffer associated by the fd will share the same |
| 205 | * content. |
| 206 | * Returns the fd on success, -1 on error. |
| 207 | * */ |
| 208 | extern _X_EXPORT int glamor_fd_from_pixmap(ScreenPtr screen, |
| 209 | PixmapPtr pixmap, |
| 210 | CARD16 *stride, CARD32 *size); |
| 211 | |
| 212 | /* @glamor_shareable_fd_from_pixmap: Get a dma-buf fd suitable for sharing |
| 213 | * with other GPUs from a pixmap. |
| 214 | * |
| 215 | * @screen: Current screen pointer. |
| 216 | * @pixmap: The pixmap from which we want the fd. |
| 217 | * @stride, @size: Pointers to fill the stride and size of the |
| 218 | * buffer associated to the fd. |
| 219 | * |
| 220 | * The returned fd will point to a buffer which is suitable for sharing |
| 221 | * across GPUs (not using GPU specific tiling). |
| 222 | * The pixmap and the buffer associated by the fd will share the same |
| 223 | * content. |
| 224 | * The pixmap's stride may be modified by this function. |
| 225 | * Returns the fd on success, -1 on error. |
| 226 | * */ |
| 227 | extern _X_EXPORT int glamor_shareable_fd_from_pixmap(ScreenPtr screen, |
| 228 | PixmapPtr pixmap, |
| 229 | CARD16 *stride, |
| 230 | CARD32 *size); |
| 231 | |
| 232 | /** |
| 233 | * @glamor_name_from_pixmap: Gets a gem name from a pixmap. |
| 234 | * |
| 235 | * @pixmap: The pixmap from which we want the gem name. |
| 236 | * |
| 237 | * the pixmap and the buffer associated by the gem name will share the |
| 238 | * same content. This function can be used by the DDX to support DRI2, |
| 239 | * and needs the same set of buffer export GL extensions as DRI3 |
| 240 | * support. |
| 241 | * |
| 242 | * Returns the name on success, -1 on error. |
| 243 | * */ |
| 244 | extern _X_EXPORT int glamor_name_from_pixmap(PixmapPtr pixmap, |
| 245 | CARD16 *stride, CARD32 *size); |
| 246 | |
| 247 | /* @glamor_gbm_bo_from_pixmap: Get a GBM bo from a pixmap. |
| 248 | * |
| 249 | * @screen: Current screen pointer. |
| 250 | * @pixmap: The pixmap from which we want the fd. |
| 251 | * @stride, @size: Pointers to fill the stride and size of the |
| 252 | * buffer associated to the fd. |
| 253 | * |
| 254 | * the pixmap and the buffer represented by the gbm_bo will share the same |
| 255 | * content. |
| 256 | * |
| 257 | * Returns the gbm_bo on success, NULL on error. |
| 258 | * */ |
| 259 | extern _X_EXPORT struct gbm_bo *glamor_gbm_bo_from_pixmap(ScreenPtr screen, |
| 260 | PixmapPtr pixmap); |
| 261 | |
| 262 | /* @glamor_pixmap_from_fds: Creates a pixmap to wrap a dma-buf fds. |
| 263 | * |
| 264 | * @screen: Current screen pointer. |
| 265 | * @num_fds: Number of fds to import |
| 266 | * @fds: The dma-buf fds to import. |
| 267 | * @width: The width of the buffers. |
| 268 | * @height: The height of the buffers. |
| 269 | * @stride: The stride of the buffers. |
| 270 | * @depth: The depth of the buffers. |
| 271 | * @bpp: The bpp of the buffers. |
| 272 | * @modifier: The modifier of the buffers. |
| 273 | * |
| 274 | * Returns a valid pixmap if the import succeeded, else NULL. |
| 275 | * */ |
| 276 | extern _X_EXPORT PixmapPtr glamor_pixmap_from_fds(ScreenPtr screen, |
| 277 | CARD8 num_fds, |
| 278 | const int *fds, |
| 279 | CARD16 width, |
| 280 | CARD16 height, |
| 281 | const CARD32 *strides, |
| 282 | const CARD32 *offsets, |
| 283 | CARD8 depth, |
| 284 | CARD8 bpp, |
| 285 | uint64_t modifier); |
| 286 | |
| 287 | /* @glamor_pixmap_from_fd: Creates a pixmap to wrap a dma-buf fd. |
| 288 | * |
| 289 | * @screen: Current screen pointer. |
| 290 | * @fd: The dma-buf fd to import. |
| 291 | * @width: The width of the buffer. |
| 292 | * @height: The height of the buffer. |
| 293 | * @stride: The stride of the buffer. |
| 294 | * @depth: The depth of the buffer. |
| 295 | * @bpp: The bpp of the buffer. |
| 296 | * |
| 297 | * Returns a valid pixmap if the import succeeded, else NULL. |
| 298 | * */ |
| 299 | extern _X_EXPORT PixmapPtr glamor_pixmap_from_fd(ScreenPtr screen, |
| 300 | int fd, |
| 301 | CARD16 width, |
| 302 | CARD16 height, |
| 303 | CARD16 stride, |
| 304 | CARD8 depth, |
| 305 | CARD8 bpp); |
| 306 | |
| 307 | /* @glamor_back_pixmap_from_fd: Backs an existing pixmap with a dma-buf fd. |
| 308 | * |
| 309 | * @pixmap: Pixmap to change backing for |
| 310 | * @fd: The dma-buf fd to import. |
| 311 | * @width: The width of the buffer. |
| 312 | * @height: The height of the buffer. |
| 313 | * @stride: The stride of the buffer. |
| 314 | * @depth: The depth of the buffer. |
| 315 | * @bpp: The number of bpp of the buffer. |
| 316 | * |
| 317 | * Returns TRUE if successful, FALSE on failure. |
| 318 | * */ |
| 319 | extern _X_EXPORT Bool glamor_back_pixmap_from_fd(PixmapPtr pixmap, |
| 320 | int fd, |
| 321 | CARD16 width, |
| 322 | CARD16 height, |
| 323 | CARD16 stride, |
| 324 | CARD8 depth, |
| 325 | CARD8 bpp); |
| 326 | |
| 327 | extern _X_EXPORT Bool glamor_get_formats(ScreenPtr screen, |
| 328 | CARD32 *num_formats, |
| 329 | CARD32 **formats); |
| 330 | |
| 331 | extern _X_EXPORT Bool glamor_get_modifiers(ScreenPtr screen, |
| 332 | uint32_t format, |
| 333 | uint32_t *num_modifiers, |
| 334 | uint64_t **modifiers); |
| 335 | |
| 336 | extern _X_EXPORT Bool glamor_get_drawable_modifiers(DrawablePtr draw, |
| 337 | uint32_t format, |
| 338 | uint32_t *num_modifiers, |
| 339 | uint64_t **modifiers); |
| 340 | |
| 341 | extern _X_EXPORT void glamor_set_drawable_modifiers_func(ScreenPtr screen, |
| 342 | GetDrawableModifiersFuncPtr func); |
| 343 | |
| 344 | #ifdef GLAMOR_FOR_XORG |
| 345 | |
| 346 | #define GLAMOR_EGL_MODULE_NAME "glamoregl" |
| 347 | |
| 348 | /* @glamor_egl_init: Initialize EGL environment. |
| 349 | * |
| 350 | * @scrn: Current screen info pointer. |
| 351 | * @fd: Current drm fd. |
| 352 | * |
| 353 | * This function creates and initializes EGL contexts. |
| 354 | * Should be called from DDX's preInit function. |
| 355 | * Return TRUE if success, otherwise return FALSE. |
| 356 | * */ |
| 357 | extern _X_EXPORT Bool glamor_egl_init(ScrnInfoPtr scrn, int fd); |
| 358 | |
| 359 | extern _X_EXPORT Bool glamor_egl_init_textured_pixmap(ScreenPtr screen); |
| 360 | |
| 361 | /* @glamor_egl_create_textured_screen: Create textured screen pixmap. |
| 362 | * |
| 363 | * @screen: screen pointer to be processed. |
| 364 | * @handle: screen pixmap's BO handle. |
| 365 | * @stride: screen pixmap's stride in bytes. |
| 366 | * |
| 367 | * This function is similar with the create_textured_pixmap. As the |
| 368 | * screen pixmap is a special, we handle it separately in this function. |
| 369 | */ |
| 370 | extern _X_EXPORT Bool glamor_egl_create_textured_screen(ScreenPtr screen, |
| 371 | int handle, int stride); |
| 372 | |
| 373 | /* Obsolete entrypoint, temporarily left here for API compatibility |
| 374 | * for xf86-video-ati. |
| 375 | */ |
| 376 | #define glamor_egl_create_textured_screen_ext(a, b, c, d) \ |
| 377 | glamor_egl_create_textured_screen(a, b, c) |
| 378 | |
| 379 | /* |
| 380 | * @glamor_egl_create_textured_pixmap: Try to create a textured pixmap from |
| 381 | * a BO handle. |
| 382 | * |
| 383 | * @pixmap: The pixmap need to be processed. |
| 384 | * @handle: The BO's handle attached to this pixmap at DDX layer. |
| 385 | * @stride: Stride in bytes for this pixmap. |
| 386 | * |
| 387 | * This function try to create a texture from the handle and attach |
| 388 | * the texture to the pixmap , thus glamor can render to this pixmap |
| 389 | * as well. Return true if successful, otherwise return FALSE. |
| 390 | */ |
| 391 | extern _X_EXPORT Bool glamor_egl_create_textured_pixmap(PixmapPtr pixmap, |
| 392 | int handle, int stride); |
| 393 | |
| 394 | /* |
| 395 | * @glamor_egl_create_textured_pixmap_from_bo: Try to create a textured pixmap |
| 396 | * from a gbm_bo. |
| 397 | * |
| 398 | * @pixmap: The pixmap need to be processed. |
| 399 | * @bo: a pointer on a gbm_bo structure attached to this pixmap at DDX layer. |
| 400 | * |
| 401 | * This function is similar to glamor_egl_create_textured_pixmap. |
| 402 | */ |
| 403 | extern _X_EXPORT Bool |
| 404 | glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap, |
| 405 | struct gbm_bo *bo, |
| 406 | Bool used_modifiers); |
| 407 | |
| 408 | extern _X_EXPORT const char *glamor_egl_get_driver_name(ScreenPtr screen); |
| 409 | |
| 410 | #endif |
| 411 | |
| 412 | extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen, |
| 413 | struct glamor_context *glamor_ctx); |
| 414 | |
| 415 | extern _X_EXPORT int glamor_create_gc(GCPtr gc); |
| 416 | |
| 417 | extern _X_EXPORT void glamor_validate_gc(GCPtr gc, unsigned long changes, |
| 418 | DrawablePtr drawable); |
| 419 | |
| 420 | extern _X_EXPORT void glamor_destroy_gc(GCPtr gc); |
| 421 | |
| 422 | #define HAS_GLAMOR_DESTROY_GC 1 |
| 423 | |
| 424 | extern Bool _X_EXPORT glamor_change_window_attributes(WindowPtr pWin, unsigned long mask); |
| 425 | extern void _X_EXPORT glamor_copy_window(WindowPtr window, DDXPointRec old_origin, RegionPtr src_region); |
| 426 | |
| 427 | extern _X_EXPORT void glamor_finish(ScreenPtr screen); |
| 428 | #define HAS_GLAMOR_TEXT 1 |
| 429 | |
| 430 | #ifdef GLAMOR_FOR_XORG |
| 431 | extern _X_EXPORT XF86VideoAdaptorPtr glamor_xv_init(ScreenPtr pScreen, |
| 432 | int num_texture_ports); |
| 433 | #endif |
| 434 | |
| 435 | #endif /* GLAMOR_H */ |