aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys/drm/intel/gem/intel_be_api.c
blob: 5853afa7566f4dcbeb325d75a54ab6a7b333ffdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

#include "intel_be_api.h"
#include "i915simple/i915_winsys.h"

#ifndef DEBUG
struct drm_api drm_api_hooks =
#else
static struct drm_api hooks =
#endif
{
	/* intel_be_context.c */
	.create_context = intel_be_create_context,
	/* intel_be_device.c */
	.create_screen = intel_be_create_screen,
	.buffer_from_texture = i915_get_texture_buffer,
	.buffer_from_handle = intel_be_buffer_from_handle,
	.handle_from_buffer = intel_be_handle_from_buffer,
	.global_handle_from_buffer = intel_be_global_handle_from_buffer,
};


/*
 * Trace integration
 */

#ifdef DEBUG
#include "trace/tr_screen.h"
#include "trace/tr_texture.h"
#include "trace/tr_buffer.h"
#include "trace/tr_context.h"

static struct pipe_screen *
trace_drm_create_screen(int fd, struct drm_create_screen_arg *arg)
{
	struct pipe_screen *screen;

	if (arg && arg->mode != DRM_CREATE_NORMAL)
		return NULL;

	screen = hooks.create_screen(fd, arg);

	return trace_screen_create(screen);
};

static struct pipe_context *
trace_drm_create_context(struct pipe_screen *_screen)
{
	struct pipe_screen *screen;
	struct pipe_context *pipe;

	if (trace_enabled())
		screen = trace_screen(_screen)->screen;
	else
		screen = _screen;

	pipe = hooks.create_context(screen);

	if (trace_enabled())
		pipe = trace_context_create(_screen, pipe);

	return pipe;
};

static boolean
trace_drm_buffer_from_texture(struct pipe_texture *_texture,
                              struct pipe_buffer **_buffer,
                              unsigned *stride)
{
	struct pipe_texture *texture;
	struct pipe_buffer *buffer = NULL;
	boolean result;

	if (trace_enabled())
		texture = trace_texture(_texture)->texture;
	else
		texture = _texture;

	result = hooks.buffer_from_texture(texture, &buffer, stride);

	if (result && _buffer)
		buffer = trace_buffer_create(trace_screen(texture->screen), buffer);

	if (_buffer)
		*_buffer = buffer;
	else
		pipe_buffer_reference(&buffer, NULL);

	return result;
}

static struct pipe_buffer *
trace_drm_buffer_from_handle(struct pipe_screen *_screen,
                             const char *name,
                             unsigned handle)
{
	struct pipe_screen *screen;
	struct pipe_buffer *result;

	if (trace_enabled())
		screen = trace_screen(_screen)->screen;
	else
		screen = _screen;

	result = hooks.buffer_from_handle(screen, name, handle);

	if (trace_enabled())
		result = trace_buffer_create(trace_screen(_screen), result);

	return result;
}

static boolean
trace_drm_handle_from_buffer(struct pipe_screen *_screen,
                             struct pipe_buffer *_buffer,
                             unsigned *handle)
{
	struct pipe_screen *screen;
	struct pipe_buffer *buffer;

	if (trace_enabled()) {
		screen = trace_screen(_screen)->screen;
		buffer = trace_buffer(_buffer)->buffer;
	} else {
		screen = _screen;
		buffer = _buffer;
	}

	return hooks.handle_from_buffer(screen, buffer, handle);
}

static boolean
trace_drm_global_handle_from_buffer(struct pipe_screen *_screen,
                                    struct pipe_buffer *_buffer,
                                    unsigned *handle)
{
	struct pipe_screen *screen;
	struct pipe_buffer *buffer;

	if (trace_enabled()) {
		screen = trace_screen(_screen)->screen;
		buffer = trace_buffer(_buffer)->buffer;
	} else {
		screen = _screen;
		buffer = _buffer;
	}

	return hooks.global_handle_from_buffer(screen, buffer, handle);
}

struct drm_api drm_api_hooks =
{
	.create_screen = trace_drm_create_screen,
	.create_context = trace_drm_create_context,

	.buffer_from_texture = trace_drm_buffer_from_texture,
	.buffer_from_handle = trace_drm_buffer_from_handle,
	.handle_from_buffer = trace_drm_handle_from_buffer,
	.global_handle_from_buffer = trace_drm_global_handle_from_buffer,
};
#endif