sct.c File Reference

Include dependency graph for sct.c:

Go to the source code of this file.

Data Structures

struct  texture_list
struct  sct_context
struct  sct_surface

Defines

#define MAX_SURFACES   ((PIPE_MAX_COLOR_BUFS) + 1)

Functions

static struct sct_surfacefind_surface_info (struct surface_context_tracker *sct, const struct pipe_surface *surface)
 Find the surface_info for the given pipe_surface.
static struct sct_surfacefind_create_surface_info (struct surface_context_tracker *sct, const struct pipe_surface *surface)
 As above, but create new surface_info if surface is new.
static struct sct_contextfind_context_info (struct surface_context_tracker *sct, const struct pipe_context *context)
 Find a context_info for the given context.
static struct sct_contextfind_create_context_info (struct surface_context_tracker *sct, const struct pipe_context *context)
 As above, but create new context_info if context is new.
static boolean find_surface_context (const struct sct_surface *si, const struct pipe_context *context)
 Is the context already bound to the surface?
static void add_context_to_surface (struct sct_surface *si, const struct pipe_context *context)
 Add a context to the list of contexts associated with a surface.
static void remove_context_from_surface (struct sct_surface *si, const struct pipe_context *context)
 Remove a context from the list of contexts associated with a surface.
static void unbind_context_surface (struct surface_context_tracker *sct, struct pipe_context *context, struct pipe_surface *surface)
 Unbind context from surface.
void sct_bind_surfaces (struct surface_context_tracker *sct, struct pipe_context *context, uint num_surf, struct pipe_surface **surfaces)
 Bind context to a set of surfaces (color + Z).
struct sct_context_listsct_get_surface_contexts (struct surface_context_tracker *sct, const struct pipe_surface *surface)
 Return list of contexts bound to a surface.
static boolean find_texture (const struct sct_context *ci, const struct pipe_texture *texture)
static void add_texture_used (struct sct_context *ci, struct pipe_texture *texture)
 Add the given texture to the context's list of used textures.
void sct_bind_texture (struct surface_context_tracker *sct, struct pipe_context *context, uint unit, struct pipe_texture *tex)
 Bind a texture to a rendering context.
boolean sct_is_texture_used (struct surface_context_tracker *sct, const struct pipe_context *context, const struct pipe_texture *texture)
 Check if the given texture has been used by the rendering context since the last call to sct_flush_textures().
void sct_update_texture (struct pipe_texture *tex)
 To be called when the image contents of a texture are changed, such as for gl[Copy]TexSubImage().
void sct_flush_textures (struct surface_context_tracker *sct, struct pipe_context *context)
 When a scene is flushed/rendered we can release the list of used textures.
void sct_destroy_context (struct surface_context_tracker *sct, struct pipe_context *context)
void sct_destroy_surface (struct surface_context_tracker *sct, struct pipe_surface *surface)


Define Documentation

#define MAX_SURFACES   ((PIPE_MAX_COLOR_BUFS) + 1)

Definition at line 43 of file sct.c.


Function Documentation

static void add_context_to_surface ( struct sct_surface si,
const struct pipe_context context 
) [static]

Add a context to the list of contexts associated with a surface.

Definition at line 178 of file sct.c.

References CALLOC_STRUCT, sct_context_list::context, sct_surface::contexts, and sct_context_list::next.

00180 {
00181    struct sct_context_list *cl = CALLOC_STRUCT(sct_context_list);
00182    if (cl) {
00183       cl->context = context;
00184       /* insert at head of list of contexts */
00185       cl->next = si->contexts;
00186       si->contexts = cl;
00187    }
00188 }

static void add_texture_used ( struct sct_context ci,
struct pipe_texture texture 
) [static]

Add the given texture to the context's list of used textures.

Definition at line 299 of file sct.c.

References CALLOC_STRUCT, find_texture(), texture_list::next, pipe_texture_reference(), texture_list::texture, and sct_context::textures_used.

00301 {
00302    if (!find_texture(ci, texture)) {
00303       /* add to list */
00304       struct texture_list *tl = CALLOC_STRUCT(texture_list);
00305       if (tl) {
00306          pipe_texture_reference(&tl->texture, texture);
00307          /* insert at head */
00308          tl->next = ci->textures_used;
00309          ci->textures_used = tl;
00310       }
00311    }
00312 }

static struct sct_context* find_context_info ( struct surface_context_tracker sct,
const struct pipe_context context 
) [static, read]

Find a context_info for the given context.

Definition at line 121 of file sct.c.

References sct_context::context, surface_context_tracker::contexts, and sct_context::next.

00123 {
00124    struct sct_context *ci;
00125    for (ci = sct->contexts; ci; ci = ci->next)
00126       if (ci->context == context)
00127          return ci;
00128    return NULL;
00129 }

static struct sct_context* find_create_context_info ( struct surface_context_tracker sct,
const struct pipe_context context 
) [static, read]

As above, but create new context_info if context is new.

Definition at line 136 of file sct.c.

References CALLOC_STRUCT, sct_context::context, surface_context_tracker::contexts, find_context_info(), and sct_context::next.

