From f86def5e74566c8db1ced1cddfc1a1f7bee9875d Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 30 Apr 2010 14:46:18 +0100 Subject: util: Add missing break statement in u_caps.c Thanks Vinson. --- src/gallium/auxiliary/util/u_caps.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium/auxiliary/util') diff --git a/src/gallium/auxiliary/util/u_caps.c b/src/gallium/auxiliary/util/u_caps.c index 048bd5c34d..c7c1e830e0 100644 --- a/src/gallium/auxiliary/util/u_caps.c +++ b/src/gallium/auxiliary/util/u_caps.c @@ -73,6 +73,7 @@ util_check_caps_out(struct pipe_screen *screen, const unsigned *list, int *out) *out = i - 2; return FALSE; } + break; case UTIL_CAPS_CHECK_UNIMPLEMENTED: *out = i - 1; return FALSE; -- cgit v1.2.3 From d0f9e7521c6e59852ceb00b30f063d0fe2c72965 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Sun, 2 May 2010 16:12:50 -0700 Subject: gallium/util: print \n after DXTn printf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-add commit 2d65a7caf97684aa654088c76a74b632fbd685fa Signed-off-by: Xavier Chantry Signed-off-by: José Fonseca --- src/gallium/auxiliary/util/u_format_s3tc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium/auxiliary/util') diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c b/src/gallium/auxiliary/util/u_format_s3tc.c index 5b279b8fe2..bb989c29d8 100644 --- a/src/gallium/auxiliary/util/u_format_s3tc.c +++ b/src/gallium/auxiliary/util/u_format_s3tc.c @@ -120,7 +120,7 @@ util_format_s3tc_init(void) library = util_dl_open(DXTN_LIBNAME); if (!library) { debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn " - "compression/decompression unavailable"); + "compression/decompression unavailable\n"); return; } @@ -142,7 +142,7 @@ util_format_s3tc_init(void) !util_format_dxtn_pack) { debug_printf("couldn't reference all symbols in " DXTN_LIBNAME ", software DXTn compression/decompression " - "unavailable"); + "unavailable\n"); util_dl_close(library); return; } -- cgit v1.2.3 From bc3d9a8b187eb0756f4666a13dbc2dc1c01b0299 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Mon, 3 May 2010 19:19:02 +0200 Subject: util: add util_format_is_plain --- src/gallium/auxiliary/util/u_format.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/gallium/auxiliary/util') diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index fb6ade5c06..6514315ea2 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -338,6 +338,21 @@ util_format_name(enum pipe_format format) return desc->name; } +/** + * Whether this format is plain, see UTIL_FORMAT_LAYOUT_PLAIN for more info. + */ +static INLINE boolean +util_format_is_plain(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + if (!format) { + return FALSE; + } + + return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ? TRUE : FALSE; +} + static INLINE boolean util_format_is_s3tc(enum pipe_format format) { -- cgit v1.2.3 From 5a6b9f3855e7ba179626f7b30467e62fc3ae0ffb Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Mon, 3 May 2010 20:09:14 +0200 Subject: util: add util_format_short_name --- src/gallium/auxiliary/util/u_format.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/gallium/auxiliary/util') diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 6514315ea2..8ba076949b 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -338,6 +338,19 @@ util_format_name(enum pipe_format format) return desc->name; } +static INLINE const char * +util_format_short_name(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (!desc) { + return "???"; + } + + return desc->short_name; +} + /** * Whether this format is plain, see UTIL_FORMAT_LAYOUT_PLAIN for more info. */ -- cgit v1.2.3 From 1fc5a318a64b10567ed6990eb04b2dc3ecb2b347 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 3 May 2010 17:08:17 -0600 Subject: gallium: move framebuffer utility functions into a new file --- src/gallium/auxiliary/Makefile | 1 + src/gallium/auxiliary/SConscript | 1 + src/gallium/auxiliary/util/u_framebuffer.c | 111 ++++++++++++++++++++++++ src/gallium/auxiliary/util/u_framebuffer.h | 49 +++++++++++ src/gallium/auxiliary/util/u_surface.c | 71 --------------- src/gallium/auxiliary/util/u_surface.h | 13 --- src/gallium/drivers/llvmpipe/lp_scene.c | 1 + src/gallium/drivers/llvmpipe/lp_setup.c | 1 + src/gallium/drivers/llvmpipe/lp_state_surface.c | 1 + 9 files changed, 165 insertions(+), 84 deletions(-) create mode 100644 src/gallium/auxiliary/util/u_framebuffer.c create mode 100644 src/gallium/auxiliary/util/u_framebuffer.h (limited to 'src/gallium/auxiliary/util') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index 2daed382cf..e0d9b31354 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -113,6 +113,7 @@ C_SOURCES = \ util/u_format_tests.c \ util/u_format_yuv.c \ util/u_format_zs.c \ + util/u_framebuffer.c \ util/u_gen_mipmap.c \ util/u_half.c \ util/u_handle_table.c \ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index a0673df8a8..29a1bd0ecb 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -162,6 +162,7 @@ source = [ 'util/u_format_tests.c', 'util/u_format_yuv.c', 'util/u_format_zs.c', + 'util/u_framebuffer.c', 'util/u_gen_mipmap.c', 'util/u_half.c', 'util/u_handle_table.c', diff --git a/src/gallium/auxiliary/util/u_framebuffer.c b/src/gallium/auxiliary/util/u_framebuffer.c new file mode 100644 index 0000000000..bdac12dbca --- /dev/null +++ b/src/gallium/auxiliary/util/u_framebuffer.c @@ -0,0 +1,111 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Framebuffer utility functions. + * + * @author Brian Paul + */ + + +#include "pipe/p_screen.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "util/u_memory.h" +#include "util/u_framebuffer.h" + + +/** + * 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; +} diff --git a/src/gallium/auxiliary/util/u_framebuffer.h b/src/gallium/auxiliary/util/u_framebuffer.h new file mode 100644 index 0000000000..adf1254e1b --- /dev/null +++ b/src/gallium/auxiliary/util/u_framebuffer.h @@ -0,0 +1,49 @@ +/************************************************************************** + * + * Copyright 2009-2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef U_FRAMEBUFFER_H +#define U_FRAMEBUFFER_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + + +extern boolean +util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src); + +extern void +util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, + const struct pipe_framebuffer_state *src); + + +extern void +util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb); + + +#endif /* U_FRAMEBUFFER_H */ diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index 42440d0d67..35a9b484fc 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -114,74 +114,3 @@ util_destroy_rgba_surface(struct pipe_resource *texture, pipe_surface_reference(&surface, 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; -} diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h index 119fcd4ce8..a61bb29171 100644 --- a/src/gallium/auxiliary/util/u_surface.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -62,17 +62,4 @@ util_destroy_rgba_surface(struct pipe_resource *texture, struct pipe_surface *surface); -extern boolean -util_framebuffer_state_equal(const struct pipe_framebuffer_state *dst, - const struct pipe_framebuffer_state *src); - -extern void -util_copy_framebuffer_state(struct pipe_framebuffer_state *dst, - const struct pipe_framebuffer_state *src); - - -extern void -util_unreference_framebuffer_state(struct pipe_framebuffer_state *fb); - - #endif /* U_SURFACE_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c index 1482a777ff..887f2dbad9 100644 --- a/src/gallium/drivers/llvmpipe/lp_scene.c +++ b/src/gallium/drivers/llvmpipe/lp_scene.c @@ -25,6 +25,7 @@ * **************************************************************************/ +#include "util/u_framebuffer.h" #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_inlines.h" diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index 2150956008..1a2cd55b16 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -33,6 +33,7 @@ */ #include "pipe/p_defines.h" +#include "util/u_framebuffer.h" #include "util/u_inlines.h" #include "util/u_memory.h" #include "util/u_pack_color.h" diff --git a/src/gallium/drivers/llvmpipe/lp_state_surface.c b/src/gallium/drivers/llvmpipe/lp_state_surface.c index 63b8f27b39..4b135aaf8b 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_surface.c +++ b/src/gallium/drivers/llvmpipe/lp_state_surface.c @@ -30,6 +30,7 @@ #include "pipe/p_state.h" #include "util/u_inlines.h" +#include "util/u_framebuffer.h" #include "util/u_surface.h" #include "lp_context.h" #include "lp_scene.h" -- cgit v1.2.3 From 8b0c217f2bc123bffd25cc4977d6abb1b3fa8186 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 3 May 2010 17:28:32 -0600 Subject: gallium: move surface utility functions into u_surface.c This is a better place than in u_rect.c --- src/gallium/auxiliary/util/u_blitter.c | 1 + src/gallium/auxiliary/util/u_clear.h | 1 + src/gallium/auxiliary/util/u_rect.c | 158 ------------------------ src/gallium/auxiliary/util/u_rect.h | 19 --- src/gallium/auxiliary/util/u_surface.c | 157 ++++++++++++++++++++++- src/gallium/auxiliary/util/u_surface.h | 18 +++ src/gallium/drivers/cell/ppu/cell_surface.c | 2 +- src/gallium/drivers/llvmpipe/lp_surface.c | 1 + src/gallium/drivers/softpipe/sp_surface.c | 2 +- src/gallium/state_trackers/dri/drm/dri1.c | 1 + src/gallium/state_trackers/vega/renderer.c | 1 + src/gallium/state_trackers/xorg/xorg_exa.c | 1 + src/gallium/state_trackers/xorg/xorg_renderer.c | 1 + src/mesa/state_tracker/st_context.c | 1 + 14 files changed, 183 insertions(+), 181 deletions(-) (limited to 'src/gallium/auxiliary/util') diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index 956aedc8a1..1abe31db46 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -47,6 +47,7 @@ #include "util/u_rect.h" #include "util/u_sampler.h" #include "util/u_simple_shaders.h" +#include "util/u_surface.h" #include "util/u_texture.h" #define INVALID_PTR ((void*)~0) diff --git a/src/gallium/auxiliary/util/u_clear.h b/src/gallium/auxiliary/util/u_clear.h index 2c32db6175..40da2d75a7 100644 --- a/src/gallium/auxiliary/util/u_clear.h +++ b/src/gallium/auxiliary/util/u_clear.h @@ -33,6 +33,7 @@ #include "pipe/p_state.h" #include "util/u_pack_color.h" #include "util/u_rect.h" +#include "util/u_surface.h" /** diff --git a/src/gallium/auxiliary/util/u_rect.c b/src/gallium/auxiliary/util/u_rect.c index 098cdfd58b..9bbcf1c8c4 100644 --- a/src/gallium/auxiliary/util/u_rect.c +++ b/src/gallium/auxiliary/util/u_rect.c @@ -30,12 +30,7 @@ */ -#include "pipe/p_defines.h" -#include "pipe/p_format.h" -#include "pipe/p_context.h" -#include "pipe/p_screen.h" #include "util/u_format.h" -#include "util/u_inlines.h" #include "util/u_rect.h" @@ -152,156 +147,3 @@ util_fill_rect(ubyte * dst, break; } } - - - -/** - * Fallback function for pipe->surface_copy(). - * Note: (X,Y)=(0,0) is always the upper-left corner. - * if do_flip, flip the image vertically on its way from src rect to dst rect. - * XXX should probably put this in new u_surface.c file... - */ -void -util_surface_copy(struct pipe_context *pipe, - boolean do_flip, - struct pipe_surface *dst, - unsigned dst_x, unsigned dst_y, - struct pipe_surface *src, - unsigned src_x, unsigned src_y, - unsigned w, unsigned h) -{ - struct pipe_transfer *src_trans, *dst_trans; - void *dst_map; - const void *src_map; - enum pipe_format src_format, dst_format; - - assert(src->texture && dst->texture); - if (!src->texture || !dst->texture) - return; - - src_format = src->texture->format; - dst_format = dst->texture->format; - - src_trans = pipe_get_transfer(pipe, - src->texture, - src->face, - src->level, - src->zslice, - PIPE_TRANSFER_READ, - src_x, src_y, w, h); - - dst_trans = pipe_get_transfer(pipe, - dst->texture, - dst->face, - dst->level, - dst->zslice, - PIPE_TRANSFER_WRITE, - dst_x, dst_y, w, h); - - assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format)); - assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format)); - assert(util_format_get_blockheight(dst_format) == util_format_get_blockheight(src_format)); - - src_map = pipe->transfer_map(pipe, src_trans); - dst_map = pipe->transfer_map(pipe, dst_trans); - - assert(src_map); - assert(dst_map); - - if (src_map && dst_map) { - /* If do_flip, invert src_y position and pass negative src stride */ - util_copy_rect(dst_map, - dst_format, - dst_trans->stride, - 0, 0, - w, h, - src_map, - do_flip ? -(int) src_trans->stride : src_trans->stride, - 0, - do_flip ? h - 1 : 0); - } - - pipe->transfer_unmap(pipe, src_trans); - pipe->transfer_unmap(pipe, dst_trans); - - pipe->transfer_destroy(pipe, src_trans); - pipe->transfer_destroy(pipe, dst_trans); -} - - - -#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8)) - - -/** - * Fallback for pipe->surface_fill() function. - * XXX should probably put this in new u_surface.c file... - */ -void -util_surface_fill(struct pipe_context *pipe, - struct pipe_surface *dst, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, unsigned value) -{ - struct pipe_transfer *dst_trans; - void *dst_map; - - assert(dst->texture); - if (!dst->texture) - return; - dst_trans = pipe_get_transfer(pipe, - dst->texture, - dst->face, - dst->level, - dst->zslice, - PIPE_TRANSFER_WRITE, - dstx, dsty, width, height); - - dst_map = pipe->transfer_map(pipe, dst_trans); - - assert(dst_map); - - if (dst_map) { - assert(dst_trans->stride > 0); - - switch (util_format_get_blocksize(dst->texture->format)) { - case 1: - case 2: - case 4: - util_fill_rect(dst_map, dst->texture->format, - dst_trans->stride, - 0, 0, width, height, value); - break; - case 8: - { - /* expand the 4-byte clear value to an 8-byte value */ - ushort *row = (ushort *) dst_map; - ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff); - ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff); - ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff); - ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff); - unsigned i, j; - val0 = (val0 << 8) | val0; - val1 = (val1 << 8) | val1; - val2 = (val2 << 8) | val2; - val3 = (val3 << 8) | val3; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - row[j*4+0] = val0; - row[j*4+1] = val1; - row[j*4+2] = val2; - row[j*4+3] = val3; - } - row += dst_trans->stride/2; - } - } - break; - default: - assert(0); - break; - } - } - - pipe->transfer_unmap(pipe, dst_trans); - pipe->transfer_destroy(pipe, dst_trans); -} diff --git a/src/gallium/auxiliary/util/u_rect.h b/src/gallium/auxiliary/util/u_rect.h index b44d821904..40d57e662d 100644 --- a/src/gallium/auxiliary/util/u_rect.h +++ b/src/gallium/auxiliary/util/u_rect.h @@ -37,9 +37,6 @@ #include "pipe/p_format.h" -struct pipe_context; -struct pipe_surface; - extern void util_copy_rect(ubyte * dst, enum pipe_format format, @@ -53,20 +50,4 @@ util_fill_rect(ubyte * dst, enum pipe_format format, unsigned width, unsigned height, uint32_t value); -extern void -util_surface_copy(struct pipe_context *pipe, - boolean do_flip, - struct pipe_surface *dst, - unsigned dst_x, unsigned dst_y, - struct pipe_surface *src, - unsigned src_x, unsigned src_y, - unsigned w, unsigned h); - -extern void -util_surface_fill(struct pipe_context *pipe, - struct pipe_surface *dst, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, unsigned value); - - #endif /* U_RECT_H */ diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index 35a9b484fc..b47c92ca28 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -32,12 +32,14 @@ */ +#include "pipe/p_defines.h" #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_inlines.h" #include "util/u_memory.h" +#include "util/u_rect.h" #include "util/u_surface.h" @@ -114,3 +116,154 @@ util_destroy_rgba_surface(struct pipe_resource *texture, pipe_surface_reference(&surface, NULL); pipe_resource_reference(&texture, NULL); } + + + +/** + * Fallback function for pipe->surface_copy(). + * Note: (X,Y)=(0,0) is always the upper-left corner. + * if do_flip, flip the image vertically on its way from src rect to dst rect. + */ +void +util_surface_copy(struct pipe_context *pipe, + boolean do_flip, + struct pipe_surface *dst, + unsigned dst_x, unsigned dst_y, + struct pipe_surface *src, + unsigned src_x, unsigned src_y, + unsigned w, unsigned h) +{ + struct pipe_transfer *src_trans, *dst_trans; + void *dst_map; + const void *src_map; + enum pipe_format src_format, dst_format; + + assert(src->texture && dst->texture); + if (!src->texture || !dst->texture) + return; + + src_format = src->texture->format; + dst_format = dst->texture->format; + + src_trans = pipe_get_transfer(pipe, + src->texture, + src->face, + src->level, + src->zslice, + PIPE_TRANSFER_READ, + src_x, src_y, w, h); + + dst_trans = pipe_get_transfer(pipe, + dst->texture, + dst->face, + dst->level, + dst->zslice, + PIPE_TRANSFER_WRITE, + dst_x, dst_y, w, h); + + assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format)); + assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format)); + assert(util_format_get_blockheight(dst_format) == util_format_get_blockheight(src_format)); + + src_map = pipe->transfer_map(pipe, src_trans); + dst_map = pipe->transfer_map(pipe, dst_trans); + + assert(src_map); + assert(dst_map); + + if (src_map && dst_map) { + /* If do_flip, invert src_y position and pass negative src stride */ + util_copy_rect(dst_map, + dst_format, + dst_trans->stride, + 0, 0, + w, h, + src_map, + do_flip ? -(int) src_trans->stride : src_trans->stride, + 0, + do_flip ? h - 1 : 0); + } + + pipe->transfer_unmap(pipe, src_trans); + pipe->transfer_unmap(pipe, dst_trans); + + pipe->transfer_destroy(pipe, src_trans); + pipe->transfer_destroy(pipe, dst_trans); +} + + + +#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8)) + + +/** + * Fallback for pipe->surface_fill() function. + */ +void +util_surface_fill(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, unsigned value) +{ + struct pipe_transfer *dst_trans; + void *dst_map; + + assert(dst->texture); + if (!dst->texture) + return; + dst_trans = pipe_get_transfer(pipe, + dst->texture, + dst->face, + dst->level, + dst->zslice, + PIPE_TRANSFER_WRITE, + dstx, dsty, width, height); + + dst_map = pipe->transfer_map(pipe, dst_trans); + + assert(dst_map); + + if (dst_map) { + assert(dst_trans->stride > 0); + + switch (util_format_get_blocksize(dst->texture->format)) { + case 1: + case 2: + case 4: + util_fill_rect(dst_map, dst->texture->format, + dst_trans->stride, + 0, 0, width, height, value); + break; + case 8: + { + /* expand the 4-byte clear value to an 8-byte value */ + ushort *row = (ushort *) dst_map; + ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff); + ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff); + ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff); + ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff); + unsigned i, j; + val0 = (val0 << 8) | val0; + val1 = (val1 << 8) | val1; + val2 = (val2 << 8) | val2; + val3 = (val3 << 8) | val3; + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + row[j*4+0] = val0; + row[j*4+1] = val1; + row[j*4+2] = val2; + row[j*4+3] = val3; + } + row += dst_trans->stride/2; + } + } + break; + default: + assert(0); + break; + } + } + + pipe->transfer_unmap(pipe, dst_trans); + pipe->transfer_destroy(pipe, dst_trans); +} diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h index a61bb29171..c43169b527 100644 --- a/src/gallium/auxiliary/util/u_surface.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -62,4 +62,22 @@ util_destroy_rgba_surface(struct pipe_resource *texture, struct pipe_surface *surface); + +extern void +util_surface_copy(struct pipe_context *pipe, + boolean do_flip, + struct pipe_surface *dst, + unsigned dst_x, unsigned dst_y, + struct pipe_surface *src, + unsigned src_x, unsigned src_y, + unsigned w, unsigned h); + +extern void +util_surface_fill(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, unsigned value); + + + #endif /* U_SURFACE_H */ diff --git a/src/gallium/drivers/cell/ppu/cell_surface.c b/src/gallium/drivers/cell/ppu/cell_surface.c index ffb8595d82..6696a4591c 100644 --- a/src/gallium/drivers/cell/ppu/cell_surface.c +++ b/src/gallium/drivers/cell/ppu/cell_surface.c @@ -25,7 +25,7 @@ * **************************************************************************/ -#include "util/u_rect.h" +#include "util/u_surface.h" #include "cell_context.h" #include "cell_surface.h" diff --git a/src/gallium/drivers/llvmpipe/lp_surface.c b/src/gallium/drivers/llvmpipe/lp_surface.c index 8bd83f576f..245171120d 100644 --- a/src/gallium/drivers/llvmpipe/lp_surface.c +++ b/src/gallium/drivers/llvmpipe/lp_surface.c @@ -26,6 +26,7 @@ **************************************************************************/ #include "util/u_rect.h" +#include "util/u_surface.h" #include "lp_context.h" #include "lp_flush.h" #include "lp_limits.h" diff --git a/src/gallium/drivers/softpipe/sp_surface.c b/src/gallium/drivers/softpipe/sp_surface.c index b04c2a63ad..32cab06004 100644 --- a/src/gallium/drivers/softpipe/sp_surface.c +++ b/src/gallium/drivers/softpipe/sp_surface.c @@ -25,7 +25,7 @@ * **************************************************************************/ -#include "util/u_rect.h" +#include "util/u_surface.h" #include "sp_context.h" #include "sp_surface.h" diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c index 23c21ed839..326ff8bcad 100644 --- a/src/gallium/state_trackers/dri/drm/dri1.c +++ b/src/gallium/state_trackers/dri/drm/dri1.c @@ -33,6 +33,7 @@ #include "util/u_memory.h" #include "util/u_rect.h" +#include "util/u_surface.h" #include "util/u_inlines.h" #include "pipe/p_context.h" #include "state_tracker/dri1_api.h" diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c index 48fbc3b330..e6aea482a7 100644 --- a/src/gallium/state_trackers/vega/renderer.c +++ b/src/gallium/state_trackers/vega/renderer.c @@ -40,6 +40,7 @@ #include "util/u_memory.h" #include "util/u_rect.h" #include "util/u_sampler.h" +#include "util/u_surface.h" #include "cso_cache/cso_context.h" diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c index d5a1be8174..65be8c332a 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.c +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -46,6 +46,7 @@ #include "util/u_math.h" #include "util/u_debug.h" #include "util/u_format.h" +#include "util/u_surface.h" #define DEBUG_PRINT 0 #define ROUND_UP_TEXTURES 1 diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.c b/src/gallium/state_trackers/xorg/xorg_renderer.c index 13fa561390..583493116d 100644 --- a/src/gallium/state_trackers/xorg/xorg_renderer.c +++ b/src/gallium/state_trackers/xorg/xorg_renderer.c @@ -9,6 +9,7 @@ #include "util/u_memory.h" #include "util/u_rect.h" #include "util/u_sampler.h" +#include "util/u_surface.h" #include "util/u_inlines.h" diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 2b1174a504..e8a3926e6d 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -64,6 +64,7 @@ #include "pipe/p_context.h" #include "util/u_inlines.h" #include "util/u_rect.h" +#include "util/u_surface.h" #include "draw/draw_context.h" #include "cso_cache/cso_context.h" -- cgit v1.2.3