1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "state_tracker/drm_api.h"
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"
44 static INLINE
struct trace_drm_api
*
45 trace_drm_api(struct drm_api
*_api
)
47 return (struct trace_drm_api
*)_api
;
50 static struct pipe_screen
*
51 trace_drm_create_screen(struct drm_api
*_api
, int fd
,
52 struct drm_create_screen_arg
*arg
)
54 struct trace_drm_api
*tr_api
= trace_drm_api(_api
);
55 struct drm_api
*api
= tr_api
->api
;
56 struct pipe_screen
*screen
;
60 if (arg
&& arg
->mode
!= DRM_CREATE_NORMAL
)
63 screen
= api
->create_screen(api
, fd
, arg
);
65 return trace_screen_create(screen
);
68 static struct pipe_context
*
69 trace_drm_create_context(struct drm_api
*_api
,
70 struct pipe_screen
*_screen
)
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
;
80 pipe
= api
->create_context(api
, screen
);
82 pipe
= trace_context_create(_screen
, pipe
);
88 trace_drm_buffer_from_texture(struct drm_api
*_api
,
89 struct pipe_texture
*_texture
,
90 struct pipe_buffer
**_buffer
,
93 struct trace_texture
*tr_texture
= trace_texture(_texture
);
94 struct trace_drm_api
*tr_api
= trace_drm_api(_api
);
95 struct pipe_texture
*texture
= tr_texture
->texture
;
96 struct drm_api
*api
= tr_api
->api
;
97 struct pipe_buffer
*buffer
= NULL
;
100 /* TODO trace call */
102 result
= api
->buffer_from_texture(api
, texture
, &buffer
, stride
);
104 if (result
&& _buffer
)
105 buffer
= trace_buffer_create(trace_screen(_texture
->screen
), buffer
);
110 pipe_buffer_reference(&buffer
, NULL
);
115 static struct pipe_buffer
*
116 trace_drm_buffer_from_handle(struct drm_api
*_api
,
117 struct pipe_screen
*_screen
,
121 struct trace_screen
*tr_screen
= trace_screen(_screen
);
122 struct trace_drm_api
*tr_api
= trace_drm_api(_api
);
123 struct pipe_screen
*screen
= tr_screen
->screen
;
124 struct drm_api
*api
= tr_api
->api
;
125 struct pipe_buffer
*result
;
127 /* TODO trace call */
129 result
= api
->buffer_from_handle(api
, screen
, name
, handle
);
131 result
= trace_buffer_create(trace_screen(_screen
), result
);
137 trace_drm_handle_from_buffer(struct drm_api
*_api
,
138 struct pipe_screen
*_screen
,
139 struct pipe_buffer
*_buffer
,
142 struct trace_screen
*tr_screen
= trace_screen(_screen
);
143 struct trace_buffer
*tr_buffer
= trace_buffer(_buffer
);
144 struct trace_drm_api
*tr_api
= trace_drm_api(_api
);
145 struct pipe_screen
*screen
= tr_screen
->screen
;
146 struct pipe_buffer
*buffer
= tr_buffer
->buffer
;
147 struct drm_api
*api
= tr_api
->api
;
149 /* TODO trace call */
151 return api
->handle_from_buffer(api
, screen
, buffer
, handle
);
155 trace_drm_global_handle_from_buffer(struct drm_api
*_api
,
156 struct pipe_screen
*_screen
,
157 struct pipe_buffer
*_buffer
,
160 struct trace_screen
*tr_screen
= trace_screen(_screen
);
161 struct trace_buffer
*tr_buffer
= trace_buffer(_buffer
);
162 struct trace_drm_api
*tr_api
= trace_drm_api(_api
);
163 struct pipe_screen
*screen
= tr_screen
->screen
;
164 struct pipe_buffer
*buffer
= tr_buffer
->buffer
;
165 struct drm_api
*api
= tr_api
->api
;
167 /* TODO trace call */
169 return api
->global_handle_from_buffer(api
, screen
, buffer
, handle
);
173 trace_drm_destroy(struct drm_api
*_api
)
175 struct trace_drm_api
*tr_api
= trace_drm_api(_api
);
176 struct drm_api
*api
= tr_api
->api
;
183 trace_drm_create(struct drm_api
*api
)
185 struct trace_drm_api
*tr_api
;
190 if (!trace_enabled())
193 tr_api
= CALLOC_STRUCT(trace_drm_api
);
198 tr_api
->base
.create_screen
= trace_drm_create_screen
;
199 tr_api
->base
.create_context
= trace_drm_create_context
;
200 tr_api
->base
.buffer_from_texture
= trace_drm_buffer_from_texture
;
201 tr_api
->base
.buffer_from_handle
= trace_drm_buffer_from_handle
;
202 tr_api
->base
.handle_from_buffer
= trace_drm_handle_from_buffer
;
203 tr_api
->base
.global_handle_from_buffer
= trace_drm_global_handle_from_buffer
;
204 tr_api
->base
.destroy
= trace_drm_destroy
;
207 return &tr_api
->base
;