00138 {
00139    struct sct_context *ci = find_context_info(sct, context);
00140    if (ci)
00141       return ci;
00142 
00143    /* alloc new */
00144    ci = CALLOC_STRUCT(sct_context);
00145    if (ci) {
00146       ci->context = context;
00147 
00148       /* insert at head */
00149       ci->next = sct->contexts;
00150       sct->contexts = ci;
00151    }
00152 
00153    return ci;
00154 }

static struct sct_surface* find_create_surface_info ( struct surface_context_tracker sct,
const struct pipe_surface surface 
) [static, read]

As above, but create new surface_info if surface is new.

Definition at line 96 of file sct.c.

References CALLOC_STRUCT, find_surface_info(), sct_surface::next, sct_surface::surface, and surface_context_tracker::surfaces.

00098 {
00099    struct sct_surface *si = find_surface_info(sct, surface);
00100    if (si)
00101       return si;
00102 
00103    /* alloc new */
00104    si = CALLOC_STRUCT(sct_surface);
00105    if (si) {
00106       si->surface = surface;
00107 
00108       /* insert at head */
00109       si->next = sct->surfaces;
00110       sct->surfaces = si;
00111    }
00112 
00113    return si;
00114 }

static boolean find_surface_context ( const struct sct_surface si,
const struct pipe_context context 
) [static]

Is the context already bound to the surface?

Definition at line 161 of file sct.c.

References sct_context_list::context, sct_surface::contexts, FALSE, sct_context_list::next, and TRUE.

00163 {
00164    const struct sct_context_list *cl;
00165    for (cl = si->contexts; cl; cl = cl->next) {
00166       if (cl->context == context) {
00167          return TRUE;
00168       }
00169    }
00170    return FALSE;
00171 }

static struct sct_surface* find_surface_info ( struct surface_context_tracker sct,
const struct pipe_surface surface 
) [static, read]

Find the surface_info for the given pipe_surface.

Definition at line 81 of file sct.c.

References sct_surface::next, sct_surface::surface, and surface_context_tracker::surfaces.

00083 {
00084    struct sct_surface *si;
00085    for (si = sct->surfaces; si; si = si->next)
00086       if (si->surface == surface)
00087          return si;
00088    return NULL;
00089 }

static boolean find_texture ( const struct sct_context ci,
const struct pipe_texture texture 
) [static]

Definition at line 281 of file sct.c.

References FALSE, texture_list::next, texture_list::texture, sct_context::textures_used, and TRUE.

00283 {
00284    const struct texture_list *tl;
00285 
00286    for (tl = ci->textures_used; tl; tl = tl->next) {
00287       if (tl->texture == texture) {
00288          return TRUE;
00289       }
00290    }
00291    return FALSE;
00292 }

static void remove_context_from_surface ( struct sct_surface si,
const struct pipe_context context 
) [static]

Remove a context from the list of contexts associated with a surface.

Definition at line 195 of file sct.c.

References sct_surface::contexts, FREE, and sct_context_list::next.

00197 {
00198    struct sct_context_list *prev = NULL, *curr, *next;
00199 
00200    for (curr = si->contexts; curr; curr = next) {
00201       if (curr->context == context) {
00202          /* remove */
00203          if (prev)
00204             prev->next = curr->next;
00205          else
00206             si->contexts = curr->next;
00207          next = curr->next;
00208          FREE(curr);
00209       }
00210       else {
00211          prev = curr;
00212          next = curr->next;
00213       }
00214    }
00215 }

void sct_bind_surfaces ( struct surface_context_tracker sct,
struct pipe_context context,
uint  num_surf,
struct pipe_surface **  surfaces 
)

Bind context to a set of surfaces (color + Z).

Like MakeCurrent().

Definition at line 238 of file sct.c.

References add_context_to_surface(), find_create_context_info(), find_create_surface_info(), find_surface_context(), MAX_SURFACES, sct_context::surfaces, and unbind_context_surface().

00242 {
00243    struct sct_context *ci = find_create_context_info(sct, context);
00244    uint i;
00245 
00246    if (!ci) {
00247       return; /* out of memory */
00248    }
00249 
00250    /* unbind currently bound surfaces */
00251    for (i = 0; i < MAX_SURFACES; i++) {
00252       if (ci->surfaces[i]) {
00253          unbind_context_surface(sct, context, ci->surfaces[i]);
00254       }
00255    }
00256 
00257    /* bind new surfaces */
00258    for (i = 0; i < num_surf; i++) {
00259       struct sct_surface *si = find_create_surface_info(sct, surfaces[i]);
00260       if (!find_surface_context(si, context)) {
00261          add_context_to_surface(si, context);
00262       }
00263    }
00264 }

void sct_bind_texture ( struct surface_context_tracker sct,
struct pipe_context context,
uint  unit,
struct pipe_texture tex 
)

Bind a texture to a rendering context.

Definition at line 319 of file sct.c.

References add_texture_used(), find_context_info(), pipe_texture_reference(), and sct_context::textures.

