renderonly.h revision 7ec681f3
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
34struct renderonly_scanout {
35   uint32_t handle;
36   uint32_t stride;
37};
38
39struct 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   void (*destroy)(struct renderonly *ro);
63   int kms_fd;
64   int gpu_fd;
65};
66
67static inline struct renderonly_scanout *
68renderonly_scanout_for_resource(struct pipe_resource *rsc,
69                                struct renderonly *ro,
70                                struct winsys_handle *out_handle)
71{
72   return ro->create_for_resource(rsc, ro, out_handle);
73}
74
75void
76renderonly_scanout_destroy(struct renderonly_scanout *scanout,
77			   struct renderonly *ro);
78
79static inline boolean
80renderonly_get_handle(struct renderonly_scanout *scanout,
81      struct winsys_handle *handle)
82{
83   if (!scanout)
84      return FALSE;
85
86   assert(handle->type == WINSYS_HANDLE_TYPE_KMS);
87   handle->handle = scanout->handle;
88   handle->stride = scanout->stride;
89
90   return TRUE;
91}
92
93/**
94 * Create a dumb buffer object for a resource at scanout hw.
95 */
96struct renderonly_scanout *
97renderonly_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
98                                               struct renderonly *ro,
99                                               struct winsys_handle *out_handle);
100
101/**
102 * Import GPU resource into scanout hw.
103 */
104struct renderonly_scanout *
105renderonly_create_gpu_import_for_resource(struct pipe_resource *rsc,
106                                          struct renderonly *ro,
107                                          struct winsys_handle *out_handle);
108
109#endif /* RENDERONLY_H_ */
110