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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
From 15419adf260b9314f487bcb855585821fa6a0d73 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <olvaffe@gmail.com>
Date: Thu, 14 Jan 2010 12:19:32 +0800
Subject: [PATCH 2/6] st/vega: Implement st_api interface.
---
src/gallium/state_trackers/vega/Makefile | 1 +
src/gallium/state_trackers/vega/api_context.c | 3 +
src/gallium/state_trackers/vega/api_masks.c | 5 +-
src/gallium/state_trackers/vega/vg_api.c | 373 +++++++++++++++++++++++++
src/gallium/state_trackers/vega/vg_api.h | 18 ++
src/gallium/state_trackers/vega/vg_context.h | 6 +
6 files changed, 403 insertions(+), 3 deletions(-)
create mode 100644 src/gallium/state_trackers/vega/vg_api.c
create mode 100644 src/gallium/state_trackers/vega/vg_api.h
diff --git a/src/gallium/state_trackers/vega/Makefile b/src/gallium/state_trackers/vega/Makefile
index 037d8dc..1f0d0e5 100644
--- a/src/gallium/state_trackers/vega/Makefile
+++ b/src/gallium/state_trackers/vega/Makefile
@@ -24,6 +24,7 @@ VG_SOURCES = \
api_text.c \
api_transform.c \
vgu.c \
+ vg_api.c \
vg_context.c \
vg_state.c \
vg_tracker.c \
diff --git a/src/gallium/state_trackers/vega/api_context.c b/src/gallium/state_trackers/vega/api_context.c
index 47db102..de3f44a 100644
--- a/src/gallium/state_trackers/vega/api_context.c
+++ b/src/gallium/state_trackers/vega/api_context.c
@@ -26,6 +26,7 @@
#include "VG/openvg.h"
+#include "vg_api.h"
#include "vg_context.h"
#include "pipe/p_context.h"
@@ -55,6 +56,8 @@ void vgFlush(void)
pipe = ctx->pipe;
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+
+ st_flush_frontbuffer();
}
void vgFinish(void)
diff --git a/src/gallium/state_trackers/vega/api_masks.c b/src/gallium/state_trackers/vega/api_masks.c
index 9c123a4..9a308f9 100644
--- a/src/gallium/state_trackers/vega/api_masks.c
+++ b/src/gallium/state_trackers/vega/api_masks.c
@@ -29,6 +29,7 @@
#include "mask.h"
#include "renderer.h"
+#include "vg_api.h"
#include "vg_context.h"
#include "pipe/p_context.h"
#include "util/u_inlines.h"
@@ -115,9 +116,7 @@ clear_with_quad(struct vg_context *st, float x0, float y0,
x1, y1);
*/
- if (st->pipe->screen && st->pipe->screen->update_buffer)
- st->pipe->screen->update_buffer( st->pipe->screen,
- st->pipe->priv );
+ st_validate_buffer();
cso_save_blend(st->cso_context);
cso_save_rasterizer(st->cso_context);
diff --git a/src/gallium/state_trackers/vega/vg_api.c b/src/gallium/state_trackers/vega/vg_api.c
new file mode 100644
index 0000000..6a85369
--- /dev/null
+++ b/src/gallium/state_trackers/vega/vg_api.c
@@ -0,0 +1,373 @@
+#include "state_tracker/st_api.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+#include "util/u_memory.h"
+#include "util/u_inlines.h"
+
+#include "vg_api.h"
+#include "vg_context.h"
+#include "vg_tracker.h" /* for st_resize_framebuffer */
+#include "image.h"
+
+/**
+ * Return a reference to the pipe texture of the EGLImage.
+ */
+struct pipe_texture *
+st_manager_reference_egl_image(VGeglImageKHR eglimg)
+{
+ struct vg_context *ctx = vg_current_context();
+ struct st_manager *smapi = ctx->iface.st_api_private;
+ struct pipe_texture *pt = NULL, *res;
+
+ if (!smapi)
+ return NULL;
+
+ res = (struct pipe_texture *) smapi->lock_resource(smapi, &ctx->iface,
+ ST_MANAGER_RESOURCE_EGL_IMAGE, (void *) eglimg);
+ pipe_texture_reference(&pt, res);
+ smapi->unlock_resource(smapi, &ctx->iface,
+ ST_MANAGER_RESOURCE_EGL_IMAGE, (void *) eglimg);
+
+ return pt;
+}
+
+/**
+ * Flush the front buffer if the current context renders to the front buffer.
+ */
+void
+st_flush_frontbuffer(void)
+{
+ struct vg_context *ctx = vg_current_context();
+ struct st_framebuffer *stfb = ctx->draw_buffer;
+
+ if (stfb) {
+ switch (stfb->strb_att) {
+ case ST_ATTACHMENT_FRONT_LEFT:
+ case ST_ATTACHMENT_FRONT_RIGHT:
+ stfb->iface->flush_front(stfb->iface, stfb->strb_att);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+/**
+ * Re-validate the framebuffer.
+ */
+void
+st_validate_buffer(void)
+{
+ struct vg_context *ctx = vg_current_context();
+ struct st_framebuffer *stfb = ctx->draw_buffer;
+
+ if (stfb)
+ ctx->iface.notify_invalid_framebuffer(&ctx->iface, stfb->iface);
+}
+
+
+static void
+st_context_notify_invalid_framebuffer(struct st_context_iface *stctxi,
+ struct st_framebuffer_iface *stfbi)
+{
+ struct vg_context *ctx = (struct vg_context *) stctxi;
+ struct pipe_screen *screen = ctx->pipe->screen;
+ struct st_framebuffer *stfb = ctx->draw_buffer;
+ struct st_renderbuffer *rb;
+ struct pipe_texture *pt;
+
+ /* no binding surface */
+ if (!stfb)
+ return;
+
+ assert(stfb->iface == stfbi);
+ if (stfb->strb_att == ST_ATTACHMENT_INVALID)
+ return;
+
+ /* validate the fb */
+ if (!stfb->iface->validate(stfb->iface, &stfb->strb_att, 1, &pt) || !pt)
+ return;
+
+ rb = stfb->strb;
+ if (rb->texture == pt) {
+ pipe_texture_reference(&pt, NULL);
+ return;
+ }
+
+ /* unreference existing ones */
+ pipe_surface_reference(&rb->surface, NULL);
+ pipe_texture_reference(&rb->texture, NULL);
+
+ rb->texture = pt;
+ rb->surface = screen->get_tex_surface(screen, rb->texture, 0, 0, 0,
+ PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE);
+
+ rb->width = rb->surface->width;
+ rb->height = rb->surface->height;
+
+ st_resize_framebuffer(stfb, rb->width, rb->height);
+}
+
+static void
+st_context_flush(struct st_context_iface *stctxi, unsigned flags,
+ struct pipe_fence_handle **fence)
+{
+ struct vg_context *ctx = (struct vg_context *) stctxi;
+ ctx->pipe->flush(ctx->pipe, flags, fence);
+}
+
+static void *
+st_context_lock_resource(struct st_context_iface *stctxi,
+ enum st_context_resource_type type, void *res)
+{
+ struct vg_image *img;
+ struct pipe_texture *pt = NULL;
+
+ if (type != ST_CONTEXT_RESOURCE_OPENVG_PARENT_IMAGE ||
+ (VGImage) res == VG_INVALID_HANDLE)
+ return NULL;
+
+ /* mark the image locked? */
+ img = (struct vg_image *) res;
+ pipe_texture_reference(&pt, img->texture);
+
+ return (void *) pt;
+}
+
+static void
+st_context_unlock_resource(struct st_context_iface *stctxi,
+ enum st_context_resource_type type, void *res)
+{
+ struct vg_image *img;
+ struct pipe_texture *pt;
+
+ if (type != ST_CONTEXT_RESOURCE_OPENVG_PARENT_IMAGE ||
+ (VGImage) res == VG_INVALID_HANDLE)
+ return;
+
+ img = (struct vg_image *) res;
+ pt = img->texture;
+ pipe_texture_reference(&pt, NULL);
+}
+
+static void
+st_context_destroy(struct st_context_iface *stctxi)
+{
+ struct vg_context *ctx = (struct vg_context *) stctxi;
+ vg_destroy_context(ctx);
+}
+
+static struct st_context_iface *
+st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
+ const struct st_visual *visual,
+ struct st_context_iface *shared_stctxi)
+{
+ struct vg_context *shared_ctx = (struct vg_context *) shared_stctxi;
+ struct vg_context *ctx;
+ struct pipe_context *pipe;
+
+ pipe = smapi->create_pipe_context(smapi);
+ if (!pipe)
+ return NULL;
+ ctx = vg_create_context(pipe, NULL, shared_ctx);
+ if (!ctx) {
+ pipe->destroy(pipe);
+ return NULL;
+ }
+
+ ctx->iface.api = ST_API_OPENVG;
+ ctx->iface.destroy = st_context_destroy;
+ ctx->iface.lock_resource = st_context_lock_resource;
+ ctx->iface.unlock_resource = st_context_unlock_resource;
+
+ ctx->iface.notify_invalid_framebuffer =
+ st_context_notify_invalid_framebuffer;
+ ctx->iface.flush = st_context_flush;
+
+ ctx->iface.teximage = NULL;
+ ctx->iface.copy = NULL;
+
+ ctx->iface.st_api_private = (void *) smapi;
+
+ return &ctx->iface;
+}
+
+static struct st_renderbuffer *
+create_renderbuffer(enum pipe_format format)
+{
+ struct st_renderbuffer *strb;
+
+ strb = CALLOC_STRUCT(st_renderbuffer);
+ if (strb)
+ strb->format = format;
+
+ return strb;
+}
+
+static void
+destroy_renderbuffer(struct st_renderbuffer *strb)
+{
+ pipe_surface_reference(&strb->surface, NULL);
+ pipe_texture_reference(&strb->texture, NULL);
+ free(strb);
+}
+
+/**
+ * Return the attachment of the render buffer.
+ */
+static enum st_attachment_type
+choose_attachment(struct st_framebuffer_iface *stfbi)
+{
+ enum st_attachment_type statt;
+
+ statt = stfbi->visual->render_buffer;
+ if (!st_visual_have_buffers(stfbi->visual, 1 << statt)) {
+ switch (statt) {
+ case ST_ATTACHMENT_BACK_LEFT:
+ statt = ST_ATTACHMENT_FRONT_LEFT;
+ break;
+ case ST_ATTACHMENT_BACK_RIGHT:
+ statt = ST_ATTACHMENT_FRONT_RIGHT;
+ break;
+ default:
+ break;
+ }
+
+ if (!st_visual_have_buffers(stfbi->visual, 1 << statt))
+ statt = ST_ATTACHMENT_INVALID;
+ }
+
+ return statt;
+}
+
+static boolean
+st_context_bind_framebuffers(struct st_context_iface *stctxi,
+ struct st_framebuffer_iface *stdrawi,
+ struct st_framebuffer_iface *streadi)
+{
+ struct vg_context *ctx = (struct vg_context *) stctxi;
+ struct st_framebuffer *stfb;
+
+ if (stdrawi != streadi)
+ return FALSE;
+
+ if (ctx->draw_buffer) {
+ stfb = ctx->draw_buffer;
+
+ /* free the existing fb */
+ if (!stdrawi ||
+ stfb->strb->format != stdrawi->visual->color_format ||
+ stfb->dsrb->format != stdrawi->visual->depth_stencil_format) {
+ destroy_renderbuffer(stfb->strb);
+ destroy_renderbuffer(stfb->dsrb);
+ free(stfb);
+
+ ctx->draw_buffer = NULL;
+ }
+ }
+
+ if (!stdrawi)
+ return TRUE;
+
+ /* create a new fb */
+ if (!ctx->draw_buffer) {
+ stfb = CALLOC_STRUCT(st_framebuffer);
+ if (!stfb)
+ return FALSE;
+
+ stfb->strb = create_renderbuffer(stdrawi->visual->color_format);
+ if (!stfb->strb) {
+ free(stfb);
+ return FALSE;
+ }
+
+ stfb->dsrb = create_renderbuffer(stdrawi->visual->depth_stencil_format);
+ if (!stfb->dsrb) {
+ free(stfb->strb);
+ free(stfb);
+ return FALSE;
+ }
+
+ stfb->width = 0;
+ stfb->height = 0;
+
+ ctx->draw_buffer = stfb;
+ }
+
+ ctx->draw_buffer->iface = stdrawi;
+ ctx->draw_buffer->strb_att = choose_attachment(stdrawi);
+
+ return TRUE;
+}
+
+static boolean
+st_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi,
+ struct st_framebuffer_iface *stdrawi,
+ struct st_framebuffer_iface *streadi)
+{
+ struct vg_context *ctx = (struct vg_context *) stctxi;
+
+ if (stctxi)
+ st_context_bind_framebuffers(stctxi, stdrawi, streadi);
+ vg_set_current_context(ctx);
+
+ return TRUE;
+}
+
+static struct st_context_iface *
+st_api_get_current(struct st_api *stapi)
+{
+ struct vg_context *ctx = vg_current_context();
+
+ return (ctx) ? &ctx->iface : NULL;
+}
+
+static st_proc_t
+st_api_get_proc_address(struct st_api *stapi, const char *procname)
+{
+ /* TODO */
+ return (st_proc_t) NULL;
+}
+
+static boolean
+st_api_is_visual_supported(struct st_api *stapi,
+ const struct st_visual *visual)
+{
+ /* the impl requires a depth/stencil buffer */
+ if (visual->depth_stencil_format == PIPE_FORMAT_NONE)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void
+st_api_destroy(struct st_api *stapi)
+{
+ free(stapi);
+}
+
+static struct st_api *
+st_module_create_api(void)
+{
+ struct st_api *stapi;
+
+ stapi = CALLOC_STRUCT(st_api);
+ if (stapi) {
+ stapi->destroy = st_api_destroy;
+ stapi->is_visual_supported = st_api_is_visual_supported;
+
+ stapi->create_context = st_api_create_context;
+ stapi->make_current = st_api_make_current;
+ stapi->get_current = st_api_get_current;
+
+ stapi->get_proc_address = st_api_get_proc_address;
+ }
+
+ return stapi;
+}
+
+const struct st_module st_module_OpenVG = {
+ .api = ST_API_OPENVG,
+ .create_api = st_module_create_api,
+};
diff --git a/src/gallium/state_trackers/vega/vg_api.h b/src/gallium/state_trackers/vega/vg_api.h
new file mode 100644
index 0000000..06c65f0
--- /dev/null
+++ b/src/gallium/state_trackers/vega/vg_api.h
@@ -0,0 +1,18 @@
+#ifndef VG_API_H
+#define VG_API_H
+
+#include "VG/openvg.h"
+#include "VG/vgext.h"
+
+#include "pipe/p_state.h"
+
+struct pipe_texture *
+st_manager_reference_egl_image(VGeglImageKHR eglimg);
+
+void
+st_flush_frontbuffer(void);
+
+void
+st_validate_buffer(void);
+
+#endif /* VG_API_H */
diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h
index bc88c8d..91300ff 100644
--- a/src/gallium/state_trackers/vega/vg_context.h
+++ b/src/gallium/state_trackers/vega/vg_context.h
@@ -33,6 +33,7 @@
#include "pipe/p_state.h"
#include "util/u_pointer.h"
#include "util/u_math.h"
+#include "state_tracker/st_api.h"
#include "cso_cache/cso_hash.h"
#include "cso_cache/cso_context.h"
@@ -58,6 +59,9 @@ struct st_framebuffer {
struct pipe_texture *blend_texture;
+ struct st_framebuffer_iface *iface;
+ enum st_attachment_type strb_att;
+
void *privateData;
};
@@ -84,6 +88,8 @@ enum dirty_state {
struct vg_context
{
+ struct st_context_iface iface;
+
struct pipe_context *pipe;
struct {
--
1.6.4.3
|