st/mesa: increase size of glsl_base_type bitfields
[mesa.git] / src / mesa / state_tracker / st_cb_bitmap.c
index 5765ed28cef046546c5ad9d00639e8483b77a2d2..a5c7ed0ee66d27bcae6d662a25d916361e9c0349 100644 (file)
@@ -45,6 +45,7 @@
 #include "st_draw.h"
 #include "st_program.h"
 #include "st_cb_bitmap.h"
+#include "st_sampler_view.h"
 #include "st_texture.h"
 
 #include "pipe/p_context.h"
@@ -82,27 +83,6 @@ static GLboolean UseBitmapCache = GL_TRUE;
 #define BITMAP_CACHE_WIDTH  512
 #define BITMAP_CACHE_HEIGHT 32
 
-struct bitmap_cache
-{
-   /** Window pos to render the cached image */
-   GLint xpos, ypos;
-   /** Bounds of region used in window coords */
-   GLint xmin, ymin, xmax, ymax;
-
-   GLfloat color[4];
-
-   /** Bitmap's Z position */
-   GLfloat zpos;
-
-   struct pipe_resource *texture;
-   struct pipe_transfer *trans;
-
-   GLboolean empty;
-
-   /** An I8 texture image: */
-   ubyte *buffer;
-};
-
 
 /** Epsilon for Z comparisons */
 #define Z_EPSILON 1e-06
@@ -211,8 +191,7 @@ setup_render_state(struct gl_context *ctx,
       GLfloat colorSave[4];
       COPY_4V(colorSave, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
       COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], color);
-      st_upload_constants(st, st->fp->Base.Base.Parameters,
-                          PIPE_SHADER_FRAGMENT);
+      st_upload_constants(st, &st->fp->Base);
       COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], colorSave);
    }
 
@@ -270,8 +249,8 @@ setup_render_state(struct gl_context *ctx,
    }
 
    /* viewport state: viewport matching window dims */
-   cso_set_viewport_dims(cso, st->state.framebuffer.width,
-                         st->state.framebuffer.height,
+   cso_set_viewport_dims(cso, st->state.fb_width,
+                         st->state.fb_height,
                          st->state.fb_orientation == Y_0_TOP);
 
    cso_set_vertex_elements(cso, 3, st->util_velems);
@@ -304,8 +283,8 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
 {
    struct st_context *st = st_context(ctx);
    struct pipe_context *pipe = st->pipe;
-   const float fb_width = (float) st->state.framebuffer.width;
-   const float fb_height = (float) st->state.framebuffer.height;
+   const float fb_width = (float) st->state.fb_width;
+   const float fb_height = (float) st->state.fb_height;
    const float x0 = (float) x;
    const float x1 = (float) (x + width);
    const float y0 = (float) y;
@@ -322,8 +301,9 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
       /* XXX if the bitmap is larger than the max texture size, break
        * it up into chunks.
        */
-      GLuint maxSize = 1 << (pipe->screen->get_param(pipe->screen,
-                                    PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
+      GLuint MAYBE_UNUSED maxSize =
+         1 << (pipe->screen->get_param(pipe->screen,
+                                       PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
       assert(width <= (GLsizei) maxSize);
       assert(height <= (GLsizei) maxSize);
    }
@@ -354,7 +334,7 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
 static void
 reset_cache(struct st_context *st)
 {
-   struct bitmap_cache *cache = st->bitmap.cache;
+   struct st_bitmap_cache *cache = &st->bitmap.cache;
 
    /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
    cache->empty = GL_TRUE;
@@ -377,7 +357,7 @@ reset_cache(struct st_context *st)
 
 /** Print bitmap image to stdout (debug) */
 static void
-print_cache(const struct bitmap_cache *cache)
+print_cache(const struct st_bitmap_cache *cache)
 {
    int i, j, k;
 
@@ -402,7 +382,7 @@ static void
 create_cache_trans(struct st_context *st)
 {
    struct pipe_context *pipe = st->pipe;
-   struct bitmap_cache *cache = st->bitmap.cache;
+   struct st_bitmap_cache *cache = &st->bitmap.cache;
 
    if (cache->trans)
       return;
@@ -426,9 +406,9 @@ create_cache_trans(struct st_context *st)
 void
 st_flush_bitmap_cache(struct st_context *st)
 {
-   struct bitmap_cache *cache = st->bitmap.cache;
+   struct st_bitmap_cache *cache = &st->bitmap.cache;
 
-   if (cache && !cache->empty) {
+   if (!cache->empty) {
       struct pipe_context *pipe = st->pipe;
       struct pipe_sampler_view *sv;
 
@@ -483,7 +463,7 @@ accum_bitmap(struct gl_context *ctx,
              const GLubyte *bitmap )
 {
    struct st_context *st = ctx->st;
-   struct bitmap_cache *cache = st->bitmap.cache;
+   struct st_bitmap_cache *cache = &st->bitmap.cache;
    int px = -999, py = -999;
    const GLfloat z = ctx->Current.RasterPos[2];
 
@@ -557,14 +537,11 @@ init_bitmap_state(struct st_context *st)
    struct pipe_screen *screen = pipe->screen;
 
    /* This function should only be called once */
-   assert(st->bitmap.cache == NULL);
+   assert(st->bitmap.vs == NULL);
 
    assert(st->internal_target == PIPE_TEXTURE_2D ||
           st->internal_target == PIPE_TEXTURE_RECT);
 
-   /* alloc bitmap cache object */
-   st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache);
-
    /* init sampler state once */
    memset(&st->bitmap.sampler, 0, sizeof(st->bitmap.sampler));
    st->bitmap.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP;
@@ -638,7 +615,7 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
 
    st_invalidate_readpix_cache(st);
 
-   if (!st->bitmap.cache) {
+   if (!st->bitmap.vs) {
       init_bitmap_state(st);
    }
 
@@ -647,7 +624,8 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
     * explicitly uploaded in the draw_bitmap_quad() function.
     */
    if ((st->dirty | ctx->NewDriverState) & ~ST_NEW_CONSTANTS &
-       ST_PIPELINE_RENDER_STATE_MASK) {
+       ST_PIPELINE_RENDER_STATE_MASK ||
+       st->gfx_shaders_may_be_dirty) {
       st_validate_state(st, ST_PIPELINE_RENDER);
    }
 
@@ -689,15 +667,15 @@ st_DrawAtlasBitmaps(struct gl_context *ctx,
    /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
    const float z = ctx->Current.RasterPos[2] * 2.0f - 1.0f;
    const float *color = ctx->Current.RasterColor;
-   const float clip_x_scale = 2.0f / st->state.framebuffer.width;
-   const float clip_y_scale = 2.0f / st->state.framebuffer.height;
+   const float clip_x_scale = 2.0f / st->state.fb_width;
+   const float clip_y_scale = 2.0f / st->state.fb_height;
    const unsigned num_verts = count * 4;
    const unsigned num_vert_bytes = num_verts * sizeof(struct st_util_vertex);
    struct st_util_vertex *verts;
    struct pipe_vertex_buffer vb = {0};
    unsigned i;
 
-   if (!st->bitmap.cache) {
+   if (!st->bitmap.vs) {
       init_bitmap_state(st);
    }
 
@@ -716,8 +694,13 @@ st_DrawAtlasBitmaps(struct gl_context *ctx,
 
    vb.stride = sizeof(struct st_util_vertex);
 
-   u_upload_alloc(st->uploader, 0, num_vert_bytes, 4,
-                  &vb.buffer_offset, &vb.buffer, (void **) &verts);
+   u_upload_alloc(pipe->stream_uploader, 0, num_vert_bytes, 4,
+                  &vb.buffer_offset, &vb.buffer.resource, (void **) &verts);
+
+   if (unlikely(!verts)) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCallLists(bitmap text)");
+      goto out;
+   }
 
    /* build quads vertex data */
    for (i = 0; i < count; i++) {
@@ -788,7 +771,7 @@ st_DrawAtlasBitmaps(struct gl_context *ctx,
       ctx->Current.RasterPos[1] += ymove;
    }
 
-   u_upload_unmap(st->uploader);
+   u_upload_unmap(pipe->stream_uploader);
 
    cso_set_vertex_buffers(st->cso_context,
                           cso_get_aux_vertex_buffer_slot(st->cso_context),
@@ -796,9 +779,10 @@ st_DrawAtlasBitmaps(struct gl_context *ctx,
 
    cso_draw_arrays(st->cso_context, PIPE_PRIM_QUADS, 0, num_verts);
 
+out:
    restore_render_state(ctx);
 
-   pipe_resource_reference(&vb.buffer, NULL);
+   pipe_resource_reference(&vb.buffer.resource, NULL);
 
    pipe_sampler_view_reference(&sv, NULL);
 
@@ -822,19 +806,15 @@ void
 st_destroy_bitmap(struct st_context *st)
 {
    struct pipe_context *pipe = st->pipe;
-   struct bitmap_cache *cache = st->bitmap.cache;
+   struct st_bitmap_cache *cache = &st->bitmap.cache;
 
    if (st->bitmap.vs) {
       cso_delete_vertex_shader(st->cso_context, st->bitmap.vs);
       st->bitmap.vs = NULL;
    }
 
-   if (cache) {
-      if (cache->trans && cache->buffer) {
-         pipe_transfer_unmap(pipe, cache->trans);
-      }
-      pipe_resource_reference(&st->bitmap.cache->texture, NULL);
-      free(st->bitmap.cache);
-      st->bitmap.cache = NULL;
+   if (cache->trans && cache->buffer) {
+      pipe_transfer_unmap(pipe, cache->trans);
    }
+   pipe_resource_reference(&st->bitmap.cache.texture, NULL);
 }