Merge branch 'gallium-no-rhw-position'
[mesa.git] / src / gallium / drivers / trace / tr_drm.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "state_tracker/drm_api.h"
29
30 #include "util/u_memory.h"
31 #include "tr_drm.h"
32 #include "tr_screen.h"
33 #include "tr_context.h"
34 #include "tr_buffer.h"
35 #include "tr_texture.h"
36
37 struct trace_drm_api
38 {
39 struct drm_api base;
40
41 struct drm_api *api;
42 };
43
44 static INLINE struct trace_drm_api *
45 trace_drm_api(struct drm_api *_api)
46 {
47 return (struct trace_drm_api *)_api;
48 }
49
50 static struct pipe_screen *
51 trace_drm_create_screen(struct drm_api *_api, int fd,
52 struct drm_create_screen_arg *arg)
53 {
54 struct trace_drm_api *tr_api = trace_drm_api(_api);
55 struct drm_api *api = tr_api->api;
56 struct pipe_screen *screen;
57
58 /* TODO trace call */
59
60 if (arg && arg->mode != DRM_CREATE_NORMAL)
61 return NULL;
62
63 screen = api->create_screen(api, fd, arg);
64
65 return trace_screen_create(screen);
66 }
67
68
69 static struct pipe_texture *
70 trace_drm_texture_from_shared_handle(struct drm_api *_api,
71 struct pipe_screen *_screen,
72 struct pipe_texture *templ,
73 const char *name,
74 unsigned stride,
75 unsigned handle)
76 {
77 struct trace_screen *tr_screen = trace_screen(_screen);
78 struct trace_drm_api *tr_api = trace_drm_api(_api);
79 struct pipe_screen *screen = tr_screen->screen;
80 struct drm_api *api = tr_api->api;
81 struct pipe_texture *result;
82
83 /* TODO trace call */
84
85 result = api->texture_from_shared_handle(api, screen, templ, name, stride, handle);
86
87 result = trace_texture_create(trace_screen(_screen), result);
88
89 return result;
90 }
91
92 static boolean
93 trace_drm_shared_handle_from_texture(struct drm_api *_api,
94 struct pipe_screen *_screen,
95 struct pipe_texture *_texture,
96 unsigned *stride,
97 unsigned *handle)
98 {
99 struct trace_screen *tr_screen = trace_screen(_screen);
100 struct trace_texture *tr_texture = trace_texture(_texture);
101 struct trace_drm_api *tr_api = trace_drm_api(_api);
102 struct pipe_screen *screen = tr_screen->screen;
103 struct pipe_texture *texture = tr_texture->texture;
104 struct drm_api *api = tr_api->api;
105
106 /* TODO trace call */
107
108 return api->shared_handle_from_texture(api, screen, texture, stride, handle);
109 }
110
111 static boolean
112 trace_drm_local_handle_from_texture(struct drm_api *_api,
113 struct pipe_screen *_screen,
114 struct pipe_texture *_texture,
115 unsigned *stride,
116 unsigned *handle)
117 {
118 struct trace_screen *tr_screen = trace_screen(_screen);
119 struct trace_texture *tr_texture = trace_texture(_texture);
120 struct trace_drm_api *tr_api = trace_drm_api(_api);
121 struct pipe_screen *screen = tr_screen->screen;
122 struct pipe_texture *texture = tr_texture->texture;
123 struct drm_api *api = tr_api->api;
124
125 /* TODO trace call */
126
127 return api->local_handle_from_texture(api, screen, texture, stride, handle);
128 }
129
130 static void
131 trace_drm_destroy(struct drm_api *_api)
132 {
133 struct trace_drm_api *tr_api = trace_drm_api(_api);
134 struct drm_api *api = tr_api->api;
135
136 if (api->destroy)
137 api->destroy(api);
138
139 free(tr_api);
140 }
141
142 struct drm_api *
143 trace_drm_create(struct drm_api *api)
144 {
145 struct trace_drm_api *tr_api;
146
147 if (!api)
148 goto error;
149
150 if (!trace_enabled())
151 goto error;
152
153 tr_api = CALLOC_STRUCT(trace_drm_api);
154
155 if (!tr_api)
156 goto error;
157
158 tr_api->base.name = api->name;
159 tr_api->base.driver_name = api->driver_name;
160 tr_api->base.create_screen = trace_drm_create_screen;
161 tr_api->base.texture_from_shared_handle = trace_drm_texture_from_shared_handle;
162 tr_api->base.shared_handle_from_texture = trace_drm_shared_handle_from_texture;
163 tr_api->base.local_handle_from_texture = trace_drm_local_handle_from_texture;
164 tr_api->base.destroy = trace_drm_destroy;
165 tr_api->api = api;
166
167 return &tr_api->base;
168
169 error:
170 return api;
171 }