diff options
Diffstat (limited to 'common')
39 files changed, 206 insertions, 1641 deletions
diff --git a/common/Makefile.am b/common/Makefile.am index f07f9489..4189dc1f 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -74,4 +74,3 @@ EXTRA_DIST = \ quic_rgb_tmpl.c \ quic_tmpl.c \ $(NULL) - diff --git a/common/backtrace.c b/common/backtrace.c index 650dc1d7..c8f46263 100644 --- a/common/backtrace.c +++ b/common/backtrace.c @@ -18,16 +18,20 @@ /* * Taken from xserver os/backtrace.c: - * Copyright 2008 Red Hat, Inc. + * Copyright (C) 2008 Red Hat, Inc. */ -#include "config.h" +#include <config.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> +#include <unistd.h> #include <sys/types.h> +#ifndef __MINGW32__ #include <sys/wait.h> +#endif + #include "spice_common.h" #define GSTACK_PATH "/usr/bin/gstack" @@ -49,6 +53,10 @@ static void spice_backtrace_backtrace(void) } #endif +/* XXX perhaps gstack can be available in windows but pipe/waitpid isn't, + * so until it is ported properly just compile it out, we lose the + * backtrace only. */ +#ifndef __MINGW32__ static int spice_backtrace_gstack(void) { pid_t kidpid; @@ -104,11 +112,22 @@ static int spice_backtrace_gstack(void) } return 0; } +#else +static int spice_backtrace_gstack(void) +{ + /* empty failing implementation */ + return -1; +} +#endif + +void spice_backtrace(void) +{ + int ret = -1; -void spice_backtrace() { if (!access(GSTACK_PATH, X_OK)) { - spice_backtrace_gstack(); - } else { + ret = spice_backtrace_gstack(); + } + if (ret != 0) { spice_backtrace_backtrace(); } } diff --git a/common/backtrace.h b/common/backtrace.h index 8fcbb782..894c0277 100644 --- a/common/backtrace.h +++ b/common/backtrace.h @@ -23,7 +23,7 @@ SPICE_BEGIN_DECLS -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) #define spice_backtrace() #else void spice_backtrace(void); diff --git a/common/bitops.h b/common/bitops.h index 449409bd..bdd862a3 100644 --- a/common/bitops.h +++ b/common/bitops.h @@ -27,7 +27,20 @@ extern "C" { #endif -#if defined(WIN32) && !defined(_WIN64) +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) +static inline int spice_bit_find_msb(unsigned int val) +{ + int ret; + + asm ("bsrl %1,%0\n\t" + "jnz 1f\n\t" + "movl $-1,%0\n" + "1:" + : "=r"(ret) : "r"(val)); + return ret + 1; +} + +#elif defined(WIN32) && !defined(_WIN64) static INLINE int spice_bit_find_msb(uint32_t val) { uint32_t r; @@ -42,19 +55,6 @@ found: return r + 1; } -#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) -static inline int spice_bit_find_msb(unsigned int val) -{ - int ret; - - asm ("bsrl %1,%0\n\t" - "jnz 1f\n\t" - "movl $-1,%0\n" - "1:" - : "=r"(ret) : "r"(val)); - return ret + 1; -} - #else static INLINE int spice_bit_find_msb(unsigned int val) { diff --git a/common/canvas_base.c b/common/canvas_base.c index d11c8ec0..c4203dd7 100644 --- a/common/canvas_base.c +++ b/common/canvas_base.c @@ -619,7 +619,7 @@ static pixman_image_t *canvas_get_jpeg_alpha(CanvasBase *canvas, decomp_alpha_buf = dest; } lz_decode(lz_data->lz, LZ_IMAGE_TYPE_XXXA, decomp_alpha_buf); - + if (invers) { uint8_t *end = dest + height * stride; for (; dest != end; dest += stride) { @@ -749,9 +749,7 @@ static pixman_image_t *canvas_get_lz(CanvasBase *canvas, SpiceImage *image, int int free_palette; if (setjmp(lz_data->jmp_env)) { - if (decomp_buf) { - free(decomp_buf); - } + free(decomp_buf); CANVAS_ERROR("lz error, %s", lz_data->message_buf); } @@ -3134,9 +3132,7 @@ static void canvas_draw_stroke(SpiceCanvas *spice_canvas, SpiceRect *bbox, stroke_lines_draw(&lines, (lineGC *)&gc, dashed); - if (gc.base.dash) { - free(gc.base.dash); - } + free(gc.base.dash); stroke_lines_free(&lines); if (!gc.solid && gc.tile && !surface_canvas) { diff --git a/common/canvas_base.h b/common/canvas_base.h index 7a69def2..861171ec 100644 --- a/common/canvas_base.h +++ b/common/canvas_base.h @@ -69,7 +69,7 @@ struct _SpiceImageCache { typedef struct { SpiceCanvas *(*get)(SpiceImageSurfaces *surfaces, - uint32_t surface_id); + uint32_t surface_id); } SpiceImageSurfacesOps; struct _SpiceImageSurfaces { @@ -177,10 +177,10 @@ typedef struct { pixman_image_t *tile, int offset_x, int offset_y); void (*fill_tiled_rects_from_surface)(SpiceCanvas *canvas, - pixman_box32_t *rects, - int n_rects, - SpiceCanvas *tile, - int offset_x, int offset_y); + pixman_box32_t *rects, + int n_rects, + SpiceCanvas *tile, + int offset_x, int offset_y); void (*fill_tiled_rects_rop)(SpiceCanvas *canvas, pixman_box32_t *rects, int n_rects, @@ -188,29 +188,29 @@ typedef struct { int offset_x, int offset_y, SpiceROP rop); void (*fill_tiled_rects_rop_from_surface)(SpiceCanvas *canvas, - pixman_box32_t *rects, - int n_rects, - SpiceCanvas *tile, - int offset_x, int offset_y, - SpiceROP rop); + pixman_box32_t *rects, + int n_rects, + SpiceCanvas *tile, + int offset_x, int offset_y, + SpiceROP rop); void (*blit_image)(SpiceCanvas *canvas, pixman_region32_t *region, pixman_image_t *src_image, int offset_x, int offset_y); void (*blit_image_from_surface)(SpiceCanvas *canvas, - pixman_region32_t *region, - SpiceCanvas *src_image, - int offset_x, int offset_y); + pixman_region32_t *region, + SpiceCanvas *src_image, + int offset_x, int offset_y); void (*blit_image_rop)(SpiceCanvas *canvas, pixman_region32_t *region, pixman_image_t *src_image, int offset_x, int offset_y, SpiceROP rop); void (*blit_image_rop_from_surface)(SpiceCanvas *canvas, - pixman_region32_t *region, - SpiceCanvas *src_image, - int offset_x, int offset_y, - SpiceROP rop); + pixman_region32_t *region, + SpiceCanvas *src_image, + int offset_x, int offset_y, + SpiceROP rop); void (*scale_image)(SpiceCanvas *canvas, pixman_region32_t *region, pixman_image_t *src_image, @@ -220,13 +220,13 @@ typedef struct { int dest_width, int dest_height, int scale_mode); void (*scale_image_from_surface)(SpiceCanvas *canvas, - pixman_region32_t *region, - SpiceCanvas *src_image, - int src_x, int src_y, - int src_width, int src_height, - int dest_x, int dest_y, - int dest_width, int dest_height, - int scale_mode); + pixman_region32_t *region, + SpiceCanvas *src_image, + int src_x, int src_y, + int src_width, int src_height, + int dest_x, int dest_y, + int dest_width, int dest_height, + int scale_mode); void (*scale_image_rop)(SpiceCanvas *canvas, pixman_region32_t *region, pixman_image_t *src_image, @@ -236,13 +236,13 @@ typedef struct { int dest_width, int dest_height, int scale_mode, SpiceROP rop); void (*scale_image_rop_from_surface)(SpiceCanvas *canvas, - pixman_region32_t *region, - SpiceCanvas *src_image, - int src_x, int src_y, - int src_width, int src_height, - int dest_x, int dest_y, - int dest_width, int dest_height, - int scale_mode, SpiceROP rop); + pixman_region32_t *region, + SpiceCanvas *src_image, + int src_x, int src_y, + int src_width, int src_height, + int dest_x, int dest_y, + int dest_width, int dest_height, + int scale_mode, SpiceROP rop); void (*blend_image)(SpiceCanvas *canvas, pixman_region32_t *region, int dest_has_alpha, @@ -252,14 +252,14 @@ typedef struct { int width, int height, int overall_alpha); void (*blend_image_from_surface)(SpiceCanvas *canvas, - pixman_region32_t *region, + pixman_region32_t *region, int dest_has_alpha, - SpiceCanvas *src_image, + SpiceCanvas *src_image, int src_has_alpha, - int src_x, int src_y, - int dest_x, int dest_y, - int width, int height, - int overall_alpha); + int src_x, int src_y, + int dest_x, int dest_y, + int width, int height, + int overall_alpha); void (*blend_scale_image)(SpiceCanvas *canvas, pixman_region32_t *region, int dest_has_alpha, @@ -271,26 +271,26 @@ typedef struct { int scale_mode, int overall_alpha); void (*blend_scale_image_from_surface)(SpiceCanvas *canvas, - pixman_region32_t *region, + pixman_region32_t *region, int dest_has_alpha, - SpiceCanvas *src_image, + SpiceCanvas *src_image, int src_has_alpha, - int src_x, int src_y, - int src_width, int src_height, - int dest_x, int dest_y, - int dest_width, int dest_height, - int scale_mode, - int overall_alpha); + int src_x, int src_y, + int src_width, int src_height, + int dest_x, int dest_y, + int dest_width, int dest_height, + int scale_mode, + int overall_alpha); void (*colorkey_image)(SpiceCanvas *canvas, pixman_region32_t *region, pixman_image_t *src_image, int offset_x, int offset_y, uint32_t transparent_color); void (*colorkey_image_from_surface)(SpiceCanvas *canvas, - pixman_region32_t *region, - SpiceCanvas *src_image, - int offset_x, int offset_y, - uint32_t transparent_color); + pixman_region32_t *region, + SpiceCanvas *src_image, + int offset_x, int offset_y, + uint32_t transparent_color); void (*colorkey_scale_image)(SpiceCanvas *canvas, pixman_region32_t *region, pixman_image_t *src_image, @@ -300,13 +300,13 @@ typedef struct { int dest_width, int dest_height, uint32_t transparent_color); void (*colorkey_scale_image_from_surface)(SpiceCanvas *canvas, - pixman_region32_t *region, - SpiceCanvas *src_image, - int src_x, int src_y, - int src_width, int src_height, - int dest_x, int dest_y, - int dest_width, int dest_height, - uint32_t transparent_color); + pixman_region32_t *region, + SpiceCanvas *src_image, + int src_x, int src_y, + int src_width, int src_height, + int dest_x, int dest_y, + int dest_width, int dest_height, + uint32_t transparent_color); void (*copy_region)(SpiceCanvas *canvas, pixman_region32_t *dest_region, int dx, int dy); diff --git a/common/canvas_utils.c b/common/canvas_utils.c index 55b71599..6632942e 100644 --- a/common/canvas_utils.c +++ b/common/canvas_utils.c @@ -51,9 +51,7 @@ static void release_data(pixman_image_t *image, void *release_data) gdi_handlers--; } #endif - if (data->data) { - free(data->data); - } + free(data->data); free(data); } @@ -299,4 +297,3 @@ pixman_image_t *alloc_lz_image_surface(LzDecodeUsrData *canvas_data, canvas_data->out_surface = surface; return surface; } - diff --git a/common/gdi_canvas.c b/common/gdi_canvas.c index f67aadf5..d3e9c7ff 100644 --- a/common/gdi_canvas.c +++ b/common/gdi_canvas.c @@ -16,6 +16,9 @@ License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H +#ifdef __MINGW32__ +#undef HAVE_STDLIB_H +#endif #include <config.h> #endif @@ -458,9 +461,6 @@ static void copy_bitmap_alpha(const uint8_t *src_alpha, int height, int width, i uint8_t i_offset; int i_count = 0; int i = 0; - int width_div_stride; - - width_div_stride = width / src_stride; if (alpha_bits_size == 1) { i_offset = 1; @@ -580,15 +580,15 @@ static uint8_t *create_bitmap(HBITMAP *bitmap, HBITMAP *prev_bitmap, HDC *dc, } static uint8_t *create_bitmap_from_pixman(HBITMAP *bitmap, HBITMAP *prev_bitmap, HDC *dc, - pixman_image_t *surface, int rotate) + pixman_image_t *surface, int rotate) { return create_bitmap(bitmap, prev_bitmap, dc, (uint8_t*)pixman_image_get_data(surface), - pixman_image_get_width(surface), - pixman_image_get_height(surface), - pixman_image_get_stride(surface), - spice_pixman_image_get_bpp(surface), - rotate); + pixman_image_get_width(surface), + pixman_image_get_height(surface), + pixman_image_get_stride(surface), + spice_pixman_image_get_bpp(surface), + rotate); } @@ -641,7 +641,7 @@ static HBRUSH get_brush(GdiCanvas *canvas, SpiceBrush *brush, RecurciveMutex **b CANVAS_ERROR("CreateSolidBrush failed"); } return hbrush; - case SPICE_BRUSH_TYPE_PATTERN: { + case SPICE_BRUSH_TYPE_PATTERN: { GdiCanvas *gdi_surface = NULL; HBRUSH hbrush; pixman_image_t *surface = NULL; @@ -798,23 +798,23 @@ static struct BitmapData get_mask_bitmap(struct GdiCanvas *canvas, struct SpiceQ gdi_surface = (GdiCanvas *)canvas_get_surface_mask(&canvas->base, mask->bitmap); if (gdi_surface) { - HBITMAP _bitmap; + HBITMAP _bitmap; - _bitmap = (HBITMAP)GetCurrentObject(gdi_surface->dc, OBJ_BITMAP); - if (!_bitmap) { - CANVAS_ERROR ("GetCurrentObject failed"); - } - bitmap.dc = gdi_surface->dc; - bitmap.hbitmap = _bitmap; - bitmap.prev_hbitmap = (HBITMAP)0; - bitmap.cache = 0; - bitmap.from_surface = 1; + _bitmap = (HBITMAP)GetCurrentObject(gdi_surface->dc, OBJ_BITMAP); + if (!_bitmap) { + CANVAS_ERROR ("GetCurrentObject failed"); + } + bitmap.dc = gdi_surface->dc; + bitmap.hbitmap = _bitmap; + bitmap.prev_hbitmap = (HBITMAP)0; + bitmap.cache = 0; + bitmap.from_surface = 1; } else { - + if (!(surface = canvas_get_mask(&canvas->base, mask, NULL))) { return bitmap; } - + pixman_data = (PixmanData *)pixman_image_get_destroy_data (surface); if (pixman_data && (WaitForSingleObject(pixman_data->mutex, INFINITE) != WAIT_FAILED)) { bitmap.dc = create_compatible_dc(); @@ -1060,16 +1060,16 @@ static void gdi_canvas_draw_copy(SpiceCanvas *spice_canvas, SpiceRect *bbox, Spi } else { surface = canvas_get_image(&canvas->base, copy->src_bitmap, FALSE); pixman_data = (PixmanData *)pixman_image_get_destroy_data(surface); - + RecurciveLock lock(*canvas->lock); bitmapmask = get_mask_bitmap(canvas, ©->mask); set_scale_mode(canvas, copy->scale_mode); set_clip(canvas, clip); - + if (pixman_data && (WaitForSingleObject(pixman_data->mutex, INFINITE) != WAIT_FAILED)) { HDC dc; HBITMAP prev_bitmap; - + dc = create_compatible_dc(); prev_bitmap = (HBITMAP)SelectObject(dc, pixman_data->bitmap); gdi_draw_bitmap_redrop(canvas->dc, ©->src_area, bbox, dc, @@ -1083,7 +1083,6 @@ static void gdi_canvas_draw_copy(SpiceCanvas *spice_canvas, SpiceRect *bbox, Spi } pixman_image_unref(surface); - } free_mask(&bitmapmask); } @@ -1149,10 +1148,10 @@ static void gdi_canvas_put_image(SpiceCanvas *spice_canvas, HDC dc, const SpiceR gdi_draw_bitmap_redrop(canvas->dc, &src, dest, dc, NULL, SPICE_ROPD_OP_PUT, 0); } else { - pixman_image_t *image = pixman_image_create_bits(PIXMAN_a8r8g8b8, src_width, src_height, - (uint32_t *)src_data, src_stride); + pixman_image_t *image = pixman_image_create_bits(PIXMAN_a8r8g8b8, src_width, src_height, + (uint32_t *)src_data, src_stride); gdi_draw_image(canvas->dc, &src, dest, image, NULL, SPICE_ROPD_OP_PUT, 0); - pixman_image_unref(image); + pixman_image_unref(image); } } @@ -1166,7 +1165,7 @@ static void gdi_draw_bitmap_transparent(GdiCanvas *canvas, HDC dest_dc, const Sp } static void gdi_draw_image_transparent(GdiCanvas *canvas, HDC dest_dc, const SpiceRect *src, - const SpiceRect *dest, pixman_image_t *image, + const SpiceRect *dest, pixman_image_t *image, uint32_t color, int rotate) { HDC dc; @@ -1203,12 +1202,12 @@ static void gdi_canvas_draw_transparent(SpiceCanvas *spice_canvas, SpiceRect *bb if (pixman_data && (WaitForSingleObject(pixman_data->mutex, INFINITE) != WAIT_FAILED)) { HDC dc; HBITMAP prev_bitmap; - + dc = create_compatible_dc(); prev_bitmap = (HBITMAP)SelectObject(dc, pixman_data->bitmap); gdi_draw_bitmap_transparent(canvas, canvas->dc, &transparent->src_area, bbox, dc, transparent->true_color); - + SelectObject(dc, prev_bitmap); DeleteObject(dc); ReleaseMutex(pixman_data->mutex); @@ -1216,7 +1215,7 @@ static void gdi_canvas_draw_transparent(SpiceCanvas *spice_canvas, SpiceRect *bb gdi_draw_image_transparent(canvas, canvas->dc, &transparent->src_area, bbox, surface, transparent->true_color, 0); } - + pixman_image_unref(surface); } } @@ -1244,7 +1243,7 @@ static void gdi_draw_bitmap_alpha(HDC dest_dc, const SpiceRect *src, const Spice } static void gdi_draw_image_alpha(HDC dest_dc, const SpiceRect *src, const SpiceRect *dest, - pixman_image_t *image, uint8_t alpha, + pixman_image_t *image, uint8_t alpha, int rotate, int use_bitmap_alpha) { HDC dc; @@ -1278,13 +1277,13 @@ static void gdi_canvas_draw_alpha_blend(SpiceCanvas *spice_canvas, SpiceRect *bb surface = canvas_get_image(&canvas->base, alpha_blend->src_bitmap, TRUE); use_bitmap_alpha = pixman_image_get_depth(surface) == 32; pixman_data = (PixmanData *)pixman_image_get_destroy_data(surface); - + RecurciveLock lock(*canvas->lock); set_clip(canvas, clip); if (pixman_data && (WaitForSingleObject(pixman_data->mutex, INFINITE) != WAIT_FAILED)) { HDC dc; HBITMAP prev_bitmap; - + dc = create_compatible_dc(); prev_bitmap = (HBITMAP)SelectObject(dc, pixman_data->bitmap); gdi_draw_bitmap_alpha(canvas->dc, &alpha_blend->src_area, bbox, dc, alpha_blend->alpha, @@ -1296,7 +1295,7 @@ static void gdi_canvas_draw_alpha_blend(SpiceCanvas *spice_canvas, SpiceRect *bb gdi_draw_image_alpha(canvas->dc, &alpha_blend->src_area, bbox, surface, alpha_blend->alpha, 0, use_bitmap_alpha); } - + pixman_image_unref(surface); } } @@ -1334,18 +1333,18 @@ static void gdi_canvas_draw_opaque(SpiceCanvas *spice_canvas, SpiceRect *bbox, S } else { surface = canvas_get_image(&canvas->base, opaque->src_bitmap, FALSE); pixman_data = (PixmanData *)pixman_image_get_destroy_data(surface); - + RecurciveLock lock(*canvas->lock); bitmapmask = get_mask_bitmap(canvas, &opaque->mask); hbrush = get_brush(canvas, &opaque->brush, &brush_lock); set_scale_mode(canvas, opaque->scale_mode); set_clip(canvas, clip); prev_hbrush = set_brush(canvas->dc, hbrush, &opaque->brush); - + if (pixman_data && (WaitForSingleObject(pixman_data->mutex, INFINITE) != WAIT_FAILED)) { HDC dc; HBITMAP prev_bitmap; - + dc = create_compatible_dc(); prev_bitmap = (HBITMAP)SelectObject(dc, pixman_data->bitmap); if (brush_lock) { @@ -1392,16 +1391,16 @@ static void gdi_canvas_draw_blend(SpiceCanvas *spice_canvas, SpiceRect *bbox, Sp } else { surface = canvas_get_image(&canvas->base, blend->src_bitmap, FALSE); pixman_data = (PixmanData *)pixman_image_get_destroy_data(surface); - + RecurciveLock lock(*canvas->lock); bitmapmask = get_mask_bitmap(canvas, &blend->mask); set_scale_mode(canvas, blend->scale_mode); set_clip(canvas, clip); - + if (pixman_data && (WaitForSingleObject(pixman_data->mutex, INFINITE) != WAIT_FAILED)) { HDC dc; HBITMAP prev_bitmap; - + dc = create_compatible_dc(); prev_bitmap = (HBITMAP)SelectObject(dc, pixman_data->bitmap); gdi_draw_bitmap_redrop(canvas->dc, &blend->src_area, bbox, dc, @@ -1411,7 +1410,7 @@ static void gdi_canvas_draw_blend(SpiceCanvas *spice_canvas, SpiceRect *bbox, Sp ReleaseMutex(pixman_data->mutex); } else { gdi_draw_image(canvas->dc, &blend->src_area, bbox, surface, - &bitmapmask, blend->rop_descriptor, 0); + &bitmapmask, blend->rop_descriptor, 0); } pixman_image_unref(surface); @@ -1497,11 +1496,11 @@ static void gdi_canvas_draw_rop3(SpiceCanvas *spice_canvas, SpiceRect *bbox, Spi set_scale_mode(canvas, rop3->scale_mode); set_clip(canvas, clip); prev_hbrush = set_brush(canvas->dc, hbrush, &rop3->brush); - + if (pixman_data && (WaitForSingleObject(pixman_data->mutex, INFINITE) != WAIT_FAILED)) { HDC dc; HBITMAP prev_bitmap; - + dc = create_compatible_dc(); prev_bitmap = (HBITMAP)SelectObject(dc, pixman_data->bitmap); if (brush_lock) { @@ -1599,7 +1598,6 @@ static void gdi_canvas_draw_text(SpiceCanvas *spice_canvas, SpiceRect *bbox, Spi static uint32_t *gdi_get_userstyle(GdiCanvas *canvas, uint8_t nseg, SPICE_FIXED28_4* style, int start_is_gap) { - double offset = 0; uint32_t *local_style; int i; @@ -1609,7 +1607,6 @@ static uint32_t *gdi_get_userstyle(GdiCanvas *canvas, uint8_t nseg, SPICE_FIXED2 local_style = spice_new(uint32_t , nseg); if (start_is_gap) { - offset = (uint32_t)fix_to_double(*style); local_style[nseg - 1] = (uint32_t)fix_to_double(*style); style++; @@ -1775,9 +1772,7 @@ static void gdi_canvas_draw_stroke(SpiceCanvas *spice_canvas, SpiceRect *bbox, S } #endif - if (user_style) { - free(user_style); - } + free(user_style); } static void gdi_canvas_clear(SpiceCanvas *spice_canvas) @@ -1812,24 +1807,23 @@ SpiceCanvas *gdi_canvas_create(int width, int height, ) { GdiCanvas *canvas; - int init_ok; if (need_init) { return NULL; } canvas = spice_new0(GdiCanvas, 1); - init_ok = canvas_base_init(&canvas->base, &gdi_canvas_ops, - width, height, format + canvas_base_init(&canvas->base, &gdi_canvas_ops, + width, height, format, #ifdef SW_CANVAS_CACHE - ,bits_cache - ,palette_cache + bits_cache, + palette_cache, #elif defined(SW_CANVAS_IMAGE_CACHE) - , bits_cache + bits_cache, #endif - , surfaces - , glz_decoder - , jpeg_decoder - , zlib_decoder); + surfaces, + glz_decoder, + jpeg_decoder, + zlib_decoder); canvas->dc = dc; canvas->lock = lock; return (SpiceCanvas *)canvas; @@ -1862,4 +1856,3 @@ void gdi_canvas_init(void) //unsafe global function rop3_init(); } - diff --git a/common/gdi_canvas.h b/common/gdi_canvas.h index af5b2296..f92c042b 100644 --- a/common/gdi_canvas.h +++ b/common/gdi_canvas.h @@ -37,7 +37,7 @@ SpiceCanvas *gdi_canvas_create(int width, int height, HDC dc, class RecurciveMutex *lock, uint32_t format, SpiceImageCache *bits_cache, SpicePaletteCache *palette_cache, - SpiceImageSurfaces *surfaces, + SpiceImageSurfaces *surfaces, SpiceGlzDecoder *glz_decoder, SpiceJpegDecoder *jpeg_decoder, SpiceZlibDecoder *zlib_decoder); diff --git a/common/gl_canvas.c b/common/gl_canvas.c index a04740b3..ffc6b52d 100644 --- a/common/gl_canvas.c +++ b/common/gl_canvas.c @@ -870,9 +870,7 @@ static void gl_canvas_destroy(SpiceCanvas *spice_canvas) } canvas_base_destroy(&canvas->base); glc_destroy(canvas->glc, canvas->textures_lost); - if (canvas->private_data) { - free(canvas->private_data); - } + free(canvas->private_data); free(canvas); } diff --git a/common/gl_canvas.h b/common/gl_canvas.h index 40b67139..400bedb2 100644 --- a/common/gl_canvas.h +++ b/common/gl_canvas.h @@ -38,7 +38,7 @@ SpiceCanvas *gl_canvas_create(int width, int height, uint32_t format #elif defined(SW_CANVAS_IMAGE_CACHE) , SpiceImageCache *bits_cache #endif - , SpiceImageSurfaces *surfaces + , SpiceImageSurfaces *surfaces , SpiceGlzDecoder *glz_decoder , SpiceJpegDecoder *jpeg_decoder , SpiceZlibDecoder *zlib_decoder diff --git a/common/glc.c b/common/glc.c index 1c81dd86..1414bcff 100644 --- a/common/glc.c +++ b/common/glc.c @@ -1511,4 +1511,3 @@ void glc_destroy(GLCCtx glc, int textures_lost) 8. support more image formats 9. use GLCImage in mask ops? */ - diff --git a/common/glc.c.save b/common/glc.c.save deleted file mode 100644 index 19581105..00000000 --- a/common/glc.c.save +++ /dev/null @@ -1,1413 +0,0 @@ -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - -#include <GL/gl.h> -#include <GL/glu.h> - -#ifdef WIN32 -#include "glext.h" -#include "wglext.h" -#endif - -#include "glc.h" - -#define TRUE 1 -#define FALSE 0 - -#define ASSERT(x) if (!(x)) {printf("%s: assert failed %s\n", __FUNCTION__, #x); for (;;);} - -#define GLC_ERROR_TETS { \ - GLenum gl_err; glFlush(); \ - if ((gl_err = glGetError()) != GL_NO_ERROR) { \ - printf("%s[%d]: opengl error: %s\n", __FUNCTION__, __LINE__, gluErrorString(gl_err)); \ - for(;;); \ - } \ -} - -#define WARN_ONCE(x) { \ - static int warn = TRUE; \ - if (warn) { \ - printf x; \ - warn = FALSE; \ - } \ -} - -#define TESS_VERTEX_ALLOC_BUNCH 20 - -typedef struct InternaCtx InternaCtx; -typedef struct InternalPat { - InternaCtx *owner; - int refs; - GLuint texture; - int x_orign; - int y_orign; - int width; - int height; -} InternalPat; - -typedef struct Pathpath { - int start_point; - int num_segments; -} Path; - -enum { - GLC_PATH_SEG_LINES, - GLC_PATH_SEG_BEIZER, -}; - -//todo: flatten cache -typedef struct PathSegment { - int type; - int count; -} PathSegment; - -typedef struct PathPoint { - double x; - double y; - double z; -} PathPoint; - -typedef GLdouble Vertex[3]; - -typedef struct InternalPath { - InternaCtx *owner; - - Path *paths; - int paths_size; - int paths_pos; - - PathSegment *segments; - int segments_size; - int segments_pos; - - PathPoint *points; - int points_size; - int points_pos; - - Path *current_path; - PathSegment *current_segment; - -} InternalPath; - -typedef struct TassVertex TassVertex; -struct TassVertex { - PathPoint point; - TassVertex *list_link; - TassVertex *next; -}; - -typedef struct TassVertexBuf TassVertexBuf; -struct TassVertexBuf { - TassVertexBuf *next; - TassVertex vertexs[0]; -}; - -struct InternaCtx { - int draw_mode; - int stencil_refs; - int stencil_mask; - int width; - int height; - GLfloat line_width; - InternalPat *pat; - int max_texture_size; - GLUtesselator* tesselator; - TassVertex *free_tess_vertex; - TassVertex *used_tess_vertex; - TassVertexBuf *vertex_bufs; -#ifdef WIN32 - PFNGLBLENDEQUATIONPROC glBlendEquation; -#endif -}; - -#define Y(y) -(y) -#define VERTEX2(x, y) glVertex2d(x, Y(y)) - -static void fill_rect(InternaCtx *ctx, void *rect); -static void fill_path(InternaCtx *ctx, void *path); -static void fill_mask(InternaCtx *ctx, int x_dest, int y_dest, int width, int height, int stride, - const uint8_t *bitmap); -static void set_pat(InternaCtx *ctx, InternalPat *pat); - -static inline void *zmalloc(size_t size) -{ - return calloc(1, size); -} - -static inline void set_raster_pos(InternaCtx *ctx, int x, int y) -{ - if (x >= 0 && y >= 0 && x < ctx->width && y < ctx->height) { - glRasterPos2i(x, Y(y)); - return; - } - glRasterPos2i(0, 0); - glBitmap(0, 0, 0, 0, (GLfloat)x, (GLfloat)Y(y), NULL); -} - -static TassVertex *alloc_tess_vertex(InternaCtx *ctx) -{ - TassVertex *vertex; - - if (!ctx->free_tess_vertex) { - TassVertexBuf *buf; - int i; - - if (!(buf = (TassVertexBuf *)malloc(sizeof(TassVertexBuf) + - sizeof(TassVertex) * TESS_VERTEX_ALLOC_BUNCH))) { - //warn - return NULL; - } - buf->next = ctx->vertex_bufs; - ctx->vertex_bufs = buf; - for (i = 0; i < TESS_VERTEX_ALLOC_BUNCH; i++) { - buf->vertexs[i].point.z = 0; - buf->vertexs[i].next = ctx->free_tess_vertex; - ctx->free_tess_vertex = &buf->vertexs[i]; - } - } - - vertex = ctx->free_tess_vertex; - ctx->free_tess_vertex = vertex->next; - vertex->next = ctx->used_tess_vertex; - ctx->used_tess_vertex = vertex; - return vertex; -} - -static void reset_tass_vertex(InternaCtx *ctx) -{ - TassVertex *vertex; - while ((vertex = ctx->used_tess_vertex)) { - ctx->used_tess_vertex = vertex->next; - vertex->next = ctx->free_tess_vertex; - ctx->free_tess_vertex = vertex; - } -} - -static void free_tass_vertex_bufs(InternaCtx *ctx) -{ - TassVertexBuf *buf; - - ctx->used_tess_vertex = NULL; - ctx->free_tess_vertex = NULL; - while ((buf = ctx->vertex_bufs)) { - ctx->vertex_bufs = buf->next; - free(buf); - } -} - -//naiev bezier flattener -static TassVertex *bezier_flattener(InternaCtx *ctx, PathPoint *points) -{ - double ax, bx, cx; - double ay, by, cy; - const int num_points = 30; - double dt; - int i; - - TassVertex *vertex_list = NULL; - TassVertex *curr_vertex; - - for (i = 0; i < num_points - 2; i++) { - TassVertex *vertex; - - if (!(vertex = alloc_tess_vertex(ctx))) { - //warn - return NULL; - } - vertex->list_link = vertex_list; - vertex_list = vertex; - } - - curr_vertex = vertex_list; - - cx = 3.0 * (points[1].x - points[0].x); - bx = 3.0 * (points[2].x - points[1].x) - cx; - ax = points[3].x - points[0].x - cx - bx; - - cy = 3.0 * (points[1].y - points[0].y); - by = 3.0 * (points[2].y - points[1].y) - cy; - ay = points[3].y - points[0].y - cy - by; - - dt = 1.0 / ( num_points - 1 ); - - for( i = 1; i < num_points - 1; i++, curr_vertex = curr_vertex->list_link) { - double tSquared, tCubed; - double t; - t = i * dt; - - tSquared = t * t; - tCubed = tSquared * t; - - curr_vertex->point.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + points[0].x; - curr_vertex->point.y = (ay * tCubed) + (by * tSquared) + (cy * t) + points[0].y; - } - - return vertex_list; -} - -#define MORE_X(path, Type, name) {\ - Type *name;\ - \ - if (!(name = (Type *)zmalloc(sizeof(*name) * path->name##_size * 2))) {\ - return FALSE;\ - }\ - memcpy(name, path->name, sizeof(*name) * path->name##_size);\ - free(path->name);\ - path->name = name;\ - path->name##_size *= 2;\ - return TRUE;\ -} - -static int more_points(InternalPath *path) -{ - MORE_X(path, PathPoint, points); -} - -static int more_segments(InternalPath *path) -{ - MORE_X(path, PathSegment, segments); -} - -static int more_paths(InternalPath *path) -{ - MORE_X(path, Path, paths); -} - -static inline void put_point(InternalPath *path, double x, double y) -{ - path->points[path->points_pos].x = x; - path->points[path->points_pos++].y = Y(y + 0.5); - path->points[path->points_pos].z = 0; -} - -void glc_path_move_to(GLCPath path, double x, double y) -{ - InternalPath *internal = (InternalPath *)path; - - ASSERT(internal); - - if (internal->current_segment) { - internal->current_segment = NULL; - internal->current_path = NULL; - if (internal->points_pos == internal->points_size && !more_points(internal)) { - //warn - return; - } - internal->points_pos++; - } - internal->points[internal->points_pos - 1].x = x; - internal->points[internal->points_pos - 1].y = Y(y + 0.5); - internal->points[internal->points_pos - 1].z = 0; -} - -static int add_segment_common(InternalPath *internal, int type, int num_points) -{ - if (internal->points_size - internal->points_pos < num_points && !more_points(internal)) { - //warn - return FALSE; - } - - if (internal->current_segment) { - if (internal->current_segment->type == type) { - internal->current_segment->count++; - return TRUE; - } - if (internal->segments_pos == internal->segments_size && !more_segments(internal)) { - //warn - return FALSE; - } - internal->current_segment = &internal->segments[internal->segments_pos++]; - internal->current_segment->type = type; - internal->current_segment->count = 1; - internal->current_path->num_segments++; - return TRUE; - } - - if (internal->paths_pos == internal->paths_size && !more_paths(internal)) { - //warn - return FALSE; - } - - if (internal->segments_pos == internal->segments_size && !more_segments(internal)) { - //warn - return FALSE; - } - - internal->current_path = &internal->paths[internal->paths_pos++]; - internal->current_path->start_point = internal->points_pos - 1; - internal->current_path->num_segments = 1; - internal->current_segment = &internal->segments[internal->segments_pos++]; - internal->current_segment->type = type; - internal->current_segment->count = 1; - return TRUE; -} - -void glc_path_line_to(GLCPath path, double x, double y) -{ - InternalPath *internal = (InternalPath *)path; - - ASSERT(internal); - - if (!add_segment_common(internal, GLC_PATH_SEG_LINES, 1)) { - return; - } - put_point(internal, x, y); -} - -void glc_path_curve_to(GLCPath path, double p1_x, double p1_y, double p2_x, double p2_y, - double p3_x, double p3_y) -{ - InternalPath *internal = (InternalPath *)path; - - ASSERT(internal); - - if (!add_segment_common(internal, GLC_PATH_SEG_BEIZER, 3)) { - return; - } - put_point(internal, p1_x, p1_y); - put_point(internal, p2_x, p2_y); - put_point(internal, p3_x, p3_y); -} - -void glc_path_close(GLCPath path) -{ - InternalPath *internal = (InternalPath *)path; - - ASSERT(internal); - if (!internal->current_path) { - return; - } - PathPoint *end_point = &internal->points[internal->current_path->start_point]; - glc_path_line_to(path, end_point->x, Y(end_point->y)); - glc_path_move_to(path, end_point->x, Y(end_point->y)); -} - -void glc_path_cleare(GLCPath path) -{ - InternalPath *internal = (InternalPath *)path; - - ASSERT(internal); - internal->paths_pos = internal->segments_pos = 0; - internal->current_segment = NULL; - internal->current_path = NULL; - - internal->points[0].x = 0; - internal->points[0].y = 0; - internal->points_pos = 1; -} - -GLCPath glc_path_create(GLCCtx glc) -{ - InternaCtx *ctx = (InternaCtx *)glc; - InternalPath *path; - - ASSERT(ctx); - if (!(path = (InternalPath *)zmalloc(sizeof(*path)))) { - return NULL; - } - - path->paths = (Path *)malloc(sizeof(*path->paths) * (path->paths_size = 2)); - if (!path->paths) { - goto error_1; - } - - path->segments = (PathSegment *)malloc(sizeof(*path->segments) * (path->segments_size = 4)); - if (!path->segments) { - goto error_2; - } - - path->points = (PathPoint *)malloc(sizeof(*path->points) * (path->points_size = 20)); - if (!path->points) { - goto error_3; - } - - path->owner = ctx; - path->points_pos = 1; - return path; - -error_3: - free(path->segments); - -error_2: - free(path->paths); - -error_1: - free(path); - - return NULL; -} - -void glc_path_destroy(GLCPath path) -{ - InternalPath *internal = (InternalPath *)path; - - if (!path) { - return; - } - - free(internal->points); - free(internal->segments); - free(internal->paths); - free(internal); -} - -static inline void unref_pat(InternalPat *pat) -{ - if (!pat) { - return; - } - ASSERT(pat->refs > 0); - if (--pat->refs == 0) { - glFinish(); - glDeleteTextures(1, &pat->texture); - free(pat); - } - GLC_ERROR_TETS; -} - -static inline InternalPat *ref_pat(InternalPat *pat) -{ - pat->refs++; - return pat; -} - -#ifdef WIN32 -static inline int find_msb(uint32_t val) -{ - uint32_t r; - __asm { - bsr eax, val - jnz found - mov eax, -1 - - found: - mov r, eax - } - return r + 1; -} -#else -static inline int find_msb(uint32_t val) -{ - int ret; - - asm("bsrl %1,%0\n\t" - "jnz 1f\n\t" - "movl $-1,%0\n" - "1:" - : "=r"(ret) : "r"(val)); - return ret + 1; -} -#endif - -static int to_pwoer_two(uint32_t val) -{ - if ((val & (val - 1)) == 0) { - return val; - } - return 1 << find_msb(val); -} - -static void scale(uint32_t *dest, uint32_t dest_width, uint32_t dest_height, - uint32_t *src, uint32_t src_width, uint32_t src_height, int src_stride) -{ - double x_scale = (double)src_width / dest_width; - double y_scale = (double)src_height / dest_height; - uint32_t i; - uint32_t j; - int prev_row = -1; - - for (i = 0; i < dest_height; i++) { - int row = (int)(y_scale * i); - if (row == prev_row) { - memcpy(dest, dest - dest_width, dest_width * sizeof(uint32_t)); - dest += dest_width; - continue; - } - for (j = 0; j < dest_width; j++) { - int col = (int)(x_scale * j); - *(dest++) = *(src + col); - } - prev_row = row; - src = (uint32_t *)((uint8_t *)src + src_stride); - } -} - -static inline void init_pattern(InternalPat *pat, int x_orign, int y_orign, const GLCImage *image) -{ - InternaCtx *ctx = pat->owner; - uint32_t *tmp_pixmap = NULL; - int width; - int height; - int width2; - int height2; - - const int pix_bytes = 4; - - ASSERT(image->format == GLC_IMAGE_RGB32); //for now - - width = image->width; - height = image->height; - width2 = to_pwoer_two(width); - height2 = to_pwoer_two(height); - - ASSERT(width > 0 && height > 0); - ASSERT(width > 0 && width <= pat->owner->max_texture_size); - ASSERT(height > 0 && height <= pat->owner->max_texture_size); - - if (width2 != width || height2 != height) { - if (!(tmp_pixmap = (uint32_t *)malloc(width2 * height2 * sizeof(uint32_t)))) { - //warn - return; - } - scale(tmp_pixmap, width2, height2, (uint32_t *)image->pixels, width, height, image->stride); - } - - glBindTexture(GL_TEXTURE_2D, pat->texture); - - //glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - - if (tmp_pixmap) { - glPixelStorei(GL_UNPACK_ROW_LENGTH, width2); - glTexImage2D(GL_TEXTURE_2D, 0, 4, width2, height2, 0, GL_BGRA, GL_UNSIGNED_BYTE, - tmp_pixmap); - free(tmp_pixmap); - } else { - ASSERT(image->stride % pix_bytes == 0); - glPixelStorei(GL_UNPACK_ROW_LENGTH, image->stride / pix_bytes); - glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, - image->pixels); - } - - GLC_ERROR_TETS; - pat->x_orign = x_orign % width; - pat->y_orign = y_orign % height; - pat->width = width; - pat->height = height; - - if (ctx->pat == pat) { - set_pat(pat->owner, pat); - } else if (ctx->pat) { - glBindTexture(GL_TEXTURE_2D, ctx->pat->texture); - } -} - -GLCPattern glc_pattern_create(GLCCtx glc, int x_orign, int y_orign, const GLCImage *image) -{ - InternaCtx *ctx = (InternaCtx *)glc; - InternalPat *pat; - - ASSERT(ctx && image); - - if (!(pat = (InternalPat *)zmalloc(sizeof(*pat)))) { - return NULL; - } - pat->refs = 1; - pat->owner = ctx; - glGenTextures(1, &pat->texture); - init_pattern(pat, x_orign, y_orign, image); - return pat; -} - -void glc_pattern_set(GLCPattern pattern, int x_orign, int y_orign, const GLCImage *image) -{ - InternalPat *pat = (InternalPat *)pattern; - ASSERT(pat && pat->owner); - - glFinish(); - init_pattern(pat, x_orign, y_orign, image); -} - -void glc_pattern_destroy(GLCPattern pat) -{ - unref_pat((InternalPat *)pat); - GLC_ERROR_TETS; -} - -static void set_pat(InternaCtx *ctx, InternalPat *pat) -{ - pat = ref_pat(pat); - unref_pat(ctx->pat); - ctx->pat = pat; - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, pat->texture); - - GLfloat s_gen_params[] = { (GLfloat)1.0 / pat->width, 0, 0, 0 }; - GLfloat t_gen_params[] = { 0, (GLfloat)1.0 / (GLfloat)pat->height, 0, 0 }; - glTexGenfv(GL_S, GL_OBJECT_PLANE, s_gen_params); - glTexGenfv(GL_T, GL_OBJECT_PLANE, t_gen_params); - - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef((float)pat->x_orign / pat->width, (float)Y(pat->y_orign) / pat->height, 0); - GLC_ERROR_TETS; -} - -void glc_set_pattern(GLCCtx glc, GLCPattern pattern) -{ - InternaCtx *ctx = (InternaCtx *)glc; - InternalPat *pat = (InternalPat *)pattern; - - ASSERT(ctx && pat && pat->owner == ctx); - set_pat(ctx, pat); -} - -void glc_set_rgb(GLCCtx glc, double red, double green, double blue) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx); - - glDisable(GL_TEXTURE_2D); - unref_pat(ctx->pat); - ctx->pat = NULL; - glColor4d(red, green, blue, 1); - GLC_ERROR_TETS; -} - -void glc_set_op(GLCCtx glc, GLCOp op) -{ - if (op == GL_COPY) { - glDisable(GL_COLOR_LOGIC_OP); - return; - } - glLogicOp(op); - glEnable(GL_COLOR_LOGIC_OP); -} - -void glc_set_line_width(GLCCtx glc, double width) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx); - ctx->line_width = (GLfloat)width; - if (ctx->line_width > 0) { - glLineWidth(ctx->line_width); - } else { - ctx->line_width = 0; - } - GLC_ERROR_TETS; -} - -void glc_set_fill_mode(GLCCtx glc, GLCFillMode fill_mode) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx); - int mode; - switch (fill_mode) { - case GLC_FILL_MODE_WINDING_ODD: - mode = GLU_TESS_WINDING_ODD; - break; - case GLC_FILL_MODE_WINDING_NONZERO: - mode = GLU_TESS_WINDING_NONZERO; - break; - default: - //warn - return; - } - gluTessProperty(ctx->tesselator, GLU_TESS_WINDING_RULE, mode); -} - -static inline void add_stencil_client(InternaCtx *ctx) -{ - if (!ctx->stencil_refs) { - glEnable(GL_STENCIL_TEST); - } - ctx->stencil_refs++; -} - -static inline void remove_stencil_client(InternaCtx *ctx) -{ - ctx->stencil_refs--; - if (!ctx->stencil_refs) { - glDisable(GL_STENCIL_TEST); - } -} - -void glc_set_mask(GLCCtx glc, int x_dest, int y_dest, int width, int height, - int stride, const uint8_t *bitmap, GLCMaskID id) -{ - InternaCtx *ctx = (InternaCtx *)glc; - uint32_t mask = (id == GLC_MASK_A) ? 0x04 : 0x08; - ASSERT(ctx && bitmap); - ASSERT(id == GLC_MASK_A || id == GLC_MASK_B); - - if (ctx->pat) { - glDisable(GL_TEXTURE_2D); - } - - glDisable(GL_BLEND); - - if (!(ctx->stencil_mask & mask)) { - add_stencil_client(ctx); - ctx->stencil_mask |= mask; - } - - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - ctx->draw_mode = FALSE; - glStencilMask(mask); - glClear(GL_STENCIL_BUFFER_BIT); - - glStencilFunc(GL_ALWAYS, mask, mask); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - fill_mask(ctx, x_dest, y_dest, width, height, stride, bitmap); -} - - -void glc_mask_rects(GLCCtx glc, int num_rect, GLCRect *rects, GLCMaskID id) -{ - InternaCtx *ctx = (InternaCtx *)glc; - uint32_t mask = (id == GLC_MASK_A) ? 0x04 : 0x08; - GLCRect *end; - ASSERT(ctx && rects); - ASSERT(id == GLC_MASK_A || id == GLC_MASK_B); - - if (ctx->pat) { - glDisable(GL_TEXTURE_2D); - } - - glDisable(GL_BLEND); - - if (!(ctx->stencil_mask & mask)) { - add_stencil_client(ctx); - ctx->stencil_mask |= mask; - } - - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - ctx->draw_mode = FALSE; - glStencilMask(mask); - glClear(GL_STENCIL_BUFFER_BIT); - - glStencilFunc(GL_ALWAYS, mask, mask); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - end = rects + num_rect; - for (; rects < end; rects++) { - fill_rect(ctx, rects); - } -} - -void glc_clear_mask(GLCCtx glc, GLCMaskID id) -{ - InternaCtx *ctx = (InternaCtx *)glc; - uint32_t mask = (id == GLC_MASK_A) ? 0x04 : 0x08; - ASSERT(ctx); - ASSERT(id == GLC_MASK_A || id == GLC_MASK_B); - - if ((ctx->stencil_mask & mask)) { - ctx->stencil_mask &= ~mask; - remove_stencil_client(ctx); - } -} - -void glc_clip_reset(GLCCtx glc) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - if (!(ctx->stencil_mask & 0x03)) { - return; - } - remove_stencil_client(ctx); - ctx->stencil_mask &= ~0x03; - glStencilMask(0x03); - glClear(GL_STENCIL_BUFFER_BIT); - GLC_ERROR_TETS; -} - -static void clip_common(InternaCtx *ctx, GLCClipOp op, void (*fill_func)(InternaCtx *, void *), - void *data) -{ - int stencil_val; - - if (ctx->pat) { - glDisable(GL_TEXTURE_2D); - } - glDisable(GL_BLEND); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - ctx->draw_mode = FALSE; - - if (op == GLC_CLIP_OP_SET) { - glc_clip_reset(ctx); - add_stencil_client(ctx); - ctx->stencil_mask |= 0x01; - } else if (!(ctx->stencil_mask & 0x03)) { - GLCRect area; - if (op == GLC_CLIP_OP_OR) { - return; - } - area.x = area.y = 0; - area.width= ctx->width; - area.height = ctx->height; - clip_common(ctx, GLC_CLIP_OP_SET, fill_rect, &area); - } - glStencilMask(0x03); - switch (op) { - case GLC_CLIP_OP_SET: - case GLC_CLIP_OP_OR: - stencil_val = ctx->stencil_mask & 0x03; - glStencilFunc(GL_ALWAYS, stencil_val, stencil_val); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - fill_func(ctx, data); - break; - case GLC_CLIP_OP_AND: { - int clear_mask; - stencil_val = ctx->stencil_mask & 0x03; - glStencilFunc(GL_EQUAL, stencil_val, stencil_val); - if (stencil_val == 0x01) { - glStencilOp(GL_ZERO, GL_INCR, GL_INCR); - stencil_val = 0x02; - clear_mask = 0x01; - } else { - glStencilOp(GL_ZERO, GL_DECR, GL_DECR); - stencil_val = 0x01; - clear_mask = 0x02; - } - fill_func(ctx, data); - - glStencilMask(clear_mask); - glClear(GL_STENCIL_BUFFER_BIT); - ctx->stencil_mask = (ctx->stencil_mask & ~clear_mask) |stencil_val; - break; - } - case GLC_CLIP_OP_EXCLUDE: - stencil_val = ctx->stencil_mask & 0x03; - glStencilFunc(GL_EQUAL, stencil_val, stencil_val); - glStencilOp(GL_KEEP, GL_ZERO, GL_ZERO); - fill_func(ctx, data); - break; - } - GLC_ERROR_TETS; -} - -void glc_clip_rect(GLCCtx glc, const GLCRect *rect, GLCClipOp op) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx && rect); - clip_common(ctx, op, fill_rect, (void *)rect); -} - -void glc_clip_path(GLCCtx glc, GLCPath path, GLCClipOp op) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx && path); - clip_common(ctx, op, fill_path, path); -} - -typedef struct FillMaskInfo { - int x_dest; - int y_dest; - int width; - int height; - int stride; - const uint8_t *bitmap; -} FillMaskInfo; - -static void __fill_mask(InternaCtx *ctx, void *data) -{ - FillMaskInfo *info = (FillMaskInfo *)data; - fill_mask(ctx, info->x_dest, info->y_dest, info->width, info->height, info->stride, - info->bitmap); -} - -void glc_clip_mask(GLCCtx glc, int x_dest, int y_dest, int width, int height, - int stride, const uint8_t *bitmap, GLCClipOp op) -{ - InternaCtx *ctx = (InternaCtx *)glc; - FillMaskInfo mask_info; - - ASSERT(ctx && bitmap); - mask_info.x_dest = x_dest; - mask_info.y_dest = y_dest; - mask_info.width = width; - mask_info.height = height; - mask_info.stride = stride; - mask_info.bitmap = bitmap; - clip_common(ctx, op, __fill_mask, &mask_info); -} - -static inline void start_draw(InternaCtx *ctx) -{ - if (ctx->draw_mode) { - return; - } - ctx->draw_mode = TRUE; - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glStencilFunc(GL_EQUAL, ctx->stencil_mask, ctx->stencil_mask); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - if (ctx->pat) { - glEnable(GL_TEXTURE_2D); - } else { - glDisable(GL_TEXTURE_2D); - } - GLC_ERROR_TETS; -} - -static void fill_rect(InternaCtx *ctx, void *r) -{ - GLCRect *rect = (GLCRect *)r; - glRectd(rect->x, Y(rect->y), rect->x + rect->width, Y(rect->y + rect->height)); - /*glBegin(GL_POLYGON); - VERTEX2(rect->x, rect->y); - VERTEX2 (rect->x + rect->width, rect->y); - VERTEX2 (rect->x + rect->width, rect->y + rect->height); - VERTEX2 (rect->x , rect->y + rect->height); - glEnd();*/ - GLC_ERROR_TETS; -} - -void glc_fill_rect(GLCCtx glc, const GLCRect *rect) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx); - start_draw(ctx); - fill_rect(ctx, (void *)rect); - GLC_ERROR_TETS; -} - -static void fill_path(InternaCtx *ctx, void *p) -{ - InternalPath *path = (InternalPath *)p; - - PathPoint *current_point = path->points; - PathSegment *current_segment = path->segments; - Path *current_path = path->paths; - Path *end_path = current_path + path->paths_pos; - reset_tass_vertex(ctx); - gluTessBeginPolygon(ctx->tesselator, ctx); - for (; current_path < end_path; current_path++) { - gluTessBeginContour(ctx->tesselator); - PathSegment *end_segment = current_segment + current_path->num_segments; - gluTessVertex(ctx->tesselator, (GLdouble *)current_point, current_point); - current_point++; - for (; current_segment < end_segment; current_segment++) { - PathPoint *end_point; - if (current_segment->type == GLC_PATH_SEG_BEIZER) { - end_point = current_point + current_segment->count * 3; - for (; current_point < end_point; current_point += 3) { - TassVertex *vertex = bezier_flattener(ctx, current_point - 1); - while (vertex) { - gluTessVertex(ctx->tesselator, (GLdouble *)&vertex->point, - (GLdouble *)&vertex->point); - vertex = vertex->list_link; - } - gluTessVertex(ctx->tesselator, (GLdouble *)¤t_point[2], - (GLdouble *)¤t_point[2]); - } - } else { - ASSERT(current_segment->type == GLC_PATH_SEG_LINES); - end_point = current_point + current_segment->count; - for (; current_point < end_point; current_point++) { - gluTessVertex(ctx->tesselator, (GLdouble *)current_point , - (GLdouble *)current_point); - } - } - } - gluTessEndContour(ctx->tesselator); - } - gluTessEndPolygon(ctx->tesselator); -} - -void glc_fill_path(GLCCtx glc, GLCPath path_ref) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx && path_ref); - start_draw(ctx); - fill_path(ctx, path_ref); -} - -static void fill_mask(InternaCtx *ctx, int x_dest, int y_dest, int width, int height, - int stride, const uint8_t *bitmap) -{ - set_raster_pos(ctx, x_dest, y_dest + height); - glPixelStorei(GL_UNPACK_ROW_LENGTH, stride * 8); - glBitmap(width, height, 0, 0, 0, 0, bitmap); -} - -void _glc_fill_mask(GLCCtx glc, int x_dest, int y_dest, int width, int height, int stride, - const uint8_t *bitmap) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx && bitmap); - start_draw(ctx); - if (ctx->pat) { - WARN_ONCE(("%s: unimplemented fill mask with pattern\n", __FUNCTION__)); - } - fill_mask(ctx, x_dest, y_dest, width, height, stride, bitmap); -} - -void glc_fill_alpha(GLCCtx glc, int x_dest, int y_dest, int width, int height, int stride, - const uint8_t *alpha_mask) -{ - InternaCtx *ctx = (InternaCtx *)glc; - GLCRect r; - - ASSERT(ctx); - start_draw(ctx); - - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); - set_raster_pos(ctx, x_dest, y_dest + height); - glPixelStorei(GL_UNPACK_ROW_LENGTH, stride); - glPixelZoom(1, 1); - glDrawPixels(width, height, GL_ALPHA, GL_UNSIGNED_BYTE, alpha_mask); - - r.x = x_dest; - r.y = y_dest; - r.width = width; - r.height = height; - - //todo: support color/texture alpah vals (GL_MODULATE) - glEnable(GL_BLEND); - glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - fill_rect(ctx, &r); - glDisable(GL_BLEND); -} - -void glc_stroke_rect(GLCCtx glc, const GLCRect *rect) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx); - if (ctx->line_width == 0) { - return; - } - - start_draw(ctx); - - glBegin(GL_LINES); - VERTEX2 (rect->x , rect->y + 0.5); - VERTEX2 (rect->x + rect->width, rect->y + 0.5); - glEnd(); - - glBegin(GL_LINES); - VERTEX2 (rect->x + rect->width - 0.5, rect->y); - VERTEX2 (rect->x + rect->width - 0.5, rect->y + rect->height); - glEnd(); - - glBegin(GL_LINES); - VERTEX2 (rect->x + rect->width, rect->y + rect->height - 0.5); - VERTEX2 (rect->x, rect->y + rect->height - 0.5); - glEnd(); - - glBegin(GL_LINES); - VERTEX2(rect->x + 0.5, rect->y + rect->height); - VERTEX2(rect->x + 0.5 , rect->y); - glEnd(); - GLC_ERROR_TETS; -} - -void glc_stroke_path(GLCCtx glc, GLCPath path_ref) -{ - InternaCtx *ctx = (InternaCtx *)glc; - InternalPath *path = (InternalPath *)path_ref; - - ASSERT(ctx && path); - if (ctx->line_width == 0) { - return; - } - start_draw(ctx); - - reset_tass_vertex(ctx); - PathPoint *current_point = path->points; - PathSegment *current_segment = path->segments; - Path *current_path = path->paths; - Path *end_path = current_path + path->paths_pos; - for (; current_path < end_path; current_path++) { - glBegin(GL_LINE_STRIP); - PathSegment *end_segment = current_segment + current_path->num_segments; - glVertex2d(current_point->x , current_point->y); - current_point++; - for (; current_segment < end_segment; current_segment++) { - PathPoint *end_point; - if (current_segment->type == GLC_PATH_SEG_BEIZER) { - end_point = current_point + current_segment->count * 3; - for (; current_point < end_point; current_point += 3) { - TassVertex *vertex = bezier_flattener(ctx, current_point - 1); - while (vertex) { - glVertex2d(vertex->point.x, vertex->point.y); - vertex = vertex->list_link; - } - glVertex2d(current_point[2].x , current_point[2].y); - } - } else { - ASSERT(current_segment->type == GLC_PATH_SEG_LINES); - end_point = current_point + current_segment->count; - for (; current_point < end_point; current_point++) { - glVertex2d(current_point->x , current_point->y); - } - } - } - glEnd(); - } -} - -void glc_draw_image(GLCCtx glc, const GLCRecti *dest, const GLCRecti *src, const GLCImage *image, - int scale_mode, double alpha) -{ - InternaCtx *ctx = (InternaCtx *)glc; - uint8_t *pixels; - const int pix_bytes = 4; - - ASSERT(ctx && image); - ASSERT(src->width > 0 && src->height > 0); - - ASSERT(image->format == GLC_IMAGE_RGB32 || image->format == GLC_IMAGE_ARGB32); //for now - start_draw(ctx); - if (ctx->pat) { - glDisable(GL_TEXTURE_2D); - } - set_raster_pos(ctx, dest->x, dest->y + dest->height); - - if (dest->width == src->width && src->height == dest->height) { - glPixelZoom(1, 1); - } else { - glPixelZoom((float)dest->width / src->width, (float)dest->height / src->height); - } - - pixels = image->pixels + src->x * 4 + (image->height - (src->y + src->height)) * image->stride; - if (image->format == GLC_IMAGE_ARGB32 || alpha != 1) { - glPixelTransferf(GL_ALPHA_SCALE, (GLfloat)alpha); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - } - ASSERT(image->stride % pix_bytes == 0); - glPixelStorei(GL_UNPACK_ROW_LENGTH, image->stride / pix_bytes); - glDrawPixels(src->width, src->height, GL_BGRA, GL_UNSIGNED_BYTE, pixels); - - if (image->format == GLC_IMAGE_ARGB32 || alpha != 1) { - glDisable(GL_BLEND); - } - - if (ctx->pat) { - glEnable(GL_TEXTURE_2D); - } - GLC_ERROR_TETS; -} - -void glc_copy_pixels(GLCCtx glc, int x_dest, int y_dest, int x_src, int y_src, int width, - int height) -{ - InternaCtx *ctx = (InternaCtx *)glc; - ASSERT(ctx); -#ifdef USE_COPY_PIXELS - start_draw(ctx); - if (ctx->pat) { - glDisable(GL_TEXTURE_2D); - } - set_raster_pos(ctx, x_dest, y_dest + height); - glPixelZoom(1, 1); - glCopyPixels(x_src, ctx->height - (y_src + height), width, height, GL_COLOR); - if (ctx->pat) { - glEnable(GL_TEXTURE_2D); - } -#else - GLuint texture; - int width2 = to_pwoer_two(width); - int height2 = to_pwoer_two(height); - - start_draw(ctx); - glEnable(GL_TEXTURE_2D); - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, x_src, ctx->height - (y_src + height), - width2, height2, 0); - - GLfloat s_gen_params[] = { (GLfloat)1.0 / width2, 0, 0, 0 }; - GLfloat t_gen_params[] = { 0, (GLfloat)1.0 / height2, 0, 0 }; - glTexGenfv(GL_S, GL_OBJECT_PLANE, s_gen_params); - glTexGenfv(GL_T, GL_OBJECT_PLANE, t_gen_params); - - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef((float)-x_dest / width2, (float)-Y(y_dest + height) / height2, 0); - - glRecti(x_dest, Y(y_dest), x_dest + width, Y(y_dest + height)); - glFinish(); - glDeleteTextures(1, &texture); - if (!ctx->pat) { - glDisable(GL_TEXTURE_2D); - } else { - set_pat(ctx, ctx->pat); - } -#endif - GLC_ERROR_TETS; -} - -void glc_read_pixels(GLCCtx glc, int x, int y, GLCImage *image) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx && image); - ASSERT(image->format == GLC_IMAGE_RGB32); //for now - ASSERT((image->stride % 4) == 0); //for now - glPixelStorei(GL_PACK_ROW_LENGTH, image->stride / 4); - glReadPixels(x, ctx->height - (y + image->height), image->width, image->height, - GL_BGRA, GL_UNSIGNED_BYTE, image->pixels); -} - -void glc_clear(GLCCtx glc) -{ - InternaCtx *ctx = (InternaCtx *)glc; - - ASSERT(ctx); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glClear(GL_COLOR_BUFFER_BIT); -} - -void glc_flush(GLCCtx glc) -{ - glFlush(); - - GLC_ERROR_TETS; -} - -static void tessellation_combine(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], - GLdouble **data_out, void *usr_data) -{ - TassVertex *vertex; - - if (!(vertex = alloc_tess_vertex((InternaCtx *)usr_data))) { - *data_out = NULL; - return; - } - vertex->point.x = coords[0]; - vertex->point.y = coords[1]; - //vertex->point.z = coords[2]; - *data_out = (GLdouble *)&vertex->point; -} - -static void tessellation_error(GLenum errorCode) -{ - printf ("%s: %s\n", __FUNCTION__, gluErrorString(errorCode)); -} - -#ifdef WIN32 -#define TESS_CALL_BACK_TYPE void (CALLBACK *)() -#else -#define TESS_CALL_BACK_TYPE void (*)() -#endif - -static int init(InternaCtx *ctx, int width, int height) -{ -#ifdef WIN32 - if (!(ctx->glBlendEquation = (PFNGLBLENDEQUATIONPROC)wglGetProcAddress("glBlendEquation"))) { - return FALSE; - } -#endif - ctx->width = width; - ctx->height = height; - ctx->line_width = 1; - - glClearColor(0, 0, 0, 0); - glClearStencil(0); - - if (!(ctx->tesselator = gluNewTess())) { - return FALSE; - } - - glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, width, 0, height, -1, 1); - - gluTessProperty(ctx->tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); - gluTessCallback(ctx->tesselator, GLU_BEGIN, (TESS_CALL_BACK_TYPE)glBegin); - gluTessCallback(ctx->tesselator, GLU_VERTEX, (TESS_CALL_BACK_TYPE)glVertex3dv); - gluTessCallback(ctx->tesselator, GLU_END, (TESS_CALL_BACK_TYPE)glEnd); - gluTessCallback(ctx->tesselator, GLU_TESS_COMBINE_DATA, (TESS_CALL_BACK_TYPE)tessellation_combine); - gluTessCallback(ctx->tesselator, GLU_TESS_ERROR, (TESS_CALL_BACK_TYPE)tessellation_error); - - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0, (GLfloat)height, 0); - - glGetIntegerv( GL_MAX_TEXTURE_SIZE, &ctx->max_texture_size); - - glPixelStorei(GL_PACK_ALIGNMENT, 1); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); - glPixelTransferf(GL_ALPHA_BIAS, 0); -#ifdef WIN32 - ctx->glBlendEquation(GL_FUNC_ADD); -#else - glBlendEquation(GL_FUNC_ADD); -#endif - - glStencilMask(0xff); - glClear(GL_STENCIL_BUFFER_BIT); - - glClear(GL_COLOR_BUFFER_BIT); - - return TRUE; -} - -GLCCtx glc_create(int width, int height) -{ - InternaCtx *ctx; - - ASSERT(sizeof(PathPoint) == sizeof(Vertex)); - - if (!(ctx = (InternaCtx *)zmalloc(sizeof(*ctx)))) { - return NULL; - } - - if (!init(ctx, width, height)) { - free(ctx); - return NULL; - } - return ctx; -} - -void glc_destroy(GLCCtx glc) -{ - InternaCtx *ctx; - - if (!(ctx = (InternaCtx *)glc)) { - return; - } - - unref_pat(ctx->pat); - free_tass_vertex_bufs(ctx); - free(ctx); -} - -/* - todo: - 1. test double vs float in gl calls - 2. int vs flat raster position - 3. pixels stride vs bytes stride - 4. improve non power of two. - glGetString(GL_EXTENSIONS); - ARB_texture_non_power_of_two - ARB_texture_rectangle - GL_TEXTURE_RECTANGLE_ARB - 5. scale - 6. origin - 7. fonts - 8. support more image formats - 9. use GLCImage in mask ops? -*/ - diff --git a/common/lines.c b/common/lines.c index e2349e82..797d5d62 100644 --- a/common/lines.c +++ b/common/lines.c @@ -509,17 +509,15 @@ miSubtractSpans (SpanGroup * spanGroup, Spans * sub) int *newwid; #define EXTRA 8 - newPt = - (DDXPointPtr) xrealloc (spans->points, - (spans->count + - EXTRA) * sizeof (DDXPointRec)); + newPt = xrealloc (spans->points, + (spans->count + + EXTRA) * sizeof (DDXPointRec)); if (!newPt) break; spansPt = newPt + (spansPt - spans->points); spans->points = newPt; - newwid = - (int *) xrealloc (spans->widths, - (spans->count + EXTRA) * sizeof (int)); + newwid = xrealloc (spans->widths, + (spans->count + EXTRA) * sizeof (int)); if (!newwid) break; spansWid = newwid + (spansWid - spans->widths); @@ -556,7 +554,7 @@ miAppendSpans (SpanGroup * spanGroup, SpanGroup * otherGroup, Spans * spans) if (spansCount > 0) { if (spanGroup->size == spanGroup->count) { spanGroup->size = (spanGroup->size + 8) * 2; - spanGroup->group = (Spans *) + spanGroup->group = xrealloc (spanGroup->group, sizeof (Spans) * spanGroup->size); } @@ -580,8 +578,7 @@ miAppendSpans (SpanGroup * spanGroup, SpanGroup * otherGroup, Spans * spans) static void miFreeSpanGroup (SpanGroup * spanGroup) { - if (spanGroup->group != NULL) - xfree (spanGroup->group); + xfree (spanGroup->group); } static void @@ -776,10 +773,8 @@ miFillUniqueSpanGroup (GCPtr pGC, SpanGroup * spanGroup, Boolean foreground) ysizes = (int *)xalloc (ylength * sizeof (int)); if (!yspans || !ysizes) { - if (yspans) - xfree (yspans); - if (ysizes) - xfree (ysizes); + xfree (yspans); + xfree (ysizes); miDisposeSpanGroup (spanGroup); return; } @@ -806,10 +801,10 @@ miFillUniqueSpanGroup (GCPtr pGC, SpanGroup * spanGroup, Boolean foreground) DDXPointPtr newpoints; int *newwidths; ysizes[index] = (ysizes[index] + 8) * 2; - newpoints = (DDXPointPtr) xrealloc (newspans->points, - ysizes[index] * sizeof (DDXPointRec)); - newwidths = (int *) xrealloc (newspans->widths, - ysizes[index] * sizeof (int)); + newpoints = xrealloc (newspans->points, + ysizes[index] * sizeof (DDXPointRec)); + newwidths = xrealloc (newspans->widths, + ysizes[index] * sizeof (int)); if (!newpoints || !newwidths) { int i; @@ -849,10 +844,8 @@ miFillUniqueSpanGroup (GCPtr pGC, SpanGroup * spanGroup, Boolean foreground) } xfree (yspans); xfree (ysizes); - if (points) - xfree (points); - if (widths) - xfree (widths); + xfree (points); + xfree (widths); return; } count = 0; diff --git a/common/lz.c b/common/lz.c index 2e3a1365..5f517940 100644 --- a/common/lz.c +++ b/common/lz.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* - Copyright 2009 Red Hat, Inc. and/or its affiliates. + Copyright (C) 2009 Red Hat, Inc. and/or its affiliates. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -439,7 +439,7 @@ typedef uint16_t rgb16_pixel_t; #define COMP_LEVEL_SIZE_LIMIT 65536 // TODO: implemented lz2. should lz1 be an option (no RLE + distance limitation of MAX_DISTANCE) -// TODO: I think MAX_FARDISTANCE can be changed easily to 2^29 +// TODO: I think MAX_FARDISTANCE can be changed easily to 2^29 // (and maybe even more when pixel > byte). // i.e. we can support 512M Bytes/Pixels distance instead of only ~68K. #define MAX_DISTANCE 8191 // 2^13 @@ -738,4 +738,3 @@ void lz_decode(LzContext *lz, LzImageType to_type, uint8_t *buf) encoder->usr->error(encoder->usr, "bad decode size\n"); } } - diff --git a/common/lz_compress_tmpl.c b/common/lz_compress_tmpl.c index 865a30a8..6db53872 100644 --- a/common/lz_compress_tmpl.c +++ b/common/lz_compress_tmpl.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* - Copyright 2009 Red Hat, Inc. and/or its affiliates. + Copyright (C) 2009 Red Hat, Inc. and/or its affiliates. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -296,7 +296,7 @@ match: // RLE or dictionary (both are encoded by distance from ref (-1) a PIXEL x = *ref; while ((ip < ip_bound) && (ref < ref_limit)) { // TODO: maybe separate a run from // the same seg or from different - // ones in order to spare + // ones in order to spare // ref < ref_limit if (!SAME_PIXEL(*ref, x)) { ref++; diff --git a/common/lz_decompress_tmpl.c b/common/lz_decompress_tmpl.c index 6d520744..b0cbb2a9 100644 --- a/common/lz_decompress_tmpl.c +++ b/common/lz_decompress_tmpl.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* - Copyright 2009 Red Hat, Inc. and/or its affiliates. + Copyright (C) 2009 Red Hat, Inc. and/or its affiliates. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -170,7 +170,7 @@ out->b = (out->b << 3) | ((out->b >> 2) & 0x07); \ out->pad = 0; \ out++; \ -} +} #endif #endif @@ -324,4 +324,3 @@ static size_t FNAME(decompress)(Encoder *encoder, OUT_PIXEL *out_buf, int size) #undef COPY_COMP_PIXEL #undef COPY_PLT_ENTRY #undef CAST_PLT_DISTANCE - diff --git a/common/mem.c b/common/mem.c index 7236cf0c..5298e37d 100644 --- a/common/mem.c +++ b/common/mem.c @@ -130,9 +130,7 @@ void *spice_realloc(void *mem, size_t n_bytes) (unsigned long)n_bytes); } - if (mem) { - free(mem); - } + free(mem); return NULL; } diff --git a/common/ogl_ctx.c b/common/ogl_ctx.c index 0917f424..41c05915 100644 --- a/common/ogl_ctx.c +++ b/common/ogl_ctx.c @@ -249,4 +249,3 @@ void oglctx_destroy(OGLCtx *ctx) XCloseDisplay(ctx->x_display); free(ctx); } - diff --git a/common/ogl_ctx.h b/common/ogl_ctx.h index ae2ce7e1..e7f677ac 100644 --- a/common/ogl_ctx.h +++ b/common/ogl_ctx.h @@ -36,4 +36,3 @@ void oglctx_destroy(OGLCtx *ctx); #endif #endif - diff --git a/common/pixman_utils.c b/common/pixman_utils.c index 612ddd8c..c04b01f3 100644 --- a/common/pixman_utils.c +++ b/common/pixman_utils.c @@ -928,7 +928,7 @@ pixman_format_code_t spice_surface_format_to_pixman(uint32_t surface_format) abort(); break; } - return (pixman_format_code_t)0; /* Not reached */ + return (pixman_format_code_t)0; /* Not reached */ } /* Returns the "spice native" pixman version of a specific bitmap format. diff --git a/common/quic.c b/common/quic.c index ca7ffd24..707724a2 100644 --- a/common/quic.c +++ b/common/quic.c @@ -1515,7 +1515,7 @@ static void uncompress_gray(Encoder *encoder, uint8_t *buf, int stride) encoder->width); \ encoder->rows_completed++; \ } - + int quic_decode(QuicContext *quic, QuicImageType type, uint8_t *buf, int stride) { Encoder *encoder = (Encoder *)quic; @@ -1697,4 +1697,3 @@ void quic_init(void) init_zeroLUT(); #endif } - diff --git a/common/quic.h b/common/quic.h index 6047da8b..7ec94f56 100644 --- a/common/quic.h +++ b/common/quic.h @@ -70,4 +70,3 @@ void quic_init(void); #endif #endif - diff --git a/common/quic_config.h b/common/quic_config.h index 2a87f201..13c71f1d 100644 --- a/common/quic_config.h +++ b/common/quic_config.h @@ -46,4 +46,3 @@ extern "C" { #endif #endif - diff --git a/common/quic_family_tmpl.c b/common/quic_family_tmpl.c index fbefe893..bfba0ccf 100644 --- a/common/quic_family_tmpl.c +++ b/common/quic_family_tmpl.c @@ -115,4 +115,3 @@ static s_bucket *FNAME(find_bucket)(Channel *channel, const unsigned int val) #undef FNAME #undef VNAME #undef BPC - diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c index 814fa5af..8f356792 100644 --- a/common/quic_rgb_tmpl.c +++ b/common/quic_rgb_tmpl.c @@ -763,4 +763,3 @@ static void FNAME(uncompress_row)(Encoder *encoder, #undef SET_b #undef GET_b #undef UNCOMPRESS_PIX_START - diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c index d300fa97..6acd5042 100644 --- a/common/quic_tmpl.c +++ b/common/quic_tmpl.c @@ -633,4 +633,3 @@ static void FNAME(uncompress_row)(Encoder *encoder, Channel *channel, #undef family #undef BPC #undef BPC_MASK - diff --git a/common/rect.h b/common/rect.h index 360cb9d7..ef265cd9 100644 --- a/common/rect.h +++ b/common/rect.h @@ -120,4 +120,3 @@ static inline int rect_is_same_size(const SpiceRect& r1, const SpiceRect& r2) #endif #endif - diff --git a/common/region.c b/common/region.c index 10a6e62e..35935eac 100644 --- a/common/region.c +++ b/common/region.c @@ -888,4 +888,3 @@ int main(void) } #endif - diff --git a/common/region.h b/common/region.h index 16ec6eb7..954e06fa 100644 --- a/common/region.h +++ b/common/region.h @@ -68,4 +68,3 @@ void region_dump(const QRegion *rgn, const char *prefix); #endif #endif - diff --git a/common/ring.h b/common/ring.h index 304bc9a5..cb70696a 100644 --- a/common/ring.h +++ b/common/ring.h @@ -170,4 +170,3 @@ static inline unsigned int ring_get_length(Ring *ring) #endif #endif - diff --git a/common/rop3.h b/common/rop3.h index 3307649f..91c9207e 100644 --- a/common/rop3.h +++ b/common/rop3.h @@ -40,4 +40,3 @@ void rop3_init(void); #endif #endif - diff --git a/common/ssl_verify.h b/common/ssl_verify.h index 8235c136..b8306f31 100644 --- a/common/ssl_verify.h +++ b/common/ssl_verify.h @@ -19,7 +19,7 @@ #ifndef SSL_VERIFY_H #define SSL_VERIFY_H -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) #include <windows.h> #include <wincrypt.h> #endif diff --git a/common/sw_canvas.c b/common/sw_canvas.c index 651c52bc..8eabc896 100644 --- a/common/sw_canvas.c +++ b/common/sw_canvas.c @@ -16,6 +16,9 @@ License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H +#ifdef __MINGW32__ +#undef HAVE_STDLIB_H +#endif #include <config.h> #endif @@ -469,8 +472,8 @@ static void __scale_image(SpiceCanvas *spice_canvas, pixman_transform_init_scale(&transform, fsx, fsy); pixman_transform_translate(&transform, NULL, - pixman_int_to_fixed (src_x), - pixman_int_to_fixed (src_y)); + pixman_int_to_fixed (src_x), + pixman_int_to_fixed (src_y)); pixman_image_set_transform(src, &transform); pixman_image_set_repeat(src, PIXMAN_REPEAT_NONE); @@ -550,8 +553,8 @@ static void __scale_image_rop(SpiceCanvas *spice_canvas, pixman_transform_init_scale(&transform, fsx, fsy); pixman_transform_translate(&transform, NULL, - pixman_int_to_fixed (src_x), - pixman_int_to_fixed (src_y)); + pixman_int_to_fixed (src_x), + pixman_int_to_fixed (src_y)); pixman_image_set_transform(src, &transform); pixman_image_set_repeat(src, PIXMAN_REPEAT_NONE); @@ -744,8 +747,8 @@ static void __blend_scale_image(SpiceCanvas *spice_canvas, pixman_transform_init_scale(&transform, fsx, fsy); pixman_transform_translate(&transform, NULL, - pixman_int_to_fixed (src_x), - pixman_int_to_fixed (src_y)); + pixman_int_to_fixed (src_x), + pixman_int_to_fixed (src_y)); mask = NULL; if (overall_alpha != 0xff) { @@ -906,8 +909,8 @@ static void __colorkey_scale_image(SpiceCanvas *spice_canvas, pixman_transform_init_scale(&transform, fsx, fsy); pixman_transform_translate(&transform, NULL, - pixman_int_to_fixed (src_x), - pixman_int_to_fixed (src_y)); + pixman_int_to_fixed (src_x), + pixman_int_to_fixed (src_y)); pixman_image_set_transform(src, &transform); pixman_image_set_repeat(src, PIXMAN_REPEAT_NONE); @@ -1163,9 +1166,7 @@ static void canvas_destroy(SpiceCanvas *spice_canvas) } pixman_image_unref(canvas->image); canvas_base_destroy(&canvas->base); - if (canvas->private_data) { - free(canvas->private_data); - } + free(canvas->private_data); free(canvas); } diff --git a/common/sw_canvas.h b/common/sw_canvas.h index d8d26a97..8667fccc 100644 --- a/common/sw_canvas.h +++ b/common/sw_canvas.h @@ -41,7 +41,7 @@ SpiceCanvas *canvas_create(int width, int height, uint32_t format #elif defined(SW_CANVAS_IMAGE_CACHE) , SpiceImageCache *bits_cache #endif - , SpiceImageSurfaces *surfaces + , SpiceImageSurfaces *surfaces , SpiceGlzDecoder *glz_decoder , SpiceJpegDecoder *jpeg_decoder , SpiceZlibDecoder *zlib_decoder @@ -54,7 +54,7 @@ SpiceCanvas *canvas_create_for_data(int width, int height, uint32_t format, uint #elif defined(SW_CANVAS_IMAGE_CACHE) , SpiceImageCache *bits_cache #endif - , SpiceImageSurfaces *surfaces + , SpiceImageSurfaces *surfaces , SpiceGlzDecoder *glz_decoder , SpiceJpegDecoder *jpeg_decoder , SpiceZlibDecoder *zlib_decoder diff --git a/common/win/my_getopt-1.5/getopt.h b/common/win/my_getopt-1.5/getopt.h index 5f08ccb4..df07082a 100644 --- a/common/win/my_getopt-1.5/getopt.h +++ b/common/win/my_getopt-1.5/getopt.h @@ -9,10 +9,10 @@ * modify, merge, publish, distribute, sublicense, 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 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 diff --git a/common/win/my_getopt-1.5/main.c b/common/win/my_getopt-1.5/main.c index 25674e1c..a9de2723 100644 --- a/common/win/my_getopt-1.5/main.c +++ b/common/win/my_getopt-1.5/main.c @@ -163,7 +163,7 @@ main(int argc, char * argv[]) /* long option list index */ int longind = 0; - /* + /* * print a warning when the POSIXLY_CORRECT environment variable will * interfere with argument placement */ @@ -326,12 +326,12 @@ main(int argc, char * argv[]) if (optind < argc) { int argindex; - + for (argindex = optind; argindex < argc; argindex ++) { char *infilename = argv[argindex]; FILE *infile; - + /* we allow "-" as a synonym for stdin here */ if (! strcmp(infilename, "-")) { diff --git a/common/win/my_getopt-1.5/my_getopt.c b/common/win/my_getopt-1.5/my_getopt.c index e3737df8..5237b8e8 100644 --- a/common/win/my_getopt-1.5/my_getopt.c +++ b/common/win/my_getopt-1.5/my_getopt.c @@ -9,10 +9,10 @@ * modify, merge, publish, distribute, sublicense, 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 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 @@ -198,7 +198,7 @@ int _my_getopt_internal(int argc, char * argv[], const char *shortopts, if(((my_optopt = argv[my_optind][1]) != '-') && ! argv[my_optind][2]) { int c; - + ind = shortoff; while((c = shortopts[ind++])) { if(((shortopts[ind] == ':') || diff --git a/common/win/my_getopt-1.5/my_getopt.h b/common/win/my_getopt-1.5/my_getopt.h index 2c1dd66f..c75101a1 100644 --- a/common/win/my_getopt-1.5/my_getopt.h +++ b/common/win/my_getopt-1.5/my_getopt.h @@ -9,10 +9,10 @@ * modify, merge, publish, distribute, sublicense, 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 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 |