Mesa (gallium-fb-dimensions): st/vega: update for framebuffer width/ height removal

Keith Whitwell keithw at kemper.freedesktop.org
Thu Jan 7 17:44:27 UTC 2010


Module: Mesa
Branch: gallium-fb-dimensions
Commit: 927f07044a2a93018be7b9d2438ee62df926bc4d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=927f07044a2a93018be7b9d2438ee62df926bc4d

Author: Keith Whitwell <keithw at vmware.com>
Date:   Thu Jan  7 17:34:16 2010 +0000

st/vega: update for framebuffer width/height removal

---

 src/gallium/state_trackers/vega/api_filters.c |    8 +------
 src/gallium/state_trackers/vega/api_images.c  |   21 ++++++++++++++---
 src/gallium/state_trackers/vega/api_masks.c   |    8 ++++++-
 src/gallium/state_trackers/vega/mask.c        |   29 ++++++++++--------------
 src/gallium/state_trackers/vega/renderer.c    |   15 +++++-------
 src/gallium/state_trackers/vega/stroker.c     |    2 +-
 src/gallium/state_trackers/vega/vg_context.c  |   29 ++++++++++++++++++-------
 src/gallium/state_trackers/vega/vg_tracker.c  |    3 --
 8 files changed, 65 insertions(+), 50 deletions(-)

diff --git a/src/gallium/state_trackers/vega/api_filters.c b/src/gallium/state_trackers/vega/api_filters.c
index 2f984fb..c6f38c9 100644
--- a/src/gallium/state_trackers/vega/api_filters.c
+++ b/src/gallium/state_trackers/vega/api_filters.c
@@ -102,15 +102,9 @@ static INLINE struct pipe_surface * setup_framebuffer(struct vg_image *dst)
 
    /* drawing dest */
    memset(&fb, 0, sizeof(fb));
-   fb.width  = dst->x + dst_surf->width;
-   fb.height = dst->y + dst_surf->height;
    fb.nr_cbufs = 1;
    fb.cbufs[0] = dst_surf;
-   {
-      VGint i;
-      for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i)
-         fb.cbufs[i] = 0;
-   }
+
    cso_set_framebuffer(ctx->cso_context, &fb);
 
    return dst_surf;
diff --git a/src/gallium/state_trackers/vega/api_images.c b/src/gallium/state_trackers/vega/api_images.c
index c437553..aa7ae8f 100644
--- a/src/gallium/state_trackers/vega/api_images.c
+++ b/src/gallium/state_trackers/vega/api_images.c
@@ -405,7 +405,8 @@ void vgReadPixels(void * data, VGint dataStride,
 
    VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4];
    VGfloat *df = (VGfloat*)temp;
-   VGint y = (fb->height - sy) - 1, yStep = -1;
+   VGint y = 0;
+   VGint yStep = -1;
    VGint i;
    VGubyte *dst = (VGubyte *)data;
    VGint xoffset = 0, yoffset = 0;
@@ -422,6 +423,10 @@ void vgReadPixels(void * data, VGint dataStride,
       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
       return;
    }
+   if (fb->cbufs[0] == NULL)
+      return;
+
+   yStep = (fb->cbufs[0]->height - sy) - 1;
 
    /* make sure rendering has completed */
    pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
@@ -435,7 +440,7 @@ void vgReadPixels(void * data, VGint dataStride,
       yoffset = -sy;
       height += sy;
       sy = 0;
-      y = (fb->height - sy) - 1;
+      y = (fb->cbufs[0]->height - sy) - 1;
       yoffset *= dataStride;
    }
 
