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"
32 #include "tr_screen.h"
33 #include "tr_context.h"
34 #include "tr_buffer.h"
35 #include "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
);
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
,
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
;
85 result
= api
->texture_from_shared_handle(api
, screen
, templ
, name
, stride
, handle
);
87 result
= trace_texture_create(trace_screen(_screen
), result
);
93 trace_drm_shared_handle_from_texture(struct drm_api
*_api
,
94 struct pipe_screen
*_screen
,
95 struct pipe_texture
*_texture
,
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
;
106 /* TODO trace call */
108 return api
->shared_handle_from_texture(api
, screen
, texture
, stride
, handle
);
112 trace_drm_local_handle_from_texture(struct drm_api
*_api
,
113 struct pipe_screen
*_screen
,
114 struct pipe_texture
*_texture
,
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
;
125 /* TODO trace call */
127 return api
->local_handle_from_texture(api
, screen
, texture
, stride
, handle
);
131 trace_drm_destroy(struct drm_api
*_api
)
133 struct trace_drm_api
*tr_api
= trace_drm_api(_api
);
134 struct drm_api
*api
= tr_api
->api
;
143 trace_drm_create(struct drm_api
*api
)
145 struct trace_drm_api
*tr_api
;
150 if (!trace_enabled())
153 tr_api
= CALLOC_STRUCT(trace_drm_api
);
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
;
167 return &tr_api
->base
;