• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 Christian Gmeiner <christian.gmeiner@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@gmail.com>
25  */
26 
27 #ifndef RENDERONLY_H
28 #define RENDERONLY_H
29 
30 #include <stdint.h>
31 #include "frontend/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     * When the screen has renderonly enabled, drivers need to follow these
60     * rules:
61     * - Create the scanout resource in resource_create and
62     *   resource_create_with_modifiers if PIPE_BIND_SCANOUT is set. Drivers
63     *   can fail if the scanout resource couldn't be created.
64     * - Try to import the scanout resource in resource_from_handle with
65     *   renderonly_create_gpu_import_for_resource. Drivers MUST NOT fail if
66     *   the scanout resource couldn't be created.
67     * - In a resource_get_handle call for WINSYS_HANDLE_TYPE_KMS, use
68     *   renderonly_get_handle with the scanout resource, even if the scanout
69     *   resource is NULL. Drivers MUST NOT return their own resource here,
70     *   because the GEM handle will not be valid for the caller's DRM FD.
71     * - Implement resource_get_params for at least PIPE_RESOURCE_PARAM_STRIDE,
72     *   PIPE_RESOURCE_PARAM_OFFSET and PIPE_RESOURCE_PARAM_MODIFIER.
73     */
74    struct renderonly_scanout *(*create_for_resource)(struct pipe_resource *rsc,
75                                                      struct renderonly *ro,
76                                                      struct winsys_handle *out_handle);
77    void (*destroy)(struct renderonly *ro);
78    int kms_fd;
79    int gpu_fd;
80 };
81 
82 static inline struct renderonly_scanout *
renderonly_scanout_for_resource(struct pipe_resource * rsc,struct renderonly * ro,struct winsys_handle * out_handle)83 renderonly_scanout_for_resource(struct pipe_resource *rsc,
84                                 struct renderonly *ro,
85                                 struct winsys_handle *out_handle)
86 {
87    return ro->create_for_resource(rsc, ro, out_handle);
88 }
89 
90 void
91 renderonly_scanout_destroy(struct renderonly_scanout *scanout,
92 			   struct renderonly *ro);
93 
94 static inline boolean
renderonly_get_handle(struct renderonly_scanout * scanout,struct winsys_handle * handle)95 renderonly_get_handle(struct renderonly_scanout *scanout,
96       struct winsys_handle *handle)
97 {
98    if (!scanout)
99       return FALSE;
100 
101    assert(handle->type == WINSYS_HANDLE_TYPE_KMS);
102    handle->handle = scanout->handle;
103    handle->stride = scanout->stride;
104 
105    return TRUE;
106 }
107 
108 /**
109  * Create a dumb buffer object for a resource at scanout hw.
110  */
111 struct renderonly_scanout *
112 renderonly_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
113                                                struct renderonly *ro,
114                                                struct winsys_handle *out_handle);
115 
116 /**
117  * Import GPU resource into scanout hw.
118  */
119 struct renderonly_scanout *
120 renderonly_create_gpu_import_for_resource(struct pipe_resource *rsc,
121                                           struct renderonly *ro,
122                                           struct winsys_handle *out_handle);
123 
124 #endif /* RENDERONLY_H_ */
125