X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Futil%2Fu_surface.c;h=42440d0d67389afdbdd4b355de469009b0b50d4a;hb=a1a7738223b754044213b969371823ec52b0a9e2;hp=35c497820434e5bbb506853101e844c341c8502a;hpb=a4b6b428855e73b35f754a9f64647c6edc1a88fa;p=mesa.git diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index 35c49782043..42440d0d673 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -35,8 +35,9 @@ #include "pipe/p_screen.h" #include "pipe/p_state.h" #include "pipe/p_defines.h" +#include "util/u_inlines.h" -#include "util/u_format.h" +#include "util/u_memory.h" #include "util/u_surface.h" @@ -49,25 +50,25 @@ boolean util_create_rgba_surface(struct pipe_screen *screen, uint width, uint height, - struct pipe_texture **textureOut, + uint bind, + struct pipe_resource **textureOut, struct pipe_surface **surfaceOut) { static const enum pipe_format rgbaFormats[] = { - PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_A8B8G8R8_UNORM, PIPE_FORMAT_NONE }; const uint target = PIPE_TEXTURE_2D; - const uint usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; enum pipe_format format = PIPE_FORMAT_NONE; - struct pipe_texture templ; + struct pipe_resource templ; uint i; /* Choose surface format */ for (i = 0; rgbaFormats[i]; i++) { if (screen->is_format_supported(screen, rgbaFormats[i], - target, usage, 0)) { + target, bind, 0)) { format = rgbaFormats[i]; break; } @@ -83,16 +84,19 @@ util_create_rgba_surface(struct pipe_screen *screen, templ.width0 = width; templ.height0 = height; templ.depth0 = 1; - templ.tex_usage = usage; + templ.bind = bind; - *textureOut = screen->texture_create(screen, &templ); + *textureOut = screen->resource_create(screen, &templ); if (!*textureOut) return FALSE; /* create surface / view into texture */ - *surfaceOut = screen->get_tex_surface(screen, *textureOut, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); + *surfaceOut = screen->get_tex_surface(screen, + *textureOut, + 0, 0, 0, + bind); if (!*surfaceOut) { - pipe_texture_reference(textureOut, NULL); + pipe_resource_reference(textureOut, NULL); return FALSE; } @@ -104,10 +108,80 @@ util_create_rgba_surface(struct pipe_screen *screen, * Release the surface and texture from util_create_rgba_surface(). */ void -util_destroy_rgba_surface(struct pipe_texture *texture, +util_destroy_rgba_surface(struct pipe_resource *texture, struct pipe_surface *surface) { pipe_surface_reference(&surface, NULL); - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); } + + +/** + * Compare pipe_framebuffer_state objects. + * \return TRUE if same, FALSE if different + */ +boolean +util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src) +{ + unsigned i; + + if (dst->width != src->width || + dst->height != src->height) + return FALSE; + + for (i = 0; i < Elements(src->cbufs); i++) { + if (dst->cbufs[i] != src->cbufs[i]) { + return FALSE; + } + } + + if (dst->nr_cbufs != src->nr_cbufs) { + return FALSE; + } + + if (dst->zsbuf != src->zsbuf) { + return FALSE; + } + + return TRUE; +} + + +/** + * Copy framebuffer state from src to dst, updating refcounts. + */ +void +util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src) +{ + unsigned i; + + dst->width = src->width; + dst->height = src->height; + + for (i = 0; i < Elements(src->cbufs); i++) { + pipe_surface_reference(&dst->cbufs[i], src->cbufs[i]); + } + + dst->nr_cbufs = src->nr_cbufs; + + pipe_surface_reference(&dst->zsbuf, src->zsbuf); +} + + +void +util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb) +{ + unsigned i; + + for (i = 0; i < fb->nr_cbufs; i++) { + pipe_surface_reference(&fb->cbufs[i], NULL); + } + + pipe_surface_reference(&fb->zsbuf, NULL); + + fb->width = fb->height = 0; + fb->nr_cbufs = 0; +}