summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/g3dvl/vl_surface.c
blob: ffc81221728271b2f041ea105f92b8ba27ea109e (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#define VL_INTERNAL
#include "vl_surface.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <pipe/p_screen.h>
#include <pipe/p_state.h>
#include <pipe/p_inlines.h>
#include <vl_winsys.h>
#include "vl_screen.h"
#include "vl_context.h"
#include "vl_render.h"
#include "vl_csc.h"
#include "vl_util.h"

int vlCreateSurface
(
	struct vlScreen *screen,
	unsigned int width,
	unsigned int height,
	enum vlFormat format,
	struct vlSurface **surface
)
{
	struct vlSurface	*sfc;
	struct pipe_texture	template;

	assert(screen);
	assert(surface);

	sfc = calloc(1, sizeof(struct vlSurface));

	if (!sfc)
		return 1;

	sfc->screen = screen;
	sfc->width = width;
	sfc->height = height;
	sfc->format = format;

	memset(&template, 0, sizeof(struct pipe_texture));
	template.target = PIPE_TEXTURE_2D;
	template.format = PIPE_FORMAT_A8R8G8B8_UNORM;
	template.last_level = 0;
	template.width[0] = vlRoundUpPOT(sfc->width);
	template.height[0] = vlRoundUpPOT(sfc->height);
	template.depth[0] = 1;
	template.compressed = 0;
	pf_get_block(template.format, &template.block);
	template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;

	sfc->texture = vlGetPipeScreen(screen)->texture_create(vlGetPipeScreen(screen), &template);

	*surface = sfc;

	return 0;
}

int vlDestroySurface
(
	struct vlSurface *surface
)
{
	assert(surface);

	pipe_texture_release(&surface->texture);
	free(surface);

	return 0;
}

int vlRenderMacroBlocksMpeg2
(
	struct vlMpeg2MacroBlockBatch *batch,
	struct vlSurface *surface
)
{
	assert(batch);
	assert(surface);

	surface->context->render->vlBegin(surface->context->render);

	surface->context->render->vlRenderMacroBlocksMpeg2
	(
		surface->context->render,
		batch,
		surface
	);

	surface->context->render->vlEnd(surface->context->render);

	return 0;
}

int vlPutPicture
(
	struct vlSurface *surface,
	vlNativeDrawable drawable,
	int srcx,
	int srcy,
	int srcw,
	int srch,
	int destx,
	int desty,
	int destw,
	int desth,
	enum vlPictureType picture_type
)
{
	struct vlCSC		*csc;
	struct pipe_context	*pipe;

	assert(surface);
	assert(surface->context);

	csc = surface->context->csc;
	pipe = surface->context->pipe;

	csc->vlResizeFrameBuffer(csc, destw, desth);

	csc->vlBegin(csc);

	csc->vlPutPicture
	(
		csc,
		surface,
		srcx,
		srcy,
		srcw,
		srch,
		destx,
		desty,
		destw,
		desth,
		picture_type
	);

	csc->vlEnd(csc);

	pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
	bind_pipe_drawable(pipe, drawable);
	/* TODO: Need to take destx, desty into consideration */
	pipe->winsys->flush_frontbuffer
	(
		pipe->winsys,
		csc->vlGetFrameBuffer(csc),
		pipe->priv
	);

	return 0;
}

struct vlScreen* vlSurfaceGetScreen
(
	struct vlSurface *surface
)
{
	assert(surface);

	return surface->screen;
}

struct vlContext* vlBindToContext
(
	struct vlSurface *surface,
	struct vlContext *context
)
{
	struct vlContext *old;

	assert(surface);

	old = surface->context;
	surface->context = context;

	return old;
}