Squashed commit of the following:
[mesa.git] / src / gallium / state_trackers / vega / image.c
index 1112ad9839d5811304d9b4c4ad777e51e451f47f..9c323b1809cc4646f83bccde6cf71bd7522372d5 100644 (file)
 
 #include "pipe/p_context.h"
 #include "pipe/p_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 #include "util/u_blit.h"
 #include "util/u_format.h"
 #include "util/u_tile.h"
 #include "util/u_memory.h"
 #include "util/u_math.h"
+#include "util/u_sampler.h"
 
 static enum pipe_format vg_format_to_pipe(VGImageFormat format)
 {
    switch(format) {
    case VG_sRGB_565:
-      return PIPE_FORMAT_R5G6B5_UNORM;
+      return PIPE_FORMAT_B5G6R5_UNORM;
    case VG_sRGBA_5551:
-      return PIPE_FORMAT_A1R5G5B5_UNORM;
+      return PIPE_FORMAT_B5G5R5A1_UNORM;
    case VG_sRGBA_4444:
-      return PIPE_FORMAT_A4R4G4B4_UNORM;
+      return PIPE_FORMAT_B4G4R4A4_UNORM;
    case VG_sL_8:
    case VG_lL_8:
       return PIPE_FORMAT_L8_UNORM;
    case VG_BW_1:
-      return PIPE_FORMAT_A8R8G8B8_UNORM;
+      return PIPE_FORMAT_B8G8R8A8_UNORM;
    case VG_A_8:
       return PIPE_FORMAT_A8_UNORM;
 #ifdef OPENVG_VERSION_1_1
@@ -66,7 +67,7 @@ static enum pipe_format vg_format_to_pipe(VGImageFormat format)
       return PIPE_FORMAT_A8_UNORM;
 #endif
    default:
-      return PIPE_FORMAT_A8R8G8B8_UNORM;
+      return PIPE_FORMAT_B8G8R8A8_UNORM;
    }
 }
 
@@ -80,8 +81,8 @@ static INLINE void vg_sync_size(VGfloat *src_loc, VGfloat *dst_loc)
 
 
 static void vg_copy_texture(struct vg_context *ctx,
-                            struct pipe_texture *dst, VGint dx, VGint dy,
-                            struct pipe_texture *src, VGint sx, VGint sy,
+                            struct pipe_resource *dst, VGint dx, VGint dy,
+                            struct pipe_sampler_view *src, VGint sx, VGint sy,
                             VGint width, VGint height)
 {
    VGfloat dst_loc[4], src_loc[4];
@@ -103,8 +104,8 @@ static void vg_copy_texture(struct vg_context *ctx,
    src_loc[3] = height;
    src_bounds[0] = 0.f;
    src_bounds[1] = 0.f;
-   src_bounds[2] = src->width0;
-   src_bounds[3] = src->height0;
+   src_bounds[2] = src->texture->width0;
+   src_bounds[3] = src->texture->height0;
 
    vg_bound_rect(src_loc, src_bounds, src_shift);
    vg_bound_rect(dst_loc, dst_bounds, dst_shift);
@@ -216,9 +217,9 @@ void vg_copy_surface(struct vg_context *ctx,
 
 }
 
-static struct pipe_texture *image_texture(struct vg_image *img)
+static struct pipe_resource *image_texture(struct vg_image *img)
 {
-   struct pipe_texture *tex = img->texture;
+   struct pipe_resource *tex = img->sampler_view->texture;
    return tex;
 }
 
@@ -247,9 +248,12 @@ struct vg_image * image_create(VGImageFormat format,
                                VGint width, VGint height)
 {
    struct vg_context *ctx = vg_current_context();
+   struct pipe_context *pipe = ctx->pipe;
    struct vg_image *image = CALLOC_STRUCT(vg_image);
    enum pipe_format pformat = vg_format_to_pipe(format);
-   struct pipe_texture pt, *newtex;
+   struct pipe_resource pt, *newtex;
+   struct pipe_sampler_view view_templ;
+   struct pipe_sampler_view *view;
    struct pipe_screen *screen = ctx->pipe->screen;
 
    vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE);
@@ -266,7 +270,7 @@ struct vg_image * image_create(VGImageFormat format,
    image->sampler.normalized_coords = 1;
 
    assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D,
-                                      PIPE_TEXTURE_USAGE_SAMPLER, 0));
+                                      PIPE_BIND_SAMPLER_VIEW, 0));
 
    memset(&pt, 0, sizeof(pt));
    pt.target = PIPE_TEXTURE_2D;
@@ -275,13 +279,18 @@ struct vg_image * image_create(VGImageFormat format,
    pt.width0 = width;
    pt.height0 = height;
    pt.depth0 = 1;
-   pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
+   pt.bind = PIPE_BIND_SAMPLER_VIEW;
 
-   newtex = screen->texture_create(screen, &pt);
+   newtex = screen->resource_create(screen, &pt);
 
    debug_assert(newtex);
 
-   image->texture = newtex;
+   u_sampler_view_default_template(&view_templ, newtex, newtex->format);
+   view = pipe->create_sampler_view(pipe, newtex, &view_templ);
+   /* want the texture to go away if the view is freed */
+   pipe_resource_reference(&newtex, NULL);
+
+   image->sampler_view = view;
 
    vg_context_add_object(ctx, VG_OBJECT_IMAGE, image);
 
@@ -345,7 +354,7 @@ void image_destroy(struct vg_image *img)
       array_destroy(img->children_array);
    }
 
-   pipe_texture_reference(&img->texture, NULL);
+   pipe_sampler_view_reference(&img->sampler_view, NULL);
    free(img);
 }
 
@@ -378,8 +387,8 @@ void image_sub_data(struct vg_image *image,
    VGfloat *df = (VGfloat*)temp;
    VGint i;
    struct vg_context *ctx = vg_current_context();
-   struct pipe_screen *screen = ctx->pipe->screen;
-   struct pipe_texture *texture = image_texture(image);
+   struct pipe_context *pipe = ctx->pipe;
+   struct pipe_resource *texture = image_texture(image);
    VGint xoffset = 0, yoffset = 0;
 
    if (x < 0) {
@@ -412,17 +421,17 @@ void image_sub_data(struct vg_image *image,
    }
 
    { /* upload color_data */
-      struct pipe_transfer *transfer = screen->get_tex_transfer(
-         screen, texture, 0, 0, 0,
+      struct pipe_transfer *transfer = pipe_get_transfer(
+         pipe, texture, 0, 0, 0,
          PIPE_TRANSFER_WRITE, 0, 0, texture->width0, texture->height0);
       src += (dataStride * yoffset);
       for (i = 0; i < height; i++) {
          _vega_unpack_float_span_rgba(ctx, width, xoffset, src, dataFormat, temp);
-         pipe_put_tile_rgba(transfer, x+image->x, y+image->y, width, 1, df);
+         pipe_put_tile_rgba(pipe, transfer, x+image->x, y+image->y, width, 1, df);
          y += yStep;
          src += dataStride;
       }
-      screen->tex_transfer_destroy(transfer);
+      pipe->transfer_destroy(pipe, transfer);
    }
 }
 
@@ -435,7 +444,6 @@ void image_get_sub_data(struct vg_image * image,
 {
    struct vg_context *ctx = vg_current_context();
    struct pipe_context *pipe = ctx->pipe;
-   struct pipe_screen *screen = pipe->screen;
    VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4];
    VGfloat *df = (VGfloat*)temp;
    VGint y = 0, yStep = 1;
@@ -444,8 +452,8 @@ void image_get_sub_data(struct vg_image * image,
 
    {
       struct pipe_transfer *transfer =
-         screen->get_tex_transfer(screen,
-                                  image->texture,  0, 0, 0,
+         pipe_get_transfer(pipe,
+                                  image->sampler_view->texture,  0, 0, 0,
                                   PIPE_TRANSFER_READ,
                                   0, 0,
                                   image->x + image->width,
@@ -455,13 +463,13 @@ void image_get_sub_data(struct vg_image * image,
 #if 0
          debug_printf("%d-%d  == %d\n", sy, height, y);
 #endif
-         pipe_get_tile_rgba(transfer, sx+image->x, y, width, 1, df);
+         pipe_get_tile_rgba(pipe, transfer, sx+image->x, y, width, 1, df);
          y += yStep;
          _vega_pack_rgba_span_float(ctx, width, temp, dataFormat, dst);
          dst += dataStride;
       }
 
-      screen->tex_transfer_destroy(transfer);
+      pipe->transfer_destroy(pipe, transfer);
    }
 }
 
@@ -479,9 +487,9 @@ struct vg_image * image_child_image(struct vg_image *parent,
    image->width = width;
    image->height = height;
    image->parent = parent;
-   image->texture = 0;
-   pipe_texture_reference(&image->texture,
-                          parent->texture);
+   image->sampler_view = NULL;
+   pipe_sampler_view_reference(&image->sampler_view,
+                               parent->sampler_view);
 
    image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
    image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
@@ -515,8 +523,8 @@ void image_copy(struct vg_image *dst, VGint dx, VGint dy,
    }
    /* make sure rendering has completed */
    ctx->pipe->flush(ctx->pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
-   vg_copy_texture(ctx, dst->texture, dst->x + dx, dst->y + dy,
-                   src->texture, src->x + sx, src->y + sy, width, height);
+   vg_copy_texture(ctx, dst->sampler_view->texture, dst->x + dx, dst->y + dy,
+                   src->sampler_view, src->x + sx, src->y + sy, width, height);
 }
 
 void image_draw(struct vg_image *img)
@@ -568,7 +576,7 @@ void image_set_pixels(VGint dx, VGint dy,
    pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
 
    surf = screen->get_tex_surface(screen, image_texture(src),  0, 0, 0,
-                                  PIPE_BUFFER_USAGE_GPU_READ);
+                                  PIPE_BIND_BLIT_SOURCE);
 
    vg_copy_surface(ctx, strb->surface, dx, dy,
                    surf, sx+src->x, sy+src->y, width, height);
@@ -593,8 +601,8 @@ void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy,
    pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
 
    surf = screen->get_tex_surface(screen, image_texture(dst),  0, 0, 0,
-                                  PIPE_BUFFER_USAGE_GPU_WRITE |
-                                  PIPE_BUFFER_USAGE_GPU_READ);
+                                  PIPE_BIND_BLIT_SOURCE);
+
    vg_copy_surface(ctx, surf, dst->x + dx, dst->y + dy,
                    strb->surface, sx, sy, width, height);
 
@@ -625,12 +633,12 @@ VGboolean vg_image_overlaps(struct vg_image *dst,
 }
 
 VGint image_bind_samplers(struct vg_image *img, struct pipe_sampler_state **samplers,
-                          struct pipe_texture **textures)
+                          struct pipe_sampler_view **sampler_views)
 {
    img->sampler.min_img_filter = image_sampler_filter(img->base.ctx);
    img->sampler.mag_img_filter = image_sampler_filter(img->base.ctx);
    samplers[3] = &img->sampler;
-   textures[3] = img->texture;
+   sampler_views[3] = img->sampler_view;
    return 1;
 }