"Fossies" - the Fresh Open Source Software Archive

Member "xorg-server-1.20.8/glamor/glamor.h" (29 Mar 2020, 17305 Bytes) of package /linux/misc/xorg-server-1.20.8.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "glamor.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.20.7_vs_1.20.8.

    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 <eric@anholt.net>
   25  *    Zhigang Gong <zhigang.gong@linux.intel.com>
   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 void 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 extern _X_EXPORT PixmapPtr glamor_create_pixmap(ScreenPtr screen, int w, int h,
  124                                                 int depth, unsigned int usage);
  125 extern _X_EXPORT Bool glamor_destroy_pixmap(PixmapPtr pixmap);
  126 
  127 #define GLAMOR_CREATE_PIXMAP_CPU        0x100
  128 #define GLAMOR_CREATE_PIXMAP_FIXUP      0x101
  129 #define GLAMOR_CREATE_FBO_NO_FBO        0x103
  130 #define GLAMOR_CREATE_NO_LARGE          0x105
  131 #define GLAMOR_CREATE_PIXMAP_NO_TEXTURE 0x106
  132 
  133 /* @glamor_egl_exchange_buffers: Exchange the underlying buffers(KHR image,fbo).
  134  *
  135  * @front: front pixmap.
  136  * @back: back pixmap.
  137  *
  138  * Used by the DRI2 page flip. This function will exchange the KHR images and
  139  * fbos of the two pixmaps.
  140  * */
  141 extern _X_EXPORT void glamor_egl_exchange_buffers(PixmapPtr front,
  142                                                   PixmapPtr back);
  143 
  144 extern _X_EXPORT void glamor_pixmap_exchange_fbos(PixmapPtr front,
  145                                                   PixmapPtr back);
  146 
  147 /* The DDX is not supposed to call these four functions */
  148 extern _X_EXPORT void glamor_enable_dri3(ScreenPtr screen);
  149 extern _X_EXPORT int glamor_egl_fds_from_pixmap(ScreenPtr, PixmapPtr, int *,
  150                                                 uint32_t *, uint32_t *,
  151                                                 uint64_t *);
  152 extern _X_EXPORT int glamor_egl_fd_name_from_pixmap(ScreenPtr, PixmapPtr,
  153                                                     CARD16 *, CARD32 *);
  154 
  155 extern _X_EXPORT struct gbm_device *glamor_egl_get_gbm_device(ScreenPtr screen);
  156 extern _X_EXPORT int glamor_egl_fd_from_pixmap(ScreenPtr, PixmapPtr, CARD16 *, CARD32 *);
  157 
  158 /* @glamor_supports_pixmap_import_export: Returns whether
  159  * glamor_fds_from_pixmap(), glamor_name_from_pixmap(), and
  160  * glamor_pixmap_from_fds() are supported.
  161  *
  162  * @screen: Current screen pointer.
  163  *
  164  * To have DRI3 support enabled, glamor and glamor_egl need to be
  165  * initialized. glamor also has to be compiled with gbm support.
  166  *
  167  * The EGL layer needs to have the following extensions working:
  168  *
  169  * .EGL_KHR_surfaceless_context
  170  * */
  171 extern _X_EXPORT Bool glamor_supports_pixmap_import_export(ScreenPtr screen);
  172 
  173 /* @glamor_fds_from_pixmap: Get a dma-buf fd from a pixmap.
  174  *
  175  * @screen: Current screen pointer.
  176  * @pixmap: The pixmap from which we want the fd.
  177  * @fds, @strides, @offsets: Pointers to fill info of each plane.
  178  * @modifier: Pointer to fill the modifier of the buffer.
  179  *
  180  * the pixmap and the buffer associated by the fds will share the same
  181  * content. The caller is responsible to close the returned file descriptors.
  182  * Returns the number of planes, -1 on error.
  183  * */
  184 extern _X_EXPORT int glamor_fds_from_pixmap(ScreenPtr screen,
  185                                             PixmapPtr pixmap,
  186                                             int *fds,
  187                                             uint32_t *strides, uint32_t *offsets,
  188                                             uint64_t *modifier);
  189 
  190 /* @glamor_fd_from_pixmap: Get a dma-buf fd from a pixmap.
  191  *
  192  * @screen: Current screen pointer.
  193  * @pixmap: The pixmap from which we want the fd.
  194  * @stride, @size: Pointers to fill the stride and size of the
  195  *         buffer associated to the fd.
  196  *
  197  * the pixmap and the buffer associated by the fd will share the same
  198  * content.
  199  * Returns the fd on success, -1 on error.
  200  * */
  201 extern _X_EXPORT int glamor_fd_from_pixmap(ScreenPtr screen,
  202                                            PixmapPtr pixmap,
  203                                            CARD16 *stride, CARD32 *size);
  204 
  205 /* @glamor_shareable_fd_from_pixmap: Get a dma-buf fd suitable for sharing
  206  *                   with other GPUs from a pixmap.
  207  *
  208  * @screen: Current screen pointer.
  209  * @pixmap: The pixmap from which we want the fd.
  210  * @stride, @size: Pointers to fill the stride and size of the
  211  *         buffer associated to the fd.
  212  *
  213  * The returned fd will point to a buffer which is suitable for sharing
  214  * across GPUs (not using GPU specific tiling).
  215  * The pixmap and the buffer associated by the fd will share the same
  216  * content.
  217  * The pixmap's stride may be modified by this function.
  218  * Returns the fd on success, -1 on error.
  219  * */
  220 extern _X_EXPORT int glamor_shareable_fd_from_pixmap(ScreenPtr screen,
  221                                                      PixmapPtr pixmap,
  222                                                      CARD16 *stride,
  223                                                      CARD32 *size);
  224 
  225 /**
  226  * @glamor_name_from_pixmap: Gets a gem name from a pixmap.
  227  *
  228  * @pixmap: The pixmap from which we want the gem name.
  229  *
  230  * the pixmap and the buffer associated by the gem name will share the
  231  * same content. This function can be used by the DDX to support DRI2,
  232  * and needs the same set of buffer export GL extensions as DRI3
  233  * support.
  234  *
  235  * Returns the name on success, -1 on error.
  236  * */
  237 extern _X_EXPORT int glamor_name_from_pixmap(PixmapPtr pixmap,
  238                                              CARD16 *stride, CARD32 *size);
  239 
  240 /* @glamor_gbm_bo_from_pixmap: Get a GBM bo from a pixmap.
  241  *
  242  * @screen: Current screen pointer.
  243  * @pixmap: The pixmap from which we want the fd.
  244  * @stride, @size: Pointers to fill the stride and size of the
  245  *         buffer associated to the fd.
  246  *
  247  * the pixmap and the buffer represented by the gbm_bo will share the same
  248  * content.
  249  *
  250  * Returns the gbm_bo on success, NULL on error.
  251  * */
  252 extern _X_EXPORT struct gbm_bo *glamor_gbm_bo_from_pixmap(ScreenPtr screen,
  253                                                           PixmapPtr pixmap);
  254 
  255 /* @glamor_pixmap_from_fds: Creates a pixmap to wrap a dma-buf fds.
  256  *
  257  * @screen: Current screen pointer.
  258  * @num_fds: Number of fds to import
  259  * @fds: The dma-buf fds to import.
  260  * @width: The width of the buffers.
  261  * @height: The height of the buffers.
  262  * @stride: The stride of the buffers.
  263  * @depth: The depth of the buffers.
  264  * @bpp: The bpp of the buffers.
  265  * @modifier: The modifier of the buffers.
  266  *
  267  * Returns a valid pixmap if the import succeeded, else NULL.
  268  * */
  269 extern _X_EXPORT PixmapPtr glamor_pixmap_from_fds(ScreenPtr screen,
  270                                                   CARD8 num_fds,
  271                                                   const int *fds,
  272                                                   CARD16 width,
  273                                                   CARD16 height,
  274                                                   const CARD32 *strides,
  275                                                   const CARD32 *offsets,
  276                                                   CARD8 depth,
  277                                                   CARD8 bpp,
  278                                                   uint64_t modifier);
  279 
  280 /* @glamor_pixmap_from_fd: Creates a pixmap to wrap a dma-buf fd.
  281  *
  282  * @screen: Current screen pointer.
  283  * @fd: The dma-buf fd to import.
  284  * @width: The width of the buffer.
  285  * @height: The height of the buffer.
  286  * @stride: The stride of the buffer.
  287  * @depth: The depth of the buffer.
  288  * @bpp: The bpp of the buffer.
  289  *
  290  * Returns a valid pixmap if the import succeeded, else NULL.
  291  * */
  292 extern _X_EXPORT PixmapPtr glamor_pixmap_from_fd(ScreenPtr screen,
  293                                                  int fd,
  294                                                  CARD16 width,
  295                                                  CARD16 height,
  296                                                  CARD16 stride,
  297                                                  CARD8 depth,
  298                                                  CARD8 bpp);
  299 
  300 /* @glamor_back_pixmap_from_fd: Backs an existing pixmap with a dma-buf fd.
  301  *
  302  * @pixmap: Pixmap to change backing for
  303  * @fd: The dma-buf fd to import.
  304  * @width: The width of the buffer.
  305  * @height: The height of the buffer.
  306  * @stride: The stride of the buffer.
  307  * @depth: The depth of the buffer.
  308  * @bpp: The number of bpp of the buffer.
  309  *
  310  * Returns TRUE if successful, FALSE on failure.
  311  * */
  312 extern _X_EXPORT Bool glamor_back_pixmap_from_fd(PixmapPtr pixmap,
  313                                                  int fd,
  314                                                  CARD16 width,
  315                                                  CARD16 height,
  316                                                  CARD16 stride,
  317                                                  CARD8 depth,
  318                                                  CARD8 bpp);
  319 
  320 extern _X_EXPORT Bool glamor_get_formats(ScreenPtr screen,
  321                                          CARD32 *num_formats,
  322                                          CARD32 **formats);
  323 
  324 extern _X_EXPORT Bool glamor_get_modifiers(ScreenPtr screen,
  325                                            uint32_t format,
  326                                            uint32_t *num_modifiers,
  327                                            uint64_t **modifiers);
  328 
  329 extern _X_EXPORT Bool glamor_get_drawable_modifiers(DrawablePtr draw,
  330                                                     uint32_t format,
  331                                                     uint32_t *num_modifiers,
  332                                                     uint64_t **modifiers);
  333 
  334 extern _X_EXPORT void glamor_set_drawable_modifiers_func(ScreenPtr screen,
  335                                                          GetDrawableModifiersFuncPtr func);
  336 
  337 #ifdef GLAMOR_FOR_XORG
  338 
  339 #define GLAMOR_EGL_MODULE_NAME  "glamoregl"
  340 
  341 /* @glamor_egl_init: Initialize EGL environment.
  342  *
  343  * @scrn: Current screen info pointer.
  344  * @fd:   Current drm fd.
  345  *
  346  * This function creates and intialize EGL contexts.
  347  * Should be called from DDX's preInit function.
  348  * Return TRUE if success, otherwise return FALSE.
  349  * */
  350 extern _X_EXPORT Bool glamor_egl_init(ScrnInfoPtr scrn, int fd);
  351 
  352 extern _X_EXPORT Bool glamor_egl_init_textured_pixmap(ScreenPtr screen);
  353 
  354 /* @glamor_egl_create_textured_screen: Create textured screen pixmap.
  355  *
  356  * @screen: screen pointer to be processed.
  357  * @handle: screen pixmap's BO handle.
  358  * @stride: screen pixmap's stride in bytes.
  359  *
  360  * This function is similar with the create_textured_pixmap. As the
  361  * screen pixmap is a special, we handle it separately in this function.
  362  */
  363 extern _X_EXPORT Bool glamor_egl_create_textured_screen(ScreenPtr screen,
  364                                                         int handle, int stride);
  365 
  366 /* Obsolete entrypoint, temporarily left here for API compatibility
  367  * for xf86-video-ati.
  368  */
  369 #define glamor_egl_create_textured_screen_ext(a, b, c, d) \
  370     glamor_egl_create_textured_screen(a, b, c)
  371 
  372 /*
  373  * @glamor_egl_create_textured_pixmap: Try to create a textured pixmap from
  374  *                     a BO handle.
  375  *
  376  * @pixmap: The pixmap need to be processed.
  377  * @handle: The BO's handle attached to this pixmap at DDX layer.
  378  * @stride: Stride in bytes for this pixmap.
  379  *
  380  * This function try to create a texture from the handle and attach
  381  * the texture to the pixmap , thus glamor can render to this pixmap
  382  * as well. Return true if successful, otherwise return FALSE.
  383  */
  384 extern _X_EXPORT Bool glamor_egl_create_textured_pixmap(PixmapPtr pixmap,
  385                                                         int handle, int stride);
  386 
  387 /*
  388  * @glamor_egl_create_textured_pixmap_from_bo: Try to create a textured pixmap
  389  *                         from a gbm_bo.
  390  *
  391  * @pixmap: The pixmap need to be processed.
  392  * @bo: a pointer on a gbm_bo structure attached to this pixmap at DDX layer.
  393  *
  394  * This function is similar to glamor_egl_create_textured_pixmap.
  395  */
  396 extern _X_EXPORT Bool
  397  glamor_egl_create_textured_pixmap_from_gbm_bo(PixmapPtr pixmap,
  398                                                struct gbm_bo *bo,
  399                                                Bool used_modifiers);
  400 
  401 extern _X_EXPORT const char *glamor_egl_get_driver_name(ScreenPtr screen);
  402 
  403 #endif
  404 
  405 extern _X_EXPORT void glamor_egl_screen_init(ScreenPtr screen,
  406                                              struct glamor_context *glamor_ctx);
  407 
  408 extern _X_EXPORT int glamor_create_gc(GCPtr gc);
  409 
  410 extern _X_EXPORT void glamor_validate_gc(GCPtr gc, unsigned long changes,
  411                                          DrawablePtr drawable);
  412 
  413 extern _X_EXPORT void glamor_destroy_gc(GCPtr gc);
  414 
  415 #define HAS_GLAMOR_DESTROY_GC 1
  416 
  417 extern Bool _X_EXPORT glamor_change_window_attributes(WindowPtr pWin, unsigned long mask);
  418 extern void _X_EXPORT glamor_copy_window(WindowPtr window, DDXPointRec old_origin, RegionPtr src_region);
  419 
  420 extern _X_EXPORT void glamor_finish(ScreenPtr screen);
  421 #define HAS_GLAMOR_TEXT 1
  422 
  423 #ifdef GLAMOR_FOR_XORG
  424 extern _X_EXPORT XF86VideoAdaptorPtr glamor_xv_init(ScreenPtr pScreen,
  425                                                     int num_texture_ports);
  426 #endif
  427 
  428 #endif                          /* GLAMOR_H */