Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
[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 "trace/tr_drm.h"
32 #include "trace/tr_screen.h"
33 #include "trace/tr_context.h"
34 #include "trace/tr_buffer.h"
35 #include "trace/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 static struct pipe_context *
69 trace_drm_create_context(struct drm_api *_api,
70 struct pipe_screen *_screen)
71 {
72 struct trace_screen *tr_screen = trace_screen(_screen);
73 struct trace_drm_api *tr_api = trace_drm_api(_api);
74 struct pipe_screen *screen = tr_screen->screen;
75 struct drm_api *api = tr_api->api;
76 struct pipe_context *pipe;
77
78 /* TODO trace call */
79
80 pipe = api->create_context(api, screen);
81
82 pipe = trace_context_create(_screen, pipe);
83
84 return pipe;
85 }
86
87 static struct pipe_texture *
88 trace_drm_texture_from_shared_handle(struct drm_api *_api,
89 struct pipe_screen *_screen,
90 struct pipe_texture *templ,
91 const char *name,
92 unsigned stride,
93 unsigned handle)
94 {
95 struct trace_screen *tr_screen = trace_screen(_screen);
96 struct trace_drm_api *tr_api = trace_drm_api(_api);
97 struct pipe_screen *screen = tr_screen->screen;
98 struct drm_api *api = tr_api->api;
99 struct pipe_texture *result;
100
101 /* TODO trace call */
102
103 result = api->texture_from_shared_handle(api, screen, templ, name, stride, handle);
104
105 result = trace_texture_create(trace_screen(_screen), result);
106
107 return result;
108 }
109
110 static boolean
111 trace_drm_shared_handle_from_texture(struct drm_api *_api,
112 struct pipe_screen *_screen,
113 struct pipe_texture *_texture,
114 unsigned *stride,
115 unsigned *handle)
116 {
117 struct trace_screen *tr_screen = trace_screen(_screen);
118 struct trace_texture *tr_texture = trace_texture(_texture);
119 struct trace_drm_api *tr_api = trace_drm_api(_api);
120 struct pipe_screen *screen = tr_screen->screen;
121 struct pipe_texture *texture = tr_texture->texture;
122 struct drm_api *api = tr_api->api;
123
124 /* TODO trace call */
125
126 return api->shared_handle_from_texture(api, screen, texture, stride, handle);
127 }
128
129 static boolean
130 trace_drm_local_handle_from_texture(struct drm_api *_api,
131 struct pipe_screen *_screen,
132 struct pipe_texture *_texture,
133 unsigned *stride,
134 unsigned *handle)
135 {
136 struct trace_screen *tr_screen = trace_screen(_screen);
137 struct trace_texture *tr_texture = trace_texture(_texture);
138 struct trace_drm_api *tr_api = trace_drm_api(_api);
139 struct pipe_screen *screen = tr_screen->screen;
140 struct pipe_texture *texture = tr_texture->texture;
141 struct drm_api *api = tr_api->api;
142
143 /* TODO trace call */
144
145 return api->local_handle_from_texture(api, screen, texture, stride, handle);
146 }
147
148 static void
149 trace_drm_destroy(struct drm_api *_api)
150 {
151 struct trace_drm_api *tr_api = trace_drm_api(_api);
152 struct drm_api *api = tr_api->api;
153
154 if (api->destroy)
155 api->destroy(api);
156
157 free(tr_api);
158 }
159
160 struct drm_api *
161 trace_drm_create(struct drm_api *api)
162 {
163 struct trace_drm_api *tr_api;
164
165 if (!api)
166 goto error;
167
168 if (!trace_enabled())
169 goto error;
170
171 tr_api = CALLOC_STRUCT(trace_drm_api);
172
173 if (!tr_api)
174 goto error;
175
176 tr_api->base.create_screen = trace_drm_create_screen;
177 tr_api->base.create_context = trace_drm_create_context;
178 tr_api->base.texture_from_shared_handle = trace_drm_texture_from_shared_handle;
179 tr_api->base.shared_handle_from_texture = trace_drm_shared_handle_from_texture;
180 tr_api->base.local_handle_from_texture = trace_drm_local_handle_from_texture;
181 tr_api->base.destroy = trace_drm_destroy;
182 tr_api->api = api;
183
184 return &tr_api->base;
185
186 error:
187 return api;
188 }