Mesa (master): st/mesa: put the bitmap_cache structure inside st_context

Marek Olšák mareko at kemper.freedesktop.org
Thu Apr 20 18:16:53 UTC 2017


Module: Mesa
Branch: master
Commit: 1fb5bc83f19cc87767f902b99e77b330258a69dd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1fb5bc83f19cc87767f902b99e77b330258a69dd

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sun Apr  9 16:45:00 2017 +0200

st/mesa: put the bitmap_cache structure inside st_context

This is nicer on caches, and the next commit will need to access
the structure from a different place.

Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>
Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/state_tracker/st_cb_bitmap.c | 54 +++++++++--------------------------
 src/mesa/state_tracker/st_context.c   |  2 ++
 src/mesa/state_tracker/st_context.h   | 23 +++++++++++++--
 3 files changed, 36 insertions(+), 43 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index cf820e4214..e0745f4812 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -83,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
@@ -354,7 +333,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 +356,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 +381,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 +405,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 +462,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 +536,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 +614,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);
    }
 
@@ -698,7 +674,7 @@ st_DrawAtlasBitmaps(struct gl_context *ctx,
    struct pipe_vertex_buffer vb = {0};
    unsigned i;
 
-   if (!st->bitmap.cache) {
+   if (!st->bitmap.vs) {
       init_bitmap_state(st);
    }
 
@@ -829,19 +805,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);
 }
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index fb98a34001..801322622f 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -484,6 +484,8 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
    st->shader_has_one_variant[MESA_SHADER_GEOMETRY] = st->has_shareable_shaders;
    st->shader_has_one_variant[MESA_SHADER_COMPUTE] = st->has_shareable_shaders;
 
+   st->bitmap.cache.empty = true;
+
    _mesa_compute_version(ctx);
 
    if (ctx->Version == 0) {
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index dfee927565..74ab43cfe9 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -40,7 +40,6 @@ extern "C" {
 #endif
 
 
-struct bitmap_cache;
 struct dd_function_table;
 struct draw_context;
 struct draw_stage;
@@ -59,6 +58,26 @@ struct st_util_vertex
    float s, t;
 };
 
+struct st_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;
+};
 
 struct st_context
 {
@@ -180,7 +199,7 @@ struct st_context
       struct pipe_sampler_state atlas_sampler;
       enum pipe_format tex_format;
       void *vs;
-      struct bitmap_cache *cache;
+      struct st_bitmap_cache cache;
    } bitmap;
 
    /** for glDraw/CopyPixels */




More information about the mesa-commit mailing list