Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2011 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,
  16.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18.  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19.  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20.  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22.  * DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors:
  25.  *    Benjamin Franzke <benjaminfranzke@googlemail.com>
  26.  */
  27.  
  28. #ifndef _GBM_DRI_INTERNAL_H_
  29. #define _GBM_DRI_INTERNAL_H_
  30.  
  31. #include <sys/mman.h>
  32. #include "gbmint.h"
  33.  
  34. #include "common_drm.h"
  35.  
  36. #include <GL/gl.h> /* dri_interface needs GL types */
  37. #include "GL/internal/dri_interface.h"
  38.  
  39. struct gbm_dri_surface;
  40. struct gbm_dri_bo;
  41.  
  42. struct gbm_dri_device {
  43.    struct gbm_drm_device base;
  44.  
  45.    void *driver;
  46.  
  47.    __DRIscreen *screen;
  48.  
  49.    const __DRIcoreExtension   *core;
  50.    const __DRIdri2Extension   *dri2;
  51.    const __DRIimageExtension  *image;
  52.    const __DRIswrastExtension *swrast;
  53.    const __DRI2flushExtension *flush;
  54.    const __DRIdri2LoaderExtension *loader;
  55.  
  56.    const __DRIconfig   **driver_configs;
  57.    const __DRIextension **extensions;
  58.    const __DRIextension **driver_extensions;
  59.  
  60.    __DRIimage *(*lookup_image)(__DRIscreen *screen, void *image, void *data);
  61.    void *lookup_user_data;
  62.  
  63.    __DRIbuffer *(*get_buffers)(__DRIdrawable * driDrawable,
  64.                                int *width, int *height,
  65.                                unsigned int *attachments, int count,
  66.                                int *out_count, void *data);
  67.    void (*flush_front_buffer)(__DRIdrawable * driDrawable, void *data);
  68.    __DRIbuffer *(*get_buffers_with_format)(__DRIdrawable * driDrawable,
  69.                              int *width, int *height,
  70.                              unsigned int *attachments, int count,
  71.                              int *out_count, void *data);
  72.    int (*image_get_buffers)(__DRIdrawable *driDrawable,
  73.                             unsigned int format,
  74.                             uint32_t *stamp,
  75.                             void *loaderPrivate,
  76.                             uint32_t buffer_mask,
  77.                             struct __DRIimageList *buffers);
  78.    void (*swrast_put_image2)(__DRIdrawable *driDrawable,
  79.                              int            op,
  80.                              int            x,
  81.                              int            y,
  82.                              int            width,
  83.                              int            height,
  84.                              int            stride,
  85.                              char          *data,
  86.                              void          *loaderPrivate);
  87.    void (*swrast_get_image)(__DRIdrawable *driDrawable,
  88.                             int            x,
  89.                             int            y,
  90.                             int            width,
  91.                             int            height,
  92.                             char          *data,
  93.                             void          *loaderPrivate);
  94.  
  95.    struct wl_drm *wl_drm;
  96. };
  97.  
  98. struct gbm_dri_bo {
  99.    struct gbm_drm_bo base;
  100.  
  101.    __DRIimage *image;
  102.  
  103.    /* Used for cursors and the swrast front BO */
  104.    uint32_t handle, size;
  105.    void *map;
  106. };
  107.  
  108. struct gbm_dri_surface {
  109.    struct gbm_surface base;
  110.  
  111.    void *dri_private;
  112. };
  113.  
  114. static inline struct gbm_dri_device *
  115. gbm_dri_device(struct gbm_device *gbm)
  116. {
  117.    return (struct gbm_dri_device *) gbm;
  118. }
  119.  
  120. static inline struct gbm_dri_bo *
  121. gbm_dri_bo(struct gbm_bo *bo)
  122. {
  123.    return (struct gbm_dri_bo *) bo;
  124. }
  125.  
  126. static inline struct gbm_dri_surface *
  127. gbm_dri_surface(struct gbm_surface *surface)
  128. {
  129.    return (struct gbm_dri_surface *) surface;
  130. }
  131.  
  132. static inline void *
  133. gbm_dri_bo_map(struct gbm_dri_bo *bo)
  134. {
  135.    struct drm_mode_map_dumb map_arg;
  136.    int ret;
  137.  
  138.    if (bo->image != NULL)
  139.       return NULL;
  140.  
  141.    if (bo->map != NULL)
  142.       return bo->map;
  143.  
  144.    memset(&map_arg, 0, sizeof(map_arg));
  145.    map_arg.handle = bo->handle;
  146.  
  147.    ret = drmIoctl(bo->base.base.gbm->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
  148.    if (ret)
  149.       return NULL;
  150.  
  151.    bo->map = mmap(0, bo->size, PROT_WRITE,
  152.                   MAP_SHARED, bo->base.base.gbm->fd, map_arg.offset);
  153.    if (bo->map == MAP_FAILED) {
  154.       bo->map = NULL;
  155.       return NULL;
  156.    }
  157.  
  158.    return bo->map;
  159. }
  160.  
  161. static inline void
  162. gbm_dri_bo_unmap(struct gbm_dri_bo *bo)
  163. {
  164.    munmap(bo->map, bo->size);
  165.    bo->map = NULL;
  166. }
  167.  
  168. #endif
  169.