ilo: replace a boolean by bool
[mesa.git] / src / gallium / state_trackers / vega / vg_context.c
index 0844012cc3b45908722169b37809a5017ad88860..c63618816835143e79ea9bc9d958edea200954ff 100644 (file)
 #include "renderer.h"
 #include "shaders_cache.h"
 #include "shader.h"
-#include "asm_util.h"
 #include "vg_manager.h"
 #include "api.h"
 #include "mask.h"
+#include "handle.h"
 
 #include "pipe/p_context.h"
 #include "util/u_inlines.h"
 
 #include "cso_cache/cso_context.h"
 
-#include "util/u_simple_shaders.h"
 #include "util/u_memory.h"
 #include "util/u_blit.h"
 #include "util/u_sampler.h"
@@ -62,15 +61,15 @@ 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_Z24_UNORM_S8_UINT,
+      PIPE_FORMAT_S8_UINT_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))
+               PIPE_TEXTURE_2D, 0, PIPE_BIND_DEPTH_STENCIL))
          break;
    }
 
@@ -184,42 +183,49 @@ void vg_init_object(struct vg_object *obj, struct vg_context *ctx, enum vg_objec
 {
    obj->type = type;
    obj->ctx = ctx;
+   obj->handle = create_handle(obj);
+}
+
+/** free object resources, but not the object itself */
+void vg_free_object(struct vg_object *obj)
+{
+   obj->type = 0;
+   obj->ctx = NULL;
+   destroy_handle(obj->handle);
 }
 
 VGboolean vg_context_is_object_valid(struct vg_context *ctx,
                                 enum vg_object_type type,
-                                void *ptr)
+                                VGHandle handle)
 {
     if (ctx) {
        struct cso_hash *hash = ctx->owned_objects[type];
        if (!hash)
           return VG_FALSE;
-       return cso_hash_contains(hash, (unsigned)(long)ptr);
+       return cso_hash_contains(hash, (unsigned) handle);
     }
     return VG_FALSE;
 }
 
 void vg_context_add_object(struct vg_context *ctx,
-                           enum vg_object_type type,
-                           void *ptr)
+                           struct vg_object *obj)
 {
     if (ctx) {
-       struct cso_hash *hash = ctx->owned_objects[type];
+       struct cso_hash *hash = ctx->owned_objects[obj->type];
        if (!hash)
           return;
-       cso_hash_insert(hash, (unsigned)(long)ptr, ptr);
+       cso_hash_insert(hash, (unsigned) obj->handle, obj);
     }
 }
 
 void vg_context_remove_object(struct vg_context *ctx,
-                              enum vg_object_type type,
-                              void *ptr)
+                              struct vg_object *obj)
 {
    if (ctx) {
-      struct cso_hash *hash = ctx->owned_objects[type];
+      struct cso_hash *hash = ctx->owned_objects[obj->type];
       if (!hash)
          return;
-      cso_hash_take(hash, (unsigned)(long)ptr);
+      cso_hash_take(hash, (unsigned) obj->handle);
    }
 }
 
@@ -371,9 +377,7 @@ vg_context_update_depth_stencil_rb(struct vg_context * ctx,
    if (!dsrb->texture)
       return TRUE;
 
-   memset(&surf_tmpl, 0, sizeof(surf_tmpl));
-   u_surface_default_template(&surf_tmpl, dsrb->texture,
-                              PIPE_BIND_DEPTH_STENCIL);
+   u_surface_default_template(&surf_tmpl, dsrb->texture);
    dsrb->surface = pipe->create_surface(pipe,
                                         dsrb->texture,
                                         &surf_tmpl);
@@ -400,8 +404,9 @@ void vg_validate_state(struct vg_context *ctx)
    if (vg_context_update_depth_stencil_rb(ctx, stfb->width, stfb->height))
       ctx->state.dirty |= DEPTH_STENCIL_DIRTY;
 
-   /* blend state depends on fb format */
-   if (ctx->state.dirty & FRAMEBUFFER_DIRTY)
+   /* blend state depends on fb format and paint color */
+   if ((ctx->state.dirty & FRAMEBUFFER_DIRTY) ||
+       (ctx->state.dirty & PAINT_DIRTY))
       ctx->state.dirty |= BLEND_DIRTY;
 
    renderer_validate(ctx->renderer, ctx->state.dirty,
@@ -414,10 +419,10 @@ void vg_validate_state(struct vg_context *ctx)
    shader_set_color_transform(ctx->shader, ctx->state.vg.color_transform);
 }
 
-VGboolean vg_object_is_valid(void *ptr, enum vg_object_type type)
+VGboolean vg_object_is_valid(VGHandle object, enum vg_object_type type)
 {
-   struct vg_object *obj = ptr;
-   if (ptr && is_aligned(obj) && obj->type == type)
+   struct vg_object *obj = handle_to_object(object);
+   if (obj && is_aligned(obj) && obj->type == type)
       return VG_TRUE;
    else
       return VG_FALSE;
@@ -443,9 +448,7 @@ static void vg_prepare_blend_texture(struct vg_context *ctx,
 
    vg_context_update_blend_texture_view(ctx, stfb->width, stfb->height);
 
-   memset(&surf_tmpl, 0, sizeof(surf_tmpl));
-   u_surface_default_template(&surf_tmpl, stfb->blend_texture_view->texture,
-                              PIPE_BIND_RENDER_TARGET);
+   u_surface_default_template(&surf_tmpl, stfb->blend_texture_view->texture);
    surf = ctx->pipe->create_surface(ctx->pipe,
                                     stfb->blend_texture_view->texture,
                                     &surf_tmpl);