st_api: Remove st_context::is_visual_supported.
[mesa.git] / src / gallium / state_trackers / vega / vg_context.c
index 7769112a31e1776ba91905c9a0c957a5185e0809..b45e0086b4add62c6e8e1ae34a272f4c1e36e546 100644 (file)
@@ -33,6 +33,7 @@
 #include "asm_util.h"
 #include "st_inlines.h"
 #include "vg_manager.h"
+#include "api.h"
 
 #include "pipe/p_context.h"
 #include "util/u_inlines.h"
@@ -43,6 +44,7 @@
 #include "util/u_simple_shaders.h"
 #include "util/u_memory.h"
 #include "util/u_blit.h"
+#include "util/u_sampler.h"
 
 struct vg_context *_vg_context = 0;
 
@@ -63,9 +65,36 @@ static void init_clear(struct vg_context *st)
    st->clear.fs =
       util_make_fragment_passthrough_shader(pipe);
 }
+
+/**
+ * A depth/stencil rb will be needed regardless of what the visual says.
+ */
+static boolean
+choose_depth_stencil_format(struct vg_context *ctx)
+{
+   struct pipe_screen *screen = ctx->pipe->screen;
+   enum pipe_format formats[] = {
+      PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+      PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+      PIPE_FORMAT_NONE
+   };
+   enum pipe_format *fmt;
+
+   for (fmt = formats; *fmt != PIPE_FORMAT_NONE; fmt++) {
+      if (screen->is_format_supported(screen, *fmt,
+               PIPE_TEXTURE_2D, 0, PIPE_BIND_DEPTH_STENCIL, 0))
+         break;
+   }
+
+   ctx->ds_format = *fmt;
+
+   return (ctx->ds_format != PIPE_FORMAT_NONE);
+}
+
 void vg_set_current_context(struct vg_context *ctx)
 {
    _vg_context = ctx;
+   api_make_dispatch_current((ctx) ? ctx->dispatch : NULL);
 }
 
 struct vg_context * vg_create_context(struct pipe_context *pipe,
@@ -78,6 +107,12 @@ struct vg_context * vg_create_context(struct pipe_context *pipe,
    ctx = CALLOC_STRUCT(vg_context);
 
    ctx->pipe = pipe;
+   if (!choose_depth_stencil_format(ctx)) {
+      FREE(ctx);
+      return NULL;
+   }
+
+   ctx->dispatch = api_create_dispatch();
 
    vg_init_state(&ctx->state.vg);
    ctx->state.dirty = ALL_DIRTY;
@@ -131,8 +166,8 @@ struct vg_context * vg_create_context(struct pipe_context *pipe,
 
 void vg_destroy_context(struct vg_context *ctx)
 {
-   struct pipe_buffer **cbuf = &ctx->mask.cbuf;
-   struct pipe_buffer **vsbuf = &ctx->vs_const_buffer;
+   struct pipe_resource **cbuf = &ctx->mask.cbuf;
+   struct pipe_resource **vsbuf = &ctx->vs_const_buffer;
 
    util_destroy_blit(ctx->blit);
    renderer_destroy(ctx->renderer);
@@ -141,10 +176,10 @@ void vg_destroy_context(struct vg_context *ctx)
    paint_destroy(ctx->default_paint);
 
    if (*cbuf)
-      pipe_buffer_reference(cbuf, NULL);
+      pipe_resource_reference(cbuf, NULL);
 
    if (*vsbuf)
-      pipe_buffer_reference(vsbuf, NULL);
+      pipe_resource_reference(vsbuf, NULL);
 
    if (ctx->clear.fs) {
       cso_delete_fragment_shader(ctx->cso_context, ctx->clear.fs);
@@ -184,6 +219,8 @@ void vg_destroy_context(struct vg_context *ctx)
    cso_hash_delete(ctx->owned_objects[VG_OBJECT_FONT]);
    cso_hash_delete(ctx->owned_objects[VG_OBJECT_PATH]);
 
+   api_destroy_dispatch(ctx->dispatch);
+
    free(ctx);
 }
 
@@ -380,14 +417,14 @@ void vg_validate_state(struct vg_context *ctx)
          2.f/fb->width, 2.f/fb->height, 1, 1,
          -1, -1, 0, 0
       };
-      struct pipe_buffer **cbuf = &ctx->vs_const_buffer;
+      struct pipe_resource **cbuf = &ctx->vs_const_buffer;
 
       vg_set_viewport(ctx, VEGA_Y0_BOTTOM);
 
-      pipe_buffer_reference(cbuf, NULL);
-      *cbuf = pipe_buffer_create(ctx->pipe->screen, 16,
-                                        PIPE_BUFFER_USAGE_CONSTANT,
-                                        param_bytes);
+      pipe_resource_reference(cbuf, NULL);
+      *cbuf = pipe_buffer_create(ctx->pipe->screen, 
+                                PIPE_BIND_CONSTANT_BUFFER,
+                                param_bytes);
 
       if (*cbuf) {
          st_no_flush_pipe_buffer_write(ctx, *cbuf,
@@ -436,19 +473,24 @@ void vg_prepare_blend_surface(struct vg_context *ctx)
 {
    struct pipe_surface *dest_surface = NULL;
    struct pipe_context *pipe = ctx->pipe;
+   struct pipe_sampler_view *view;
+   struct pipe_sampler_view view_templ;
    struct st_framebuffer *stfb = ctx->draw_buffer;
    struct st_renderbuffer *strb = stfb->strb;
 
    /* first finish all pending rendering */
    vgFinish();
 
+   u_sampler_view_default_template(&view_templ, strb->texture, strb->texture->format);
+   view = pipe->create_sampler_view(pipe, strb->texture, &view_templ);
+
    dest_surface = pipe->screen->get_tex_surface(pipe->screen,
-                                                stfb->blend_texture,
+                                                stfb->blend_texture_view->texture,
                                                 0, 0, 0,
-                                                PIPE_BUFFER_USAGE_GPU_WRITE);
+                                                PIPE_BIND_RENDER_TARGET);
    /* flip it, because we want to use it as a sampler */
    util_blit_pixels_tex(ctx->blit,
-                        strb->texture,
+                        view,
                         0, strb->height,
                         strb->width, 0,
                         dest_surface,
@@ -461,6 +503,8 @@ void vg_prepare_blend_surface(struct vg_context *ctx)
 
    /* make sure it's complete */
    vgFinish();
+
+   pipe_sampler_view_reference(&view, NULL);
 }
 
 
@@ -477,13 +521,13 @@ void vg_prepare_blend_surface_from_mask(struct vg_context *ctx)
    vgFinish();
 
    dest_surface = pipe->screen->get_tex_surface(pipe->screen,
-                                                stfb->blend_texture,
+                                                stfb->blend_texture_view->texture,
                                                 0, 0, 0,
-                                                PIPE_BUFFER_USAGE_GPU_WRITE);
+                                                PIPE_BIND_RENDER_TARGET);
 
    /* flip it, because we want to use it as a sampler */
    util_blit_pixels_tex(ctx->blit,
-                        stfb->alpha_mask,
+                        stfb->alpha_mask_view,
                         0, strb->height,
                         strb->width, 0,
                         dest_surface,