Home | History | Annotate | Download | only in renderonly
      1 /*
      2  * Copyright (C) 2016 Christian Gmeiner <christian.gmeiner (at) gmail.com>
      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 FROM,
     20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21  * SOFTWARE.
     22  *
     23  * Authors:
     24  *    Christian Gmeiner <christian.gmeiner (at) gmail.com>
     25  */
     26 
     27 #ifndef RENDERONLY_H
     28 #define RENDERONLY_H
     29 
     30 #include <stdint.h>
     31 #include "state_tracker/drm_driver.h"
     32 #include "pipe/p_state.h"
     33 
     34 struct renderonly_scanout {
     35    uint32_t handle;
     36    uint32_t stride;
     37 };
     38 
     39 struct renderonly {
     40    /**
     41     * Create a renderonly_scanout object for scanout resource.
     42     *
     43     * This function creates a renderonly_scanout object based on the provided
     44     * resource. The library is designed that the driver specific pipe_resource
     45     * struct holds a pointer to a renderonly_scanout struct.
     46     *
     47     * struct driver_resource {
     48     *    struct pipe_resource base;
     49     *    struct renderonly_scanout *scanout;
     50     *   ...
     51     * };
     52     *
     53     * The renderonly_scanout object exits for two reasons:
     54     * - Do any special treatment for a scanout resource like importing the GPU
     55     *   resource into the scanout hw.
     56     * - Make it easier for a gallium driver to detect if anything special needs
     57     *   to be done in flush_resource(..) like a resolve to linear.
     58     */
     59    struct renderonly_scanout *(*create_for_resource)(struct pipe_resource *rsc,
     60                                                      struct renderonly *ro,
     61                                                      struct winsys_handle *out_handle);
     62    int kms_fd;
     63    int gpu_fd;
     64 };
     65 
     66 struct renderonly *
     67 renderonly_dup(const struct renderonly *ro);
     68 
     69 static inline struct renderonly_scanout *
     70 renderonly_scanout_for_resource(struct pipe_resource *rsc,
     71                                 struct renderonly *ro,
     72                                 struct winsys_handle *out_handle)
     73 {
     74    return ro->create_for_resource(rsc, ro, out_handle);
     75 }
     76 
     77 void
     78 renderonly_scanout_destroy(struct renderonly_scanout *scanout,
     79 			   struct renderonly *ro);
     80 
     81 static inline boolean
     82 renderonly_get_handle(struct renderonly_scanout *scanout,
     83       struct winsys_handle *handle)
     84 {
     85    if (!scanout)
     86       return FALSE;
     87 
     88    assert(handle->type == DRM_API_HANDLE_TYPE_KMS);
     89    handle->handle = scanout->handle;
     90    handle->stride = scanout->stride;
     91 
     92    return TRUE;
     93 }
     94 
     95 /**
     96  * Create a dumb buffer object for a resource at scanout hw.
     97  */
     98 struct renderonly_scanout *
     99 renderonly_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
    100                                                struct renderonly *ro,
    101                                                struct winsys_handle *out_handle);
    102 
    103 /**
    104  * Import GPU resource into scanout hw.
    105  */
    106 struct renderonly_scanout *
    107 renderonly_create_gpu_import_for_resource(struct pipe_resource *rsc,
    108                                           struct renderonly *ro,
    109                                           struct winsys_handle *out_handle);
    110 
    111 #endif /* RENDERONLY_H_ */
    112