/*
* Mesa 3-D graphics library
- * Version: 7.9
*
+ * Copyright 2009 VMware, Inc. All Rights Reserved.
* Copyright (C) 2010 LunarG Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
#include "pipe/p_screen.h"
#include "util/u_memory.h"
#include "util/u_inlines.h"
-#include "util/u_format.h"
+#include "util/u_box.h"
+#include "util/u_surface.h"
+#include "vg_api.h"
#include "vg_manager.h"
#include "vg_context.h"
-#include "vg_tracker.h" /* for st_resize_framebuffer */
-#include "image.h"
+#include "api.h"
+#include "handle.h"
+
+static boolean
+vg_context_update_color_rb(struct vg_context *ctx, struct pipe_resource *pt)
+{
+ struct st_renderbuffer *strb = ctx->draw_buffer->strb;
+ struct pipe_context *pipe = ctx->pipe;
+ struct pipe_surface surf_tmpl;
+
+ if (strb->texture == pt) {
+ pipe_resource_reference(&pt, NULL);
+ return FALSE;
+ }
+
+ /* unreference existing ones */
+ pipe_surface_reference(&strb->surface, NULL);
+ pipe_resource_reference(&strb->texture, NULL);
+ strb->width = strb->height = 0;
+
+ strb->texture = pt;
+
+ u_surface_default_template(&surf_tmpl, strb->texture);
+ strb->surface = pipe->create_surface(pipe, strb->texture, &surf_tmpl);
+
+ if (!strb->surface) {
+ pipe_resource_reference(&strb->texture, NULL);
+ return TRUE;
+ }
+
+ strb->width = pt->width0;
+ strb->height = pt->height0;
+
+ return TRUE;
+}
/**
* Flush the front buffer if the current context renders to the front buffer.
if (!stfb)
return;
- /* st_public.h is used */
- if (!stfb->iface) {
- struct pipe_screen *screen = ctx->pipe->screen;
- if (screen->flush_frontbuffer) {
- screen->flush_frontbuffer(screen,
- stfb->strb->surface, ctx->pipe->priv);
- }
- return;
- }
-
switch (stfb->strb_att) {
case ST_ATTACHMENT_FRONT_LEFT:
case ST_ATTACHMENT_FRONT_RIGHT:
- stfb->iface->flush_front(stfb->iface, stfb->strb_att);
+ stfb->iface->flush_front(&ctx->iface, stfb->iface, stfb->strb_att);
break;
default:
break;
void
vg_manager_validate_framebuffer(struct vg_context *ctx)
{
- struct pipe_screen *screen = ctx->pipe->screen;
struct st_framebuffer *stfb = ctx->draw_buffer;
- struct st_renderbuffer *rb;
struct pipe_resource *pt;
+ int32_t new_stamp;
/* no binding surface */
if (!stfb)
return;
- /* st_public.h is used */
- if (!stfb->iface) {
- struct pipe_screen *screen = ctx->pipe->screen;
- if (screen->update_buffer)
- screen->update_buffer(screen, ctx->pipe->priv);
- return;
- }
-
- if (!p_atomic_read(&ctx->draw_buffer_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_resource_reference(&pt, NULL);
- return;
- }
-
- /* unreference existing ones */
- pipe_surface_reference(&rb->surface, NULL);
- pipe_resource_reference(&rb->texture, NULL);
+ new_stamp = p_atomic_read(&stfb->iface->stamp);
+ if (stfb->iface_stamp != new_stamp) {
+ do {
+ /* validate the fb */
+ if (!stfb->iface->validate(stfb->iface, &stfb->strb_att,
+ 1, &pt) || !pt)
+ return;
- rb->texture = pt;
- rb->surface = screen->get_tex_surface(screen, rb->texture, 0, 0, 0,
- PIPE_BIND_RENDER_TARGET |
- PIPE_BIND_BLIT_SOURCE |
- PIPE_BIND_BLIT_DESTINATION);
+ stfb->iface_stamp = new_stamp;
+ new_stamp = p_atomic_read(&stfb->iface->stamp);
- rb->width = rb->surface->width;
- rb->height = rb->surface->height;
+ } while (stfb->iface_stamp != new_stamp);
- st_resize_framebuffer(stfb, rb->width, rb->height);
-
- p_atomic_set(&ctx->draw_buffer_invalid, FALSE);
-}
+ if (vg_context_update_color_rb(ctx, pt) ||
+ stfb->width != pt->width0 ||
+ stfb->height != pt->height0)
+ ++stfb->stamp;
+ stfb->width = pt->width0;
+ stfb->height = pt->height0;
+ }
-static void
-vg_context_notify_invalid_framebuffer(struct st_context_iface *stctxi,
- struct st_framebuffer_iface *stfbi)
-{
- struct vg_context *ctx = (struct vg_context *) stctxi;
- p_atomic_set(&ctx->draw_buffer_invalid, TRUE);
+ if (ctx->draw_stamp != stfb->stamp) {
+ ctx->state.dirty |= FRAMEBUFFER_DIRTY;
+ ctx->draw_stamp = stfb->stamp;
+ }
}
static void
struct pipe_fence_handle **fence)
{
struct vg_context *ctx = (struct vg_context *) stctxi;
- ctx->pipe->flush(ctx->pipe, flags, fence);
- if (flags & PIPE_FLUSH_RENDER_CACHE)
+ unsigned pipe_flags = 0;
+
+ if (flags & ST_FLUSH_END_OF_FRAME) {
+ pipe_flags |= PIPE_FLUSH_END_OF_FRAME;
+ }
+
+ ctx->pipe->flush(ctx->pipe, fence, pipe_flags);
+ if (flags & ST_FLUSH_FRONT)
vg_manager_flush_frontbuffer(ctx);
}
vg_context_destroy(struct st_context_iface *stctxi)
{
struct vg_context *ctx = (struct vg_context *) stctxi;
+ struct pipe_context *pipe = ctx->pipe;
+
vg_destroy_context(ctx);
+ pipe->destroy(pipe);
}
static struct st_context_iface *
vg_api_create_context(struct st_api *stapi, struct st_manager *smapi,
- const struct st_visual *visual,
+ const struct st_context_attribs *attribs,
+ enum st_context_error *error,
struct st_context_iface *shared_stctxi)
{
struct vg_context *shared_ctx = (struct vg_context *) shared_stctxi;
struct vg_context *ctx;
struct pipe_context *pipe;
+ if (!(stapi->profile_mask & (1 << attribs->profile))) {
+ *error = ST_CONTEXT_ERROR_BAD_API;
+ return NULL;
+ }
+
+ /* only 1.0 is supported */
+ if (attribs->major > 1 || (attribs->major == 1 && attribs->minor > 0)) {
+ *error = ST_CONTEXT_ERROR_BAD_VERSION;
+ return NULL;
+ }
+
+ /* for VGHandle / pointer lookups */
+ init_handles();
+
pipe = smapi->screen->context_create(smapi->screen, NULL);
- if (!pipe)
+ if (!pipe) {
+ *error = ST_CONTEXT_ERROR_NO_MEMORY;
return NULL;
+ }
ctx = vg_create_context(pipe, NULL, shared_ctx);
if (!ctx) {
pipe->destroy(pipe);
+ *error = ST_CONTEXT_ERROR_NO_MEMORY;
return NULL;
}
ctx->iface.destroy = vg_context_destroy;
- ctx->iface.notify_invalid_framebuffer =
- vg_context_notify_invalid_framebuffer;
ctx->iface.flush = vg_context_flush;
ctx->iface.teximage = NULL;
{
pipe_surface_reference(&strb->surface, NULL);
pipe_resource_reference(&strb->texture, NULL);
- free(strb);
+ FREE(strb);
}
/**
if (stdrawi != streadi)
return FALSE;
- p_atomic_set(&ctx->draw_buffer_invalid, TRUE);
-
strb_att = (stdrawi) ? choose_attachment(stdrawi) : ST_ATTACHMENT_INVALID;
if (ctx->draw_buffer) {
/* free the existing fb */
if (!stdrawi ||
stfb->strb_att != strb_att ||
- stfb->strb->format != stdrawi->visual->color_format ||
- stfb->dsrb->format != stdrawi->visual->depth_stencil_format) {
+ stfb->strb->format != stdrawi->visual->color_format) {
destroy_renderbuffer(stfb->strb);
destroy_renderbuffer(stfb->dsrb);
- free(stfb);
+ FREE(stfb);
ctx->draw_buffer = NULL;
}
stfb->strb = create_renderbuffer(stdrawi->visual->color_format);
if (!stfb->strb) {
- free(stfb);
+ FREE(stfb);
return FALSE;
}
- stfb->dsrb = create_renderbuffer(stdrawi->visual->depth_stencil_format);
+ stfb->dsrb = create_renderbuffer(ctx->ds_format);
if (!stfb->dsrb) {
- free(stfb->strb);
- free(stfb);
+ FREE(stfb->strb);
+ FREE(stfb);
return FALSE;
}
stfb->width = 0;
stfb->height = 0;
stfb->strb_att = strb_att;
+ stfb->stamp = 1;
+ stfb->iface_stamp = p_atomic_read(&stdrawi->stamp) - 1;
ctx->draw_buffer = stfb;
}
ctx->draw_buffer->iface = stdrawi;
+ ctx->draw_stamp = ctx->draw_buffer->stamp - 1;
return TRUE;
}
return (ctx) ? &ctx->iface : NULL;
}
-static boolean
-vg_api_is_visual_supported(struct st_api *stapi,
- const struct st_visual *visual)
-{
- /* the impl requires a depth/stencil buffer */
- return util_format_is_depth_and_stencil(visual->depth_stencil_format);
-}
-
static st_proc_t
vg_api_get_proc_address(struct st_api *stapi, const char *procname)
{
- /* TODO */
- return (st_proc_t) NULL;
+ return api_get_proc_address(procname);
}
static void
vg_api_destroy(struct st_api *stapi)
{
- free(stapi);
}
-static struct st_api *
-vg_module_create_api(void)
-{
- struct st_api *stapi;
-
- stapi = CALLOC_STRUCT(st_api);
- if (stapi) {
- stapi->destroy = vg_api_destroy;
- stapi->get_proc_address = vg_api_get_proc_address;
- stapi->is_visual_supported = vg_api_is_visual_supported;
-
- stapi->create_context = vg_api_create_context;
- stapi->make_current = vg_api_make_current;
- stapi->get_current = vg_api_get_current;
- }
+static const struct st_api vg_api = {
+ "Vega " PACKAGE_VERSION,
+ ST_API_OPENVG,
+ ST_PROFILE_DEFAULT_MASK,
+ 0,
+ vg_api_destroy,
+ vg_api_get_proc_address,
+ vg_api_create_context,
+ vg_api_make_current,
+ vg_api_get_current,
+};
- return stapi;
+const struct st_api *
+vg_api_get(void)
+{
+ return &vg_api;
}
-
-PUBLIC const struct st_module st_module_OpenVG = {
- .api = ST_API_OPENVG,
- .create_api = vg_module_create_api,
-};