etnaviv: Only use renderonly_get_handle for GEM handles.
[mesa.git] / src / gallium / auxiliary / renderonly / renderonly.h
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 "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 struct pipe_resource *prime;
39 };
40
41 struct renderonly {
42 /**
43 * Create a renderonly_scanout object for scanout resource.
44 *
45 * This function creates a renderonly_scanout object based on the provided
46 * resource. The library is designed that the driver specific pipe_resource
47 * struct holds a pointer to a renderonly_scanout struct.
48 *
49 * struct driver_resource {
50 * struct pipe_resource base;
51 * struct renderonly_scanout *scanout;
52 * ...
53 * };
54 *
55 * The renderonly_scanout object exits for two reasons:
56 * - Do any special treatment for a scanout resource like importing the GPU
57 * resource into the scanout hw.
58 * - Make it easier for a gallium driver to detect if anything special needs
59 * to be done in flush_resource(..) like a resolve to linear.
60 */
61 struct renderonly_scanout *(*create_for_resource)(struct pipe_resource *rsc,
62 struct renderonly *ro);
63 int kms_fd;
64 int gpu_fd;
65 };
66
67 struct renderonly *
68 renderonly_dup(const struct renderonly *ro);
69
70 static inline struct renderonly_scanout *
71 renderonly_scanout_for_resource(struct pipe_resource *rsc, struct renderonly *ro)
72 {
73 return ro->create_for_resource(rsc, ro);
74 }
75
76 struct renderonly_scanout *
77 renderonly_scanout_for_prime(struct pipe_resource *rsc, struct renderonly *ro);
78
79 void
80 renderonly_scanout_destroy(struct renderonly_scanout *scanout,
81 struct renderonly *ro);
82
83 static inline boolean
84 renderonly_get_handle(struct renderonly_scanout *scanout,
85 struct winsys_handle *handle)
86 {
87 if (!scanout)
88 return FALSE;
89
90 assert(handle->type == DRM_API_HANDLE_TYPE_KMS);
91 handle->handle = scanout->handle;
92 handle->stride = scanout->stride;
93
94 return TRUE;
95 }
96
97 /**
98 * Create a dumb buffer object for a resource at scanout hw.
99 */
100 struct renderonly_scanout *
101 renderonly_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
102 struct renderonly *ro);
103
104 /**
105 * Import GPU resource into scanout hw.
106 */
107 struct renderonly_scanout *
108 renderonly_create_gpu_import_for_resource(struct pipe_resource *rsc,
109 struct renderonly *ro);
110
111 #endif /* RENDERONLY_H_ */