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
);
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
,
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
;
101 /* TODO trace call */
103 result
= api
->texture_from_shared_handle(api
, screen
, templ
, name
, stride
, handle
);
105 result
= trace_texture_create(trace_screen(_screen
), result
);
111 trace_drm_shared_handle_from_texture(struct drm_api
*_api
,
112 struct pipe_screen
*_screen
,
113 struct pipe_texture
*_texture
,
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
;
124 /* TODO trace call */
126 return api
->shared_handle_from_texture(api
, screen
, texture
, stride
, handle
);
130 trace_drm_local_handle_from_texture(struct drm_api
*_api
,
131 struct pipe_screen
*_screen
,
132 struct pipe_texture
*_texture
,
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
;
143 /* TODO trace call */
145 return api
->local_handle_from_texture(api
, screen
, texture
, stride
, handle
);
149 trace_drm_destroy(struct drm_api
*_api
)
151 struct trace_drm_api
*tr_api
= trace_drm_api(_api
);
152 struct drm_api
*api
= tr_api
->api
;
161 trace_drm_create(struct drm_api
*api
)
163 struct trace_drm_api
*tr_api
;
168 if (!trace_enabled())
171 tr_api
= CALLOC_STRUCT(trace_drm_api
);
176 tr_api
->base
.driver_name
= api
->driver_name
;
177 tr_api
->base
.create_screen
= trace_drm_create_screen
;
178 tr_api
->base
.create_context
= trace_drm_create_context
;
179 tr_api
->base
.texture_from_shared_handle
= trace_drm_texture_from_shared_handle
;
180 tr_api
->base
.shared_handle_from_texture
= trace_drm_shared_handle_from_texture
;
181 tr_api
->base
.local_handle_from_texture
= trace_drm_local_handle_from_texture
;
182 tr_api
->base
.destroy
= trace_drm_destroy
;
185 return &tr_api
->base
;