@@ -469,6 +474,7 @@ void vgCopyPixels(VGint dx, VGint dy,
    struct vg_context *ctx = vg_current_context();
    struct pipe_framebuffer_state *fb = &ctx->state.g3d.fb;
    struct st_renderbuffer *strb = ctx->draw_buffer->strb;
+   VGint fb_width, fb_height;
 
    if (width <= 0 || height <= 0) {
       vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
@@ -476,10 +482,17 @@ void vgCopyPixels(VGint dx, VGint dy,
    }
 
    /* do nothing if we copy from outside the fb */
-   if (dx >= (VGint)fb->width || dy >= (VGint)fb->height ||
-       sx >= (VGint)fb->width || sy >= (VGint)fb->height)
+   if (fb->cbufs[0] == NULL)
+      return;
+
+   fb_width = (VGint)fb->cbufs[0]->width;
+   fb_height = (VGint)fb->cbufs[0]->height;
+
+   if (dx >= (VGint)fb_width || dy >= (VGint)fb_height ||
+       sx >= (VGint)fb_width || sy >= (VGint)fb_height)
       return;
 
+
    vg_validate_state(ctx);
    /* make sure rendering has completed */
    vgFinish();
diff --git a/src/gallium/state_trackers/vega/api_masks.c b/src/gallium/state_trackers/vega/api_masks.c
index 4f9f3da..2161f39 100644
--- a/src/gallium/state_trackers/vega/api_masks.c
+++ b/src/gallium/state_trackers/vega/api_masks.c
@@ -216,9 +216,15 @@ void vgClear(VGint x, VGint y,
 #endif
 
    fb = &ctx->state.g3d.fb;
+   if (fb->cbufs[0] == NULL)
+      return;
+
    /* check for a whole surface clear */
    if (!ctx->state.vg.scissoring &&
-       (x == 0 && y == 0 && width == fb->width && height == fb->height)) {
+       x == 0 &&
+       y == 0 && 
+       width == fb->cbufs[0]->width &&
+       height == fb->cbufs[0]->height) {
       ctx->pipe->clear(ctx->pipe, PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
                        ctx->state.vg.clear_color, 1., 0);
    } else {
diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c
index 42300bb..1a11f11 100644
--- a/src/gallium/state_trackers/vega/mask.c
+++ b/src/gallium/state_trackers/vega/mask.c
@@ -118,7 +118,7 @@ static void read_alpha_mask(void * data, VGint dataStride,
 
    VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4];
    VGfloat *df = (VGfloat*)temp;
-   VGint y = (fb->height - sy) - 1, yStep = -1;
+   VGint y = (fb->cbufs[0]->height - sy) - 1, yStep = -1;
    VGint i;
    VGubyte *dst = (VGubyte *)data;
    VGint xoffset = 0, yoffset = 0;
@@ -135,7 +135,7 @@ static void read_alpha_mask(void * data, VGint dataStride,
       yoffset = -sy;
       height += sy;
       sy = 0;
-      y = (fb->height - sy) - 1;
+      y = (fb->cbufs[0]->height - sy) - 1;
       yoffset *= dataStride;
    }
 
@@ -166,21 +166,23 @@ void save_alpha_to_file(const char *filename)
    struct vg_context *ctx = vg_current_context();
    struct pipe_framebuffer_state *fb = &ctx->state.g3d.fb;
    VGint *data;
+   int width = fb->cbufs[0]->width;
+   int height = fb->cbufs[0]->height;
    int i, j;
 
-   data = malloc(sizeof(int) * fb->width * fb->height);
-   read_alpha_mask(data, fb->width * sizeof(int),
+   data = malloc(sizeof(int) * width * height);
+   read_alpha_mask(data, width * sizeof(int),
                    VG_sRGBA_8888,
-                   0, 0, fb->width, fb->height);
+                   0, 0, width, height);
    fprintf(stderr, "/*---------- start */\n");
    fprintf(stderr, "const int image_width = %d;\n",
-           fb->width);
+           width);
    fprintf(stderr, "const int image_height = %d;\n",
-           fb->height);
+           height);
    fprintf(stderr, "const int image_data = {\n");
-   for (i = 0; i < fb->height; ++i) {
-      for (j = 0; j < fb->width; ++j) {
-         int rgba = data[i * fb->height + j];
+   for (i = 0; i < height; ++i) {
+      for (j = 0; j < width; ++j) {
+         int rgba = data[i * height + j];
          int argb = 0;
          argb = (rgba >> 8);
          argb |= ((rgba & 0xff) << 24);
@@ -200,15 +202,8 @@ static void setup_mask_framebuffer(struct pipe_surface *surf,
    struct pipe_framebuffer_state fb;
 
    memset(&fb, 0, sizeof(fb));
-   fb.width = surf_width;
-   fb.height = surf_height;
    fb.nr_cbufs = 1;
    fb.cbufs[0] = surf;
-   {
-      VGint i;
-      for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i)
-         fb.cbufs[i] = 0;
-   }
    cso_set_framebuffer(ctx->cso_context, &fb);
 }
 
diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c
index 64e3a7c..2782d13 100644
--- a/src/gallium/state_trackers/vega/renderer.c
+++ b/src/gallium/state_trackers/vega/renderer.c
@@ -351,15 +351,8 @@ void renderer_copy_texture(struct renderer *ctx,
 
    /* drawing dest */
    memset(&fb, 0, sizeof(fb));
-   fb.width = dst_surf->width;
-   fb.height = dst_surf->height;
    fb.nr_cbufs = 1;
    fb.cbufs[0] = dst_surf;
-   {
-      VGint i;
-      for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i)
-         fb.cbufs[i] = 0;
-   }
    cso_set_framebuffer(ctx->cso, &fb);
 
    /* draw quad */
@@ -521,11 +514,15 @@ void renderer_copy_surface(struct renderer *ctx,
    /* drawing dest */
    if (stfb->strb->surface != dst) {
       memset(&fb, 0, sizeof(fb));
-      fb.width = dst->width;
-      fb.height = dst->height;
       fb.nr_cbufs = 1;
       fb.cbufs[0] = dst;
       fb.zsbuf = stfb->dsrb->surface;
+      
+      if (dst && stfb->dsrb->surface) {
+         assert(dst->width == stfb->dsrb->surface->width);
+         assert(dst->height == stfb->dsrb->surface->height);
+      }
+
       cso_set_framebuffer(ctx->cso, &fb);
    }
 
diff --git a/src/gallium/state_trackers/vega/stroker.c b/src/gallium/state_trackers/vega/stroker.c
index 68a5202..ec94fa8 100644
--- a/src/gallium/state_trackers/vega/stroker.c
+++ b/src/gallium/state_trackers/vega/stroker.c
@@ -52,7 +52,7 @@ static const VGfloat zero_coords[] = {0.f, 0.f};
 enum intersection_type {
    NoIntersections,
    BoundedIntersection,
-   UnboundedIntersection,
+   UnboundedIntersection
 };
 
 enum line_join_mode {
diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c
index 00d23f5..31c89fd 100644
--- a/src/gallium/state_trackers/vega/vg_context.c
+++ b/src/gallium/state_trackers/vega/vg_context.c
@@ -228,7 +228,8 @@ static void update_clip_state(struct vg_context *ctx)
 
    memset(dsa, 0, sizeof(struct pipe_depth_stencil_alpha_state));
 
-   if (state->scissoring) {
+   if (state->scissoring &&
+       ctx->state.g3d.fb.cbufs[0]) {
       struct pipe_blend_state *blend = &ctx->state.g3d.blend;
       struct pipe_framebuffer_state *fb = &ctx->state.g3d.fb;
       int i;
@@ -265,8 +266,8 @@ static void update_clip_state(struct vg_context *ctx)
 
          minx = 0;
          miny = 0;
-         maxx = fb->width;
-         maxy = fb->height;
+         maxx = fb->cbufs[0]->width;
+         maxy = fb->cbufs[0]->height;
 
          if (x > minx)
             minx = x;
@@ -368,13 +369,18 @@ void vg_validate_state(struct vg_context *ctx)
       struct pipe_framebuffer_state *fb = &ctx->state.g3d.fb;
       const VGint param_bytes = 8 * sizeof(VGfloat);
       VGfloat vs_consts[8] = {
-         2.f/fb->width, 2.f/fb->height, 1, 1,
+         0, 0, 1, 1,
          -1, -1, 0, 0
       };
       struct pipe_constant_buffer *cbuf = &ctx->vs_const_buffer;
 
       vg_set_viewport(ctx, VEGA_Y0_BOTTOM);
 
+      if (fb->cbufs[0]) {
+         vs_consts[0] = 2.f/fb->cbufs[0]->width;
+         vs_consts[1] = 2.f/fb->cbufs[0]->height;
+      }
+
       pipe_buffer_reference(&cbuf->buffer, NULL);
       cbuf->buffer = pipe_buffer_create(ctx->pipe->screen, 16,
                                         PIPE_BUFFER_USAGE_CONSTANT,
@@ -531,13 +537,20 @@ void vg_set_viewport(struct vg_context *ctx, VegaOrientation orientation)
    struct pipe_viewport_state viewport;
    struct pipe_framebuffer_state *fb = &ctx->state.g3d.fb;
    VGfloat y_scale = (orientation == VEGA_Y0_BOTTOM) ? -2.f : 2.f;
+   unsigned width, height;
+
+   if (fb->cbufs[0] == NULL)
+      return;
+
+   width = fb->cbufs[0]->width;
+   height = fb->cbufs[0]->height;
 
-   viewport.scale[0] =  fb->width / 2.f;
-   viewport.scale[1] =  fb->height / y_scale;
+   viewport.scale[0] =  width / 2.f;
+   viewport.scale[1] =  height / y_scale;
    viewport.scale[2] =  1.0;
    viewport.scale[3] =  1.0;
-   viewport.translate[0] = fb->width / 2.f;
-   viewport.translate[1] = fb->height / 2.f;
+   viewport.translate[0] = width / 2.f;
+   viewport.translate[1] = height / 2.f;
    viewport.translate[2] = 0.0;
    viewport.translate[3] = 0.0;
 
diff --git a/src/gallium/state_trackers/vega/vg_tracker.c b/src/gallium/state_trackers/vega/vg_tracker.c
index e503913..f460471 100644
--- a/src/gallium/state_trackers/vega/vg_tracker.c
+++ b/src/gallium/state_trackers/vega/vg_tracker.c
@@ -297,9 +297,6 @@ void st_resize_framebuffer(struct st_framebuffer *stfb,
 
       memset(state, 0, sizeof(struct pipe_framebuffer_state));
 
-      state->width  = width;
-      state->height = height;
-
       state->nr_cbufs = 1;
       state->cbufs[0] = strb->surface;
       for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i)




More information about the mesa-commit mailing list