00323 {
00324    struct sct_context *ci = find_context_info(sct, context);
00325 
00326    if (ci->textures[unit] != tex) {
00327       /* put texture on the 'used' list */
00328       add_texture_used(ci, tex);
00329       /* bind new */
00330       pipe_texture_reference(&ci->textures[unit], tex);
00331    }
00332 }

void sct_destroy_context ( struct surface_context_tracker sct,
struct pipe_context context 
)

Definition at line 389 of file sct.c.

References sct_context::context, surface_context_tracker::contexts, FREE, sct_context::next, sct_surface::next, remove_context_from_surface(), and surface_context_tracker::surfaces.

00391 {
00392    /* XXX should we require an unbinding first? */
00393    {
00394       struct sct_surface *si;
00395       for (si = sct->surfaces; si; si = si->next) {
00396          remove_context_from_surface(si, context);
00397       }
00398    }
00399 
00400    /* remove context from context_info list */
00401    {
00402       struct sct_context *ci, *next, *prev = NULL;
00403       for (ci = sct->contexts; ci; ci = next) {
00404          next = ci->next;
00405          if (ci->context == context) {
00406             if (prev)
00407                prev->next = ci->next;
00408             else
00409                sct->contexts = ci->next;
00410             FREE(ci);
00411          }
00412          else {
00413             prev = ci;
00414          }
00415       }
00416    }
00417 
00418 }

void sct_destroy_surface ( struct surface_context_tracker sct,
struct pipe_surface surface 
)

Definition at line 422 of file sct.c.

References assert, surface_context_tracker::contexts, FREE, MAX_SURFACES, sct_surface::next, sct_context::next, sct_surface::surface, surface_context_tracker::surfaces, and sct_context::surfaces.

00424 {
00425    if (1) {
00426       /* debug/sanity: no context should be bound to surface */
00427       struct sct_context *ci;
00428       uint i;
00429       for (ci = sct->contexts; ci; ci = ci->next) {
00430          for (i = 0; i < MAX_SURFACES; i++) {
00431             assert(ci->surfaces[i] != surface);
00432          }
00433       }
00434    }
00435 
00436    /* remove surface from sct_surface list */
00437    {
00438       struct sct_surface *si, *next, *prev = NULL;
00439       for (si = sct->surfaces; si; si = next) {
00440          next = si->next;
00441          if (si->surface == surface) {
00442             /* unlink */
00443             if (prev)
00444                prev->next = si->next;
00445             else
00446                sct->surfaces = si->next;
00447             FREE(si);
00448          }
00449          else {
00450             prev = si;
00451          }
00452       }
00453    }
00454 }

void sct_flush_textures ( struct surface_context_tracker sct,
struct pipe_context context 
)

When a scene is flushed/rendered we can release the list of used textures.

Definition at line 366 of file sct.c.

References add_texture_used(), find_context_info(), FREE, texture_list::next, PIPE_MAX_SAMPLERS, pipe_texture_release(), texture_list::texture, sct_context::textures, and sct_context::textures_used.

00368 {
00369    struct sct_context *ci = find_context_info(sct, context);
00370    struct texture_list *tl, *next;
00371    uint i;
00372 
00373    for (tl = ci->textures_used; tl; tl = next) {
00374       next = tl->next;
00375       pipe_texture_release(&tl->texture);
00376       FREE(tl);
00377    }
00378    ci->textures_used = NULL;
00379 
00380    /* put the currently bound textures on the 'used' list */
00381    for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
00382       add_texture_used(ci, ci->textures[i]);
00383    }
00384 }

struct sct_context_list* sct_get_surface_contexts ( struct surface_context_tracker sct,
const struct pipe_surface surface 
) [read]

Return list of contexts bound to a surface.

Definition at line 271 of file sct.c.

References sct_surface::contexts, and find_surface_info().

00273 {
00274    const struct sct_surface *si = find_surface_info(sct, surface);
00275    return si->contexts;
00276 }

boolean sct_is_texture_used ( struct surface_context_tracker sct,
const struct pipe_context context,
const struct pipe_texture texture 
)

Check if the given texture has been used by the rendering context since the last call to sct_flush_textures().

Definition at line 340 of file sct.c.

References find_context_info(), and find_texture().

00343 {
00344    const struct sct_context *ci = find_context_info(sct, context);
00345    return find_texture(ci, texture);
00346 }

void sct_update_texture ( struct pipe_texture tex  ) 

To be called when the image contents of a texture are changed, such as for gl[Copy]TexSubImage().

XXX this may not be needed

Definition at line 355 of file sct.c.

00356 {
00357 
00358 }

static void unbind_context_surface ( struct surface_context_tracker sct,
struct pipe_context context,
struct pipe_surface surface 
) [static]

Unbind context from surface.

Definition at line 222 of file sct.c.

References find_surface_info(), and remove_context_from_surface().

00225 {
00226    struct sct_surface *si = find_surface_info(sct, surface);
00227    if (si) {
00228       remove_context_from_surface(si, context);
00229    }
00230 }


Generated on Tue Sep 29 06:25:25 2009 for Gallium3D by  doxygen 1.5.4