diff options
author | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2007-05-22 14:50:26 -0400 |
---|---|---|
committer | Eamon Walsh <ewalsh@moss-uranus.epoch.ncsc.mil> | 2007-05-22 14:50:26 -0400 |
commit | 2a4aa63a23ddd816b647b851a01865861827a7eb (patch) | |
tree | a957a7979bda27a4a2c103835cfd6e3a7ddc79e5 /fb | |
parent | 9cee4ec5e6e06d23aafb302494b082c77ade4623 (diff) | |
parent | cc648e609d472472bac4a2e568eb3598b3690ba3 (diff) |
Merge branch 'master' into XACE-SELINUX
Conflicts:
include/miscstruct.h
Diffstat (limited to 'fb')
-rw-r--r-- | fb/Makefile.am | 1 | ||||
-rw-r--r-- | fb/fbcompose.c | 3687 | ||||
-rw-r--r-- | fb/fbmmx.c | 970 | ||||
-rw-r--r-- | fb/fbmmx.h | 62 | ||||
-rw-r--r-- | fb/fbpict.c | 1586 | ||||
-rw-r--r-- | fb/fbpict.h | 236 | ||||
-rw-r--r-- | fb/fbtrap.c | 3 |
7 files changed, 1169 insertions, 5376 deletions
diff --git a/fb/Makefile.am b/fb/Makefile.am index ab135c9c9..01e81da41 100644 --- a/fb/Makefile.am +++ b/fb/Makefile.am @@ -42,7 +42,6 @@ libfb_la_SOURCES = \ fbblt.c \ fbbltone.c \ fbbstore.c \ - fbcompose.c \ fbcopy.c \ fbfill.c \ fbfillrect.c \ diff --git a/fb/fbcompose.c b/fb/fbcompose.c deleted file mode 100644 index 6ea948307..000000000 --- a/fb/fbcompose.c +++ /dev/null @@ -1,3687 +0,0 @@ -/* - * - * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. - * 2005 Lars Knoll & Zack Rusin, Trolltech - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include "fb.h" - -#ifdef RENDER - -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include <assert.h> - -#include "picturestr.h" -#include "mipict.h" -#include "fbpict.h" - -#define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b)) - -#define SCANLINE_BUFFER_LENGTH 2048 - -typedef FASTCALL void (*fetchProc)(const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed); - -/* - * All of the fetch functions - */ - -static FASTCALL void -fbFetch_a8r8g8b8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - MEMCPY_WRAPPED(buffer, (const CARD32 *)bits + x, width*sizeof(CARD32)); -} - -static FASTCALL void -fbFetch_x8r8g8b8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD32 *pixel = (const CARD32 *)bits + x; - const CARD32 *end = pixel + width; - while (pixel < end) { - WRITE(buffer++, READ(pixel++) | 0xff000000); - } -} - -static FASTCALL void -fbFetch_a8b8g8r8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD32 *pixel = (CARD32 *)bits + x; - const CARD32 *end = pixel + width; - while (pixel < end) { - WRITE(buffer++, ((READ(pixel) & 0xff00ff00) | - ((READ(pixel) >> 16) & 0xff) | - ((READ(pixel) & 0xff) << 16))); - ++pixel; - } -} - -static FASTCALL void -fbFetch_x8b8g8r8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD32 *pixel = (CARD32 *)bits + x; - const CARD32 *end = pixel + width; - while (pixel < end) { - WRITE(buffer++, 0xff000000 | - ((READ(pixel) & 0x0000ff00) | - ((READ(pixel) >> 16) & 0xff) | - ((READ(pixel) & 0xff) << 16))); - ++pixel; - } -} - -static FASTCALL void -fbFetch_r8g8b8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + 3*x; - const CARD8 *end = pixel + 3*width; - while (pixel < end) { - CARD32 b = Fetch24(pixel) | 0xff000000; - pixel += 3; - WRITE(buffer++, b); - } -} - -static FASTCALL void -fbFetch_b8g8r8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + 3*x; - const CARD8 *end = pixel + 3*width; - while (pixel < end) { - CARD32 b = 0xff000000; -#if IMAGE_BYTE_ORDER == MSBFirst - b |= (READ(pixel++)); - b |= (READ(pixel++) << 8); - b |= (READ(pixel++) << 16); -#else - b |= (READ(pixel++) << 16); - b |= (READ(pixel++) << 8); - b |= (READ(pixel++)); -#endif - } -} - -static FASTCALL void -fbFetch_r5g6b5 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r = (((p) << 3) & 0xf8) | - (((p) << 5) & 0xfc00) | - (((p) << 8) & 0xf80000); - r |= (r >> 5) & 0x70007; - r |= (r >> 6) & 0x300; - WRITE(buffer++, 0xff000000 | r); - } -} - -static FASTCALL void -fbFetch_b5g6r5 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b; - - b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8; - g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5; - r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14; - WRITE(buffer++, (0xff000000 | r | g | b)); - } -} - -static FASTCALL void -fbFetch_a1r5g5b5 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b, a; - - a = (CARD32) ((CARD8) (0 - ((p & 0x8000) >> 15))) << 24; - r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9; - g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6; - b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2; - WRITE(buffer++, (a | r | g | b)); - } -} - -static FASTCALL void -fbFetch_x1r5g5b5 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b; - - r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9; - g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6; - b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2; - WRITE(buffer++, (0xff000000 | r | g | b)); - } -} - -static FASTCALL void -fbFetch_a1b5g5r5 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b, a; - - a = (CARD32) ((CARD8) (0 - ((p & 0x8000) >> 15))) << 24; - b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7; - g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6; - r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14; - WRITE(buffer++, (a | r | g | b)); - } -} - -static FASTCALL void -fbFetch_x1b5g5r5 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b; - - b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7; - g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6; - r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14; - WRITE(buffer++, (0xff000000 | r | g | b)); - } -} - -static FASTCALL void -fbFetch_a4r4g4b4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b, a; - - a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16; - r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12; - g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8; - b = ((p & 0x000f) | ((p & 0x000f) << 4)); - WRITE(buffer++, (a | r | g | b)); - } -} - -static FASTCALL void -fbFetch_x4r4g4b4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b; - - r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12; - g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8; - b = ((p & 0x000f) | ((p & 0x000f) << 4)); - WRITE(buffer++, (0xff000000 | r | g | b)); - } -} - -static FASTCALL void -fbFetch_a4b4g4r4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b, a; - - a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16; - b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4; - g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8; - r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16; - WRITE(buffer++, (a | r | g | b)); - } -} - -static FASTCALL void -fbFetch_x4b4g4r4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD16 *pixel = (const CARD16 *)bits + x; - const CARD16 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b; - - b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4; - g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8; - r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16; - WRITE(buffer++, (0xff000000 | r | g | b)); - } -} - -static FASTCALL void -fbFetch_a8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + x; - const CARD8 *end = pixel + width; - while (pixel < end) { - WRITE(buffer++, READ(pixel++) << 24); - } -} - -static FASTCALL void -fbFetch_r3g3b2 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + x; - const CARD8 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b; - - r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16; - g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8; - b = (((p & 0x03) ) | - ((p & 0x03) << 2) | - ((p & 0x03) << 4) | - ((p & 0x03) << 6)); - WRITE(buffer++, (0xff000000 | r | g | b)); - } -} - -static FASTCALL void -fbFetch_b2g3r3 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + x; - const CARD8 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 r,g,b; - - b = (((p & 0xc0) ) | - ((p & 0xc0) >> 2) | - ((p & 0xc0) >> 4) | - ((p & 0xc0) >> 6)); - g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8; - r = (((p & 0x07) ) | - ((p & 0x07) << 3) | - ((p & 0x06) << 6)) << 16; - WRITE(buffer++, (0xff000000 | r | g | b)); - } -} - -static FASTCALL void -fbFetch_a2r2g2b2 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + x; - const CARD8 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 a,r,g,b; - - a = ((p & 0xc0) * 0x55) << 18; - r = ((p & 0x30) * 0x55) << 12; - g = ((p & 0x0c) * 0x55) << 6; - b = ((p & 0x03) * 0x55); - WRITE(buffer++, a|r|g|b); - } -} - -static FASTCALL void -fbFetch_a2b2g2r2 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + x; - const CARD8 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - CARD32 a,r,g,b; - - a = ((p & 0xc0) * 0x55) << 18; - b = ((p & 0x30) * 0x55) >> 6; - g = ((p & 0x0c) * 0x55) << 6; - r = ((p & 0x03) * 0x55) << 16; - WRITE(buffer++, a|r|g|b); - } -} - -static FASTCALL void -fbFetch_c8 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + x; - const CARD8 *end = pixel + width; - while (pixel < end) { - CARD32 p = READ(pixel++); - WRITE(buffer++, indexed->rgba[p]); - } -} - -static FASTCALL void -fbFetch_x4a4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - const CARD8 *pixel = (const CARD8 *)bits + x; - const CARD8 *end = pixel + width; - while (pixel < end) { - CARD8 p = READ(pixel++) & 0xf; - WRITE(buffer++, (p | (p << 4)) << 24); - } -} - -#define Fetch8(l,o) (((CARD8 *) (l))[(o) >> 2]) -#if IMAGE_BYTE_ORDER == MSBFirst -#define Fetch4(l,o) ((o) & 2 ? Fetch8(l,o) & 0xf : Fetch8(l,o) >> 4) -#else -#define Fetch4(l,o) ((o) & 2 ? Fetch8(l,o) >> 4 : Fetch8(l,o) & 0xf) -#endif - -static FASTCALL void -fbFetch_a4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 p = Fetch4(bits, i + x); - - p |= p << 4; - WRITE(buffer++, p << 24); - } -} - -static FASTCALL void -fbFetch_r1g2b1 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 p = Fetch4(bits, i + x); - CARD32 r,g,b; - - r = ((p & 0x8) * 0xff) << 13; - g = ((p & 0x6) * 0x55) << 7; - b = ((p & 0x1) * 0xff); - WRITE(buffer++, 0xff000000|r|g|b); - } -} - -static FASTCALL void -fbFetch_b1g2r1 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 p = Fetch4(bits, i + x); - CARD32 r,g,b; - - b = ((p & 0x8) * 0xff) >> 3; - g = ((p & 0x6) * 0x55) << 7; - r = ((p & 0x1) * 0xff) << 16; - WRITE(buffer++, 0xff000000|r|g|b); - } -} - -static FASTCALL void -fbFetch_a1r1g1b1 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 p = Fetch4(bits, i + x); - CARD32 a,r,g,b; - - a = ((p & 0x8) * 0xff) << 21; - r = ((p & 0x4) * 0xff) << 14; - g = ((p & 0x2) * 0xff) << 7; - b = ((p & 0x1) * 0xff); - WRITE(buffer++, a|r|g|b); - } -} - -static FASTCALL void -fbFetch_a1b1g1r1 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 p = Fetch4(bits, i + x); - CARD32 a,r,g,b; - - a = ((p & 0x8) * 0xff) << 21; - r = ((p & 0x4) * 0xff) >> 3; - g = ((p & 0x2) * 0xff) << 7; - b = ((p & 0x1) * 0xff) << 16; - WRITE(buffer++, a|r|g|b); - } -} - -static FASTCALL void -fbFetch_c4 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 p = Fetch4(bits, i + x); - - WRITE(buffer++, indexed->rgba[p]); - } -} - - -static FASTCALL void -fbFetch_a1 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 p = ((CARD32 *)bits)[(i + x) >> 5]; - CARD32 a; -#if BITMAP_BIT_ORDER == MSBFirst - a = p >> (0x1f - ((i+x) & 0x1f)); -#else - a = p >> ((i+x) & 0x1f); -#endif - a = a & 1; - a |= a << 1; - a |= a << 2; - a |= a << 4; - WRITE(buffer++, a << 24); - } -} - -static FASTCALL void -fbFetch_g1 (const FbBits *bits, int x, int width, CARD32 *buffer, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 p = ((CARD32 *)bits)[(i+x) >> 5]; - CARD32 a; -#if BITMAP_BIT_ORDER == MSBFirst - a = p >> (0x1f - ((i+x) & 0x1f)); -#else - a = p >> ((i+x) & 0x1f); -#endif - a = a & 1; - WRITE(buffer++, indexed->rgba[a]); - } -} - -static fetchProc fetchProcForPicture (PicturePtr pict) -{ - switch(pict->format) { - case PICT_a8r8g8b8: return fbFetch_a8r8g8b8; - case PICT_x8r8g8b8: return fbFetch_x8r8g8b8; - case PICT_a8b8g8r8: return fbFetch_a8b8g8r8; - case PICT_x8b8g8r8: return fbFetch_x8b8g8r8; - - /* 24bpp formats */ - case PICT_r8g8b8: return fbFetch_r8g8b8; - case PICT_b8g8r8: return fbFetch_b8g8r8; - - /* 16bpp formats */ - case PICT_r5g6b5: return fbFetch_r5g6b5; - case PICT_b5g6r5: return fbFetch_b5g6r5; - - case PICT_a1r5g5b5: return fbFetch_a1r5g5b5; - case PICT_x1r5g5b5: return fbFetch_x1r5g5b5; - case PICT_a1b5g5r5: return fbFetch_a1b5g5r5; - case PICT_x1b5g5r5: return fbFetch_x1b5g5r5; - case PICT_a4r4g4b4: return fbFetch_a4r4g4b4; - case PICT_x4r4g4b4: return fbFetch_x4r4g4b4; - case PICT_a4b4g4r4: return fbFetch_a4b4g4r4; - case PICT_x4b4g4r4: return fbFetch_x4b4g4r4; - - /* 8bpp formats */ - case PICT_a8: return fbFetch_a8; - case PICT_r3g3b2: return fbFetch_r3g3b2; - case PICT_b2g3r3: return fbFetch_b2g3r3; - case PICT_a2r2g2b2: return fbFetch_a2r2g2b2; - case PICT_a2b2g2r2: return fbFetch_a2b2g2r2; - case PICT_c8: return fbFetch_c8; - case PICT_g8: return fbFetch_c8; - case PICT_x4a4: return fbFetch_x4a4; - - /* 4bpp formats */ - case PICT_a4: return fbFetch_a4; - case PICT_r1g2b1: return fbFetch_r1g2b1; - case PICT_b1g2r1: return fbFetch_b1g2r1; - case PICT_a1r1g1b1: return fbFetch_a1r1g1b1; - case PICT_a1b1g1r1: return fbFetch_a1b1g1r1; - case PICT_c4: return fbFetch_c4; - case PICT_g4: return fbFetch_c4; - - /* 1bpp formats */ - case PICT_a1: return fbFetch_a1; - case PICT_g1: return fbFetch_g1; - } - - return NULL; -} - -/* - * Pixel wise fetching - */ - -typedef FASTCALL CARD32 (*fetchPixelProc)(const FbBits *bits, int offset, miIndexedPtr indexed); - -static FASTCALL CARD32 -fbFetchPixel_a8r8g8b8 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - return READ((CARD32 *)bits + offset); -} - -static FASTCALL CARD32 -fbFetchPixel_x8r8g8b8 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - return READ((CARD32 *)bits + offset) | 0xff000000; -} - -static FASTCALL CARD32 -fbFetchPixel_a8b8g8r8 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD32 *)bits + offset); - - return ((pixel & 0xff000000) | - ((pixel >> 16) & 0xff) | - (pixel & 0x0000ff00) | - ((pixel & 0xff) << 16)); -} - -static FASTCALL CARD32 -fbFetchPixel_x8b8g8r8 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD32 *)bits + offset); - - return ((0xff000000) | - ((pixel >> 16) & 0xff) | - (pixel & 0x0000ff00) | - ((pixel & 0xff) << 16)); -} - -static FASTCALL CARD32 -fbFetchPixel_r8g8b8 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD8 *pixel = ((CARD8 *) bits) + (offset*3); -#if IMAGE_BYTE_ORDER == MSBFirst - return (0xff000000 | - (READ(pixel + 0) << 16) | - (READ(pixel + 1) << 8) | - (READ(pixel + 2))); -#else - return (0xff000000 | - (READ(pixel + 2) << 16) | - (READ(pixel + 1) << 8) | - (READ(pixel + 0))); -#endif -} - -static FASTCALL CARD32 -fbFetchPixel_b8g8r8 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD8 *pixel = ((CARD8 *) bits) + (offset*3); -#if IMAGE_BYTE_ORDER == MSBFirst - return (0xff000000 | - (READ(pixel + 2) << 16) | - (READ(pixel + 1) << 8) | - (READ(pixel + 0))); -#else - return (0xff000000 | - (READ(pixel + 0) << 16) | - (READ(pixel + 1) << 8) | - (READ(pixel + 2))); -#endif -} - -static FASTCALL CARD32 -fbFetchPixel_r5g6b5 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 r,g,b; - - r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8; - g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5; - b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2; - return (0xff000000 | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_b5g6r5 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 r,g,b; - - b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8; - g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5; - r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14; - return (0xff000000 | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_a1r5g5b5 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 a,r,g,b; - - a = (CARD32) ((CARD8) (0 - ((pixel & 0x8000) >> 15))) << 24; - r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9; - g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6; - b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2; - return (a | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_x1r5g5b5 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 r,g,b; - - r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9; - g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6; - b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2; - return (0xff000000 | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_a1b5g5r5 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 a,r,g,b; - - a = (CARD32) ((CARD8) (0 - ((pixel & 0x8000) >> 15))) << 24; - b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7; - g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6; - r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14; - return (a | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_x1b5g5r5 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 r,g,b; - - b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7; - g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6; - r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14; - return (0xff000000 | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_a4r4g4b4 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 a,r,g,b; - - a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16; - r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12; - g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8; - b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)); - return (a | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_x4r4g4b4 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 r,g,b; - - r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12; - g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8; - b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)); - return (0xff000000 | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_a4b4g4r4 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 a,r,g,b; - - a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16; - b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4; - g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8; - r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16; - return (a | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_x4b4g4r4 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD16 *) bits + offset); - CARD32 r,g,b; - - b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4; - g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8; - r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16; - return (0xff000000 | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_a8 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD8 *) bits + offset); - - return pixel << 24; -} - -static FASTCALL CARD32 -fbFetchPixel_r3g3b2 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD8 *) bits + offset); - CARD32 r,g,b; - - r = ((pixel & 0xe0) | ((pixel & 0xe0) >> 3) | ((pixel & 0xc0) >> 6)) << 16; - g = ((pixel & 0x1c) | ((pixel & 0x18) >> 3) | ((pixel & 0x1c) << 3)) << 8; - b = (((pixel & 0x03) ) | - ((pixel & 0x03) << 2) | - ((pixel & 0x03) << 4) | - ((pixel & 0x03) << 6)); - return (0xff000000 | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_b2g3r3 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD8 *) bits + offset); - CARD32 r,g,b; - - b = (((pixel & 0xc0) ) | - ((pixel & 0xc0) >> 2) | - ((pixel & 0xc0) >> 4) | - ((pixel & 0xc0) >> 6)); - g = ((pixel & 0x38) | ((pixel & 0x38) >> 3) | ((pixel & 0x30) << 2)) << 8; - r = (((pixel & 0x07) ) | - ((pixel & 0x07) << 3) | - ((pixel & 0x06) << 6)) << 16; - return (0xff000000 | r | g | b); -} - -static FASTCALL CARD32 -fbFetchPixel_a2r2g2b2 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD8 *) bits + offset); - CARD32 a,r,g,b; - - a = ((pixel & 0xc0) * 0x55) << 18; - r = ((pixel & 0x30) * 0x55) << 12; - g = ((pixel & 0x0c) * 0x55) << 6; - b = ((pixel & 0x03) * 0x55); - return a|r|g|b; -} - -static FASTCALL CARD32 -fbFetchPixel_a2b2g2r2 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD8 *) bits + offset); - CARD32 a,r,g,b; - - a = ((pixel & 0xc0) * 0x55) << 18; - b = ((pixel & 0x30) * 0x55) >> 6; - g = ((pixel & 0x0c) * 0x55) << 6; - r = ((pixel & 0x03) * 0x55) << 16; - return a|r|g|b; -} - -static FASTCALL CARD32 -fbFetchPixel_c8 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD8 *) bits + offset); - return indexed->rgba[pixel]; -} - -static FASTCALL CARD32 -fbFetchPixel_x4a4 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = READ((CARD8 *) bits + offset); - - return ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24; -} - -#define Fetch8(l,o) (((CARD8 *) (l))[(o) >> 2]) -#if IMAGE_BYTE_ORDER == MSBFirst -#define Fetch4(l,o) ((o) & 2 ? Fetch8(l,o) & 0xf : Fetch8(l,o) >> 4) -#else -#define Fetch4(l,o) ((o) & 2 ? Fetch8(l,o) >> 4 : Fetch8(l,o) & 0xf) -#endif - -static FASTCALL CARD32 -fbFetchPixel_a4 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = Fetch4(bits, offset); - - pixel |= pixel << 4; - return pixel << 24; -} - -static FASTCALL CARD32 -fbFetchPixel_r1g2b1 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = Fetch4(bits, offset); - CARD32 r,g,b; - - r = ((pixel & 0x8) * 0xff) << 13; - g = ((pixel & 0x6) * 0x55) << 7; - b = ((pixel & 0x1) * 0xff); - return 0xff000000|r|g|b; -} - -static FASTCALL CARD32 -fbFetchPixel_b1g2r1 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = Fetch4(bits, offset); - CARD32 r,g,b; - - b = ((pixel & 0x8) * 0xff) >> 3; - g = ((pixel & 0x6) * 0x55) << 7; - r = ((pixel & 0x1) * 0xff) << 16; - return 0xff000000|r|g|b; -} - -static FASTCALL CARD32 -fbFetchPixel_a1r1g1b1 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = Fetch4(bits, offset); - CARD32 a,r,g,b; - - a = ((pixel & 0x8) * 0xff) << 21; - r = ((pixel & 0x4) * 0xff) << 14; - g = ((pixel & 0x2) * 0xff) << 7; - b = ((pixel & 0x1) * 0xff); - return a|r|g|b; -} - -static FASTCALL CARD32 -fbFetchPixel_a1b1g1r1 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = Fetch4(bits, offset); - CARD32 a,r,g,b; - - a = ((pixel & 0x8) * 0xff) << 21; - r = ((pixel & 0x4) * 0xff) >> 3; - g = ((pixel & 0x2) * 0xff) << 7; - b = ((pixel & 0x1) * 0xff) << 16; - return a|r|g|b; -} - -static FASTCALL CARD32 -fbFetchPixel_c4 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = Fetch4(bits, offset); - - return indexed->rgba[pixel]; -} - - -static FASTCALL CARD32 -fbFetchPixel_a1 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = ((CARD32 *)bits)[offset >> 5]; - CARD32 a; -#if BITMAP_BIT_ORDER == MSBFirst - a = pixel >> (0x1f - (offset & 0x1f)); -#else - a = pixel >> (offset & 0x1f); -#endif - a = a & 1; - a |= a << 1; - a |= a << 2; - a |= a << 4; - return a << 24; -} - -static FASTCALL CARD32 -fbFetchPixel_g1 (const FbBits *bits, int offset, miIndexedPtr indexed) -{ - CARD32 pixel = ((CARD32 *)bits)[offset >> 5]; - CARD32 a; -#if BITMAP_BIT_ORDER == MSBFirst - a = pixel >> (0x1f - (offset & 0x1f)); -#else - a = pixel >> (offset & 0x1f); -#endif - a = a & 1; - return indexed->rgba[a]; -} - -static fetchPixelProc fetchPixelProcForPicture (PicturePtr pict) -{ - switch(pict->format) { - case PICT_a8r8g8b8: return fbFetchPixel_a8r8g8b8; - case PICT_x8r8g8b8: return fbFetchPixel_x8r8g8b8; - case PICT_a8b8g8r8: return fbFetchPixel_a8b8g8r8; - case PICT_x8b8g8r8: return fbFetchPixel_x8b8g8r8; - - /* 24bpp formats */ - case PICT_r8g8b8: return fbFetchPixel_r8g8b8; - case PICT_b8g8r8: return fbFetchPixel_b8g8r8; - - /* 16bpp formats */ - case PICT_r5g6b5: return fbFetchPixel_r5g6b5; - case PICT_b5g6r5: return fbFetchPixel_b5g6r5; - - case PICT_a1r5g5b5: return fbFetchPixel_a1r5g5b5; - case PICT_x1r5g5b5: return fbFetchPixel_x1r5g5b5; - case PICT_a1b5g5r5: return fbFetchPixel_a1b5g5r5; - case PICT_x1b5g5r5: return fbFetchPixel_x1b5g5r5; - case PICT_a4r4g4b4: return fbFetchPixel_a4r4g4b4; - case PICT_x4r4g4b4: return fbFetchPixel_x4r4g4b4; - case PICT_a4b4g4r4: return fbFetchPixel_a4b4g4r4; - case PICT_x4b4g4r4: return fbFetchPixel_x4b4g4r4; - - /* 8bpp formats */ - case PICT_a8: return fbFetchPixel_a8; - case PICT_r3g3b2: return fbFetchPixel_r3g3b2; - case PICT_b2g3r3: return fbFetchPixel_b2g3r3; - case PICT_a2r2g2b2: return fbFetchPixel_a2r2g2b2; - case PICT_a2b2g2r2: return fbFetchPixel_a2b2g2r2; - case PICT_c8: return fbFetchPixel_c8; - case PICT_g8: return fbFetchPixel_c8; - case PICT_x4a4: return fbFetchPixel_x4a4; - - /* 4bpp formats */ - case PICT_a4: return fbFetchPixel_a4; - case PICT_r1g2b1: return fbFetchPixel_r1g2b1; - case PICT_b1g2r1: return fbFetchPixel_b1g2r1; - case PICT_a1r1g1b1: return fbFetchPixel_a1r1g1b1; - case PICT_a1b1g1r1: return fbFetchPixel_a1b1g1r1; - case PICT_c4: return fbFetchPixel_c4; - case PICT_g4: return fbFetchPixel_c4; - - /* 1bpp formats */ - case PICT_a1: return fbFetchPixel_a1; - case PICT_g1: return fbFetchPixel_g1; - } - - return NULL; -} - - - -/* - * All the store functions - */ - -typedef FASTCALL void (*storeProc) (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed); - -#define Splita(v) CARD32 a = ((v) >> 24), r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff -#define Split(v) CARD32 r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff - -static FASTCALL void -fbStore_a8r8g8b8 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - MEMCPY_WRAPPED(((CARD32 *)bits) + x, values, width*sizeof(CARD32)); -} - -static FASTCALL void -fbStore_x8r8g8b8 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD32 *pixel = (CARD32 *)bits + x; - for (i = 0; i < width; ++i) - WRITE(pixel++, READ(values + i) & 0xffffff); -} - -static FASTCALL void -fbStore_a8b8g8r8 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD32 *pixel = (CARD32 *)bits + x; - for (i = 0; i < width; ++i) - WRITE(pixel++, (READ(values + i) & 0xff00ff00) | ((READ(values + i) >> 16) & 0xff) | ((READ(values + i) & 0xff) << 16)); -} - -static FASTCALL void -fbStore_x8b8g8r8 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD32 *pixel = (CARD32 *)bits + x; - for (i = 0; i < width; ++i) - WRITE(pixel++, (READ(values + i) & 0x0000ff00) | ((READ(values + i) >> 16) & 0xff) | ((READ(values + i) & 0xff) << 16)); -} - -static FASTCALL void -fbStore_r8g8b8 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD8 *pixel = ((CARD8 *) bits) + 3*x; - for (i = 0; i < width; ++i) { - Store24(pixel, READ(values + i)); - pixel += 3; - } -} - -static FASTCALL void -fbStore_b8g8r8 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD8 *pixel = ((CARD8 *) bits) + 3*x; - for (i = 0; i < width; ++i) { - CARD32 val = READ(values + i); -#if IMAGE_BYTE_ORDER == MSBFirst - WRITE(pixel++, Blue(val)); - WRITE(pixel++, Green(val)); - WRITE(pixel++, Red(val)); -#else - WRITE(pixel++, Red(val)); - WRITE(pixel++, Green(val)); - WRITE(pixel++, Blue(val)); -#endif - } -} - -static FASTCALL void -fbStore_r5g6b5 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - CARD32 s = READ(values + i); - WRITE(pixel++, ((s >> 3) & 0x001f) | - ((s >> 5) & 0x07e0) | - ((s >> 8) & 0xf800)); - } -} - -static FASTCALL void -fbStore_b5g6r5 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Split(READ(values + i)); - WRITE(pixel++, ((b << 8) & 0xf800) | - ((g << 3) & 0x07e0) | - ((r >> 3) )); - } -} - -static FASTCALL void -fbStore_a1r5g5b5 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Splita(READ(values + i)); - WRITE(pixel++, ((a << 8) & 0x8000) | - ((r << 7) & 0x7c00) | - ((g << 2) & 0x03e0) | - ((b >> 3) )); - } -} - -static FASTCALL void -fbStore_x1r5g5b5 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Split(READ(values + i)); - WRITE(pixel++, ((r << 7) & 0x7c00) | - ((g << 2) & 0x03e0) | - ((b >> 3) )); - } -} - -static FASTCALL void -fbStore_a1b5g5r5 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Splita(READ(values + i)); - WRITE(pixel++, ((a << 8) & 0x8000) | - ((b << 7) & 0x7c00) | - ((g << 2) & 0x03e0) | - ((r >> 3) )); - } -} - -static FASTCALL void -fbStore_x1b5g5r5 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Split(READ(values + i)); - WRITE(pixel++, ((b << 7) & 0x7c00) | - ((g << 2) & 0x03e0) | - ((r >> 3) )); - } -} - -static FASTCALL void -fbStore_a4r4g4b4 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Splita(READ(values + i)); - WRITE(pixel++, ((a << 8) & 0xf000) | - ((r << 4) & 0x0f00) | - ((g ) & 0x00f0) | - ((b >> 4) )); - } -} - -static FASTCALL void -fbStore_x4r4g4b4 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Split(READ(values + i)); - WRITE(pixel++, ((r << 4) & 0x0f00) | - ((g ) & 0x00f0) | - ((b >> 4) )); - } -} - -static FASTCALL void -fbStore_a4b4g4r4 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Splita(READ(values + i)); - WRITE(pixel++, ((a << 8) & 0xf000) | - ((b << 4) & 0x0f00) | - ((g ) & 0x00f0) | - ((r >> 4) )); - } -} - -static FASTCALL void -fbStore_x4b4g4r4 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD16 *pixel = ((CARD16 *) bits) + x; - for (i = 0; i < width; ++i) { - Split(READ(values + i)); - WRITE(pixel++, ((b << 4) & 0x0f00) | - ((g ) & 0x00f0) | - ((r >> 4) )); - } -} - -static FASTCALL void -fbStore_a8 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD8 *pixel = ((CARD8 *) bits) + x; - for (i = 0; i < width; ++i) { - WRITE(pixel++, READ(values + i) >> 24); - } -} - -static FASTCALL void -fbStore_r3g3b2 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD8 *pixel = ((CARD8 *) bits) + x; - for (i = 0; i < width; ++i) { - Split(READ(values + i)); - WRITE(pixel++, ((r ) & 0xe0) | - ((g >> 3) & 0x1c) | - ((b >> 6) )); - } -} - -static FASTCALL void -fbStore_b2g3r3 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD8 *pixel = ((CARD8 *) bits) + x; - for (i = 0; i < width; ++i) { - Split(READ(values + i)); - WRITE(pixel++, ((b ) & 0xe0) | - ((g >> 3) & 0x1c) | - ((r >> 6) )); - } -} - -static FASTCALL void -fbStore_a2r2g2b2 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD8 *pixel = ((CARD8 *) bits) + x; - for (i = 0; i < width; ++i) { - Splita(READ(values + i)); - WRITE(pixel++, ((a ) & 0xc0) | - ((r >> 2) & 0x30) | - ((g >> 4) & 0x0c) | - ((b >> 6) )); - } -} - -static FASTCALL void -fbStore_c8 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD8 *pixel = ((CARD8 *) bits) + x; - for (i = 0; i < width; ++i) { - WRITE(pixel++, miIndexToEnt24(indexed,READ(values + i))); - } -} - -static FASTCALL void -fbStore_x4a4 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - CARD8 *pixel = ((CARD8 *) bits) + x; - for (i = 0; i < width; ++i) { - WRITE(pixel++, READ(values + i) >> 28); - } -} - -#define Store8(l,o,v) (((CARD8 *) l)[(o) >> 3] = (v)) -#if IMAGE_BYTE_ORDER == MSBFirst -#define Store4(l,o,v) Store8(l,o,((o) & 4 ? \ - (Fetch8(l,o) & 0xf0) | (v) : \ - (Fetch8(l,o) & 0x0f) | ((v) << 4))) -#else -#define Store4(l,o,v) Store8(l,o,((o) & 4 ? \ - (Fetch8(l,o) & 0x0f) | ((v) << 4) : \ - (Fetch8(l,o) & 0xf0) | (v))) -#endif - -static FASTCALL void -fbStore_a4 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - Store4(bits, i + x, READ(values + i)>>28); - } -} - -static FASTCALL void -fbStore_r1g2b1 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 pixel; - - Split(READ(values + i)); - pixel = (((r >> 4) & 0x8) | - ((g >> 5) & 0x6) | - ((b >> 7) )); - Store4(bits, i + x, pixel); - } -} - -static FASTCALL void -fbStore_b1g2r1 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 pixel; - - Split(READ(values + i)); - pixel = (((b >> 4) & 0x8) | - ((g >> 5) & 0x6) | - ((r >> 7) )); - Store4(bits, i + x, pixel); - } -} - -static FASTCALL void -fbStore_a1r1g1b1 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 pixel; - Splita(READ(values + i)); - pixel = (((a >> 4) & 0x8) | - ((r >> 5) & 0x4) | - ((g >> 6) & 0x2) | - ((b >> 7) )); - Store4(bits, i + x, pixel); - } -} - -static FASTCALL void -fbStore_a1b1g1r1 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 pixel; - Splita(READ(values + i)); - pixel = (((a >> 4) & 0x8) | - ((b >> 5) & 0x4) | - ((g >> 6) & 0x2) | - ((r >> 7) )); - Store4(bits, i + x, pixel); - } -} - -static FASTCALL void -fbStore_c4 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 pixel; - - pixel = miIndexToEnt24(indexed, READ(values + i)); - Store4(bits, i + x, pixel); - } -} - -static FASTCALL void -fbStore_a1 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 *pixel = ((CARD32 *) bits) + ((i+x) >> 5); - CARD32 mask = FbStipMask((i+x) & 0x1f, 1); - - CARD32 v = READ(values + i) & 0x80000000 ? mask : 0; - WRITE(pixel, (READ(pixel) & ~mask) | v); - } -} - -static FASTCALL void -fbStore_g1 (FbBits *bits, const CARD32 *values, int x, int width, miIndexedPtr indexed) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 *pixel = ((CARD32 *) bits) + ((i+x) >> 5); - CARD32 mask = FbStipMask((i+x) & 0x1f, 1); - - CARD32 v = miIndexToEntY24(indexed,READ(values + i)) ? mask : 0; - WRITE(pixel, (READ(pixel) & ~mask) | v); - } -} - - -static storeProc storeProcForPicture (PicturePtr pict) -{ - switch(pict->format) { - case PICT_a8r8g8b8: return fbStore_a8r8g8b8; - case PICT_x8r8g8b8: return fbStore_x8r8g8b8; - case PICT_a8b8g8r8: return fbStore_a8b8g8r8; - case PICT_x8b8g8r8: return fbStore_x8b8g8r8; - - /* 24bpp formats */ - case PICT_r8g8b8: return fbStore_r8g8b8; - case PICT_b8g8r8: return fbStore_b8g8r8; - - /* 16bpp formats */ - case PICT_r5g6b5: return fbStore_r5g6b5; - case PICT_b5g6r5: return fbStore_b5g6r5; - - case PICT_a1r5g5b5: return fbStore_a1r5g5b5; - case PICT_x1r5g5b5: return fbStore_x1r5g5b5; - case PICT_a1b5g5r5: return fbStore_a1b5g5r5; - case PICT_x1b5g5r5: return fbStore_x1b5g5r5; - case PICT_a4r4g4b4: return fbStore_a4r4g4b4; - case PICT_x4r4g4b4: return fbStore_x4r4g4b4; - case PICT_a4b4g4r4: return fbStore_a4b4g4r4; - case PICT_x4b4g4r4: return fbStore_x4b4g4r4; - - /* 8bpp formats */ - case PICT_a8: return fbStore_a8; - case PICT_r3g3b2: return fbStore_r3g3b2; - case PICT_b2g3r3: return fbStore_b2g3r3; - case PICT_a2r2g2b2: return fbStore_a2r2g2b2; - case PICT_c8: return fbStore_c8; - case PICT_g8: return fbStore_c8; - case PICT_x4a4: return fbStore_x4a4; - - /* 4bpp formats */ - case PICT_a4: return fbStore_a4; - case PICT_r1g2b1: return fbStore_r1g2b1; - case PICT_b1g2r1: return fbStore_b1g2r1; - case PICT_a1r1g1b1: return fbStore_a1r1g1b1; - case PICT_a1b1g1r1: return fbStore_a1b1g1r1; - case PICT_c4: return fbStore_c4; - case PICT_g4: return fbStore_c4; - - /* 1bpp formats */ - case PICT_a1: return fbStore_a1; - case PICT_g1: return fbStore_g1; - default: - return NULL; - } -} - - -/* - * Combine src and mask - */ -static FASTCALL void -fbCombineMaskU (CARD32 *src, const CARD32 *mask, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 a = READ(mask + i) >> 24; - CARD32 s = READ(src + i); - FbByteMul(s, a); - WRITE(src + i, s); - } -} - -/* - * All of the composing functions - */ - -static FASTCALL void -fbCombineClear (CARD32 *dest, const CARD32 *src, int width) -{ - MEMSET_WRAPPED(dest, 0, width*sizeof(CARD32)); -} - -static FASTCALL void -fbCombineSrcU (CARD32 *dest, const CARD32 *src, int width) -{ - MEMCPY_WRAPPED(dest, src, width*sizeof(CARD32)); -} - - -static FASTCALL void -fbCombineOverU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - CARD32 ia = Alpha(~s); - - FbByteMulAdd(d, ia, s); - WRITE(dest + i, d); - } -} - -static FASTCALL void -fbCombineOverReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - CARD32 ia = Alpha(~READ(dest + i)); - FbByteMulAdd(s, ia, d); - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineInU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 a = Alpha(READ(dest + i)); - FbByteMul(s, a); - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineInReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 d = READ(dest + i); - CARD32 a = Alpha(READ(src + i)); - FbByteMul(d, a); - WRITE(dest + i, d); - } -} - -static FASTCALL void -fbCombineOutU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 a = Alpha(~READ(dest + i)); - FbByteMul(s, a); - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineOutReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 d = READ(dest + i); - CARD32 a = Alpha(~READ(src + i)); - FbByteMul(d, a); - WRITE(dest + i, d); - } -} - -static FASTCALL void -fbCombineAtopU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - CARD32 dest_a = Alpha(d); - CARD32 src_ia = Alpha(~s); - - FbByteAddMul(s, dest_a, d, src_ia); - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineAtopReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - CARD32 src_a = Alpha(s); - CARD32 dest_ia = Alpha(~d); - - FbByteAddMul(s, dest_ia, d, src_a); - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineXorU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - CARD32 src_ia = Alpha(~s); - CARD32 dest_ia = Alpha(~d); - - FbByteAddMul(s, dest_ia, d, src_ia); - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineAddU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - FbByteAdd(d, s); - WRITE(dest + i, d); - } -} - -static FASTCALL void -fbCombineSaturateU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - CARD16 sa, da; - - sa = s >> 24; - da = ~d >> 24; - if (sa > da) - { - sa = FbIntDiv(da, sa); - FbByteMul(s, sa); - } - FbByteAdd(d, s); - WRITE(dest + i, d); - } -} - -/* - * All of the disjoint composing functions - - The four entries in the first column indicate what source contributions - come from each of the four areas of the picture -- areas covered by neither - A nor B, areas covered only by A, areas covered only by B and finally - areas covered by both A and B. - - Disjoint Conjoint - Fa Fb Fa Fb -(0,0,0,0) 0 0 0 0 -(0,A,0,A) 1 0 1 0 -(0,0,B,B) 0 1 0 1 -(0,A,B,A) 1 min((1-a)/b,1) 1 max(1-a/b,0) -(0,A,B,B) min((1-b)/a,1) 1 max(1-b/a,0) 1 -(0,0,0,A) max(1-(1-b)/a,0) 0 min(1,b/a) 0 -(0,0,0,B) 0 max(1-(1-a)/b,0) 0 min(a/b,1) -(0,A,0,0) min(1,(1-b)/a) 0 max(1-b/a,0) 0 -(0,0,B,0) 0 min(1,(1-a)/b) 0 max(1-a/b,0) -(0,0,B,A) max(1-(1-b)/a,0) min(1,(1-a)/b) min(1,b/a) max(1-a/b,0) -(0,A,0,B) min(1,(1-b)/a) max(1-(1-a)/b,0) max(1-b/a,0) min(1,a/b) -(0,A,B,0) min(1,(1-b)/a) min(1,(1-a)/b) max(1-b/a,0) max(1-a/b,0) - - */ - -#define CombineAOut 1 -#define CombineAIn 2 -#define CombineBOut 4 -#define CombineBIn 8 - -#define CombineClear 0 -#define CombineA (CombineAOut|CombineAIn) -#define CombineB (CombineBOut|CombineBIn) -#define CombineAOver (CombineAOut|CombineBOut|CombineAIn) -#define CombineBOver (CombineAOut|CombineBOut|CombineBIn) -#define CombineAAtop (CombineBOut|CombineAIn) -#define CombineBAtop (CombineAOut|CombineBIn) -#define CombineXor (CombineAOut|CombineBOut) - -/* portion covered by a but not b */ -static INLINE CARD8 -fbCombineDisjointOutPart (CARD8 a, CARD8 b) -{ - /* min (1, (1-b) / a) */ - - b = ~b; /* 1 - b */ - if (b >= a) /* 1 - b >= a -> (1-b)/a >= 1 */ - return 0xff; /* 1 */ - return FbIntDiv(b,a); /* (1-b) / a */ -} - -/* portion covered by both a and b */ -static INLINE CARD8 -fbCombineDisjointInPart (CARD8 a, CARD8 b) -{ - /* max (1-(1-b)/a,0) */ - /* = - min ((1-b)/a - 1, 0) */ - /* = 1 - min (1, (1-b)/a) */ - - b = ~b; /* 1 - b */ - if (b >= a) /* 1 - b >= a -> (1-b)/a >= 1 */ - return 0; /* 1 - 1 */ - return ~FbIntDiv(b,a); /* 1 - (1-b) / a */ -} - -static FASTCALL void -fbCombineDisjointGeneralU (CARD32 *dest, const CARD32 *src, int width, CARD8 combine) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - CARD32 m,n,o,p; - CARD16 Fa, Fb, t, u, v; - CARD8 sa = s >> 24; - CARD8 da = d >> 24; - - switch (combine & CombineA) { - default: - Fa = 0; - break; - case CombineAOut: - Fa = fbCombineDisjointOutPart (sa, da); - break; - case CombineAIn: - Fa = fbCombineDisjointInPart (sa, da); - break; - case CombineA: - Fa = 0xff; - break; - } - - switch (combine & CombineB) { - default: - Fb = 0; - break; - case CombineBOut: - Fb = fbCombineDisjointOutPart (da, sa); - break; - case CombineBIn: - Fb = fbCombineDisjointInPart (da, sa); - break; - case CombineB: - Fb = 0xff; - break; - } - m = FbGen (s,d,0,Fa,Fb,t, u, v); - n = FbGen (s,d,8,Fa,Fb,t, u, v); - o = FbGen (s,d,16,Fa,Fb,t, u, v); - p = FbGen (s,d,24,Fa,Fb,t, u, v); - s = m|n|o|p; - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineDisjointOverU (CARD32 *dest, const CARD32 *src, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD16 a = s >> 24; - - if (a != 0x00) - { - if (a != 0xff) - { - CARD32 d = READ(dest + i); - a = fbCombineDisjointOutPart (d >> 24, a); - FbByteMulAdd(d, a, s); - s = d; - } - WRITE(dest + i, s); - } - } -} - -static FASTCALL void -fbCombineDisjointInU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineDisjointGeneralU (dest, src, width, CombineAIn); -} - -static FASTCALL void -fbCombineDisjointInReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineDisjointGeneralU (dest, src, width, CombineBIn); -} - -static FASTCALL void -fbCombineDisjointOutU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineDisjointGeneralU (dest, src, width, CombineAOut); -} - -static FASTCALL void -fbCombineDisjointOutReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineDisjointGeneralU (dest, src, width, CombineBOut); -} - -static FASTCALL void -fbCombineDisjointAtopU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineDisjointGeneralU (dest, src, width, CombineAAtop); -} - -static FASTCALL void -fbCombineDisjointAtopReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineDisjointGeneralU (dest, src, width, CombineBAtop); -} - -static FASTCALL void -fbCombineDisjointXorU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineDisjointGeneralU (dest, src, width, CombineXor); -} - -/* portion covered by a but not b */ -static INLINE CARD8 -fbCombineConjointOutPart (CARD8 a, CARD8 b) -{ - /* max (1-b/a,0) */ - /* = 1-min(b/a,1) */ - - /* min (1, (1-b) / a) */ - - if (b >= a) /* b >= a -> b/a >= 1 */ - return 0x00; /* 0 */ - return ~FbIntDiv(b,a); /* 1 - b/a */ -} - -/* portion covered by both a and b */ -static INLINE CARD8 -fbCombineConjointInPart (CARD8 a, CARD8 b) -{ - /* min (1,b/a) */ - - if (b >= a) /* b >= a -> b/a >= 1 */ - return 0xff; /* 1 */ - return FbIntDiv(b,a); /* b/a */ -} - -static FASTCALL void -fbCombineConjointGeneralU (CARD32 *dest, const CARD32 *src, int width, CARD8 combine) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - CARD32 m,n,o,p; - CARD16 Fa, Fb, t, u, v; - CARD8 sa = s >> 24; - CARD8 da = d >> 24; - - switch (combine & CombineA) { - default: - Fa = 0; - break; - case CombineAOut: - Fa = fbCombineConjointOutPart (sa, da); - break; - case CombineAIn: - Fa = fbCombineConjointInPart (sa, da); - break; - case CombineA: - Fa = 0xff; - break; - } - - switch (combine & CombineB) { - default: - Fb = 0; - break; - case CombineBOut: - Fb = fbCombineConjointOutPart (da, sa); - break; - case CombineBIn: - Fb = fbCombineConjointInPart (da, sa); - break; - case CombineB: - Fb = 0xff; - break; - } - m = FbGen (s,d,0,Fa,Fb,t, u, v); - n = FbGen (s,d,8,Fa,Fb,t, u, v); - o = FbGen (s,d,16,Fa,Fb,t, u, v); - p = FbGen (s,d,24,Fa,Fb,t, u, v); - s = m|n|o|p; - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineConjointOverU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineAOver); -} - - -static FASTCALL void -fbCombineConjointOverReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineBOver); -} - - -static FASTCALL void -fbCombineConjointInU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineAIn); -} - - -static FASTCALL void -fbCombineConjointInReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineBIn); -} - -static FASTCALL void -fbCombineConjointOutU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineAOut); -} - -static FASTCALL void -fbCombineConjointOutReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineBOut); -} - -static FASTCALL void -fbCombineConjointAtopU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineAAtop); -} - -static FASTCALL void -fbCombineConjointAtopReverseU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineBAtop); -} - -static FASTCALL void -fbCombineConjointXorU (CARD32 *dest, const CARD32 *src, int width) -{ - fbCombineConjointGeneralU (dest, src, width, CombineXor); -} - -static CombineFuncU fbCombineFuncU[] = { - fbCombineClear, - fbCombineSrcU, - NULL, /* CombineDst */ - fbCombineOverU, - fbCombineOverReverseU, - fbCombineInU, - fbCombineInReverseU, - fbCombineOutU, - fbCombineOutReverseU, - fbCombineAtopU, - fbCombineAtopReverseU, - fbCombineXorU, - fbCombineAddU, - fbCombineSaturateU, - NULL, - NULL, - fbCombineClear, - fbCombineSrcU, - NULL, /* CombineDst */ - fbCombineDisjointOverU, - fbCombineSaturateU, /* DisjointOverReverse */ - fbCombineDisjointInU, - fbCombineDisjointInReverseU, - fbCombineDisjointOutU, - fbCombineDisjointOutReverseU, - fbCombineDisjointAtopU, - fbCombineDisjointAtopReverseU, - fbCombineDisjointXorU, - NULL, - NULL, - NULL, - NULL, - fbCombineClear, - fbCombineSrcU, - NULL, /* CombineDst */ - fbCombineConjointOverU, - fbCombineConjointOverReverseU, - fbCombineConjointInU, - fbCombineConjointInReverseU, - fbCombineConjointOutU, - fbCombineConjointOutReverseU, - fbCombineConjointAtopU, - fbCombineConjointAtopReverseU, - fbCombineConjointXorU, -}; - -static FASTCALL void -fbCombineMaskC (CARD32 *src, CARD32 *mask, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 a = READ(mask + i); - - CARD32 x; - CARD16 xa; - - if (!a) - { - WRITE(src + i, 0); - continue; - } - - x = READ(src + i); - if (a == 0xffffffff) - { - x = x >> 24; - x |= x << 8; - x |= x << 16; - WRITE(mask + i, x); - continue; - } - - xa = x >> 24; - FbByteMulC(x, a); - WRITE(src + i, x); - FbByteMul(a, xa); - WRITE(mask + i, a); - } -} - -static FASTCALL void -fbCombineMaskValueC (CARD32 *src, const CARD32 *mask, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 a = READ(mask + i); - CARD32 x; - - if (!a) - { - WRITE(src + i, 0); - continue; - } - - if (a == 0xffffffff) - continue; - - x = READ(src + i); - FbByteMulC(x, a); - WRITE(src + i, x); - } -} - - -static FASTCALL void -fbCombineMaskAlphaC (const CARD32 *src, CARD32 *mask, int width) -{ - int i; - for (i = 0; i < width; ++i) { - CARD32 a = READ(mask + i); - CARD32 x; - - if (!a) - continue; - - x = READ(src + i) >> 24; - if (x == 0xff) - continue; - if (a == 0xffffffff) - { - x = x >> 24; - x |= x << 8; - x |= x << 16; - WRITE(mask + i, x); - continue; - } - - FbByteMul(a, x); - WRITE(mask + i, a); - } -} - -static FASTCALL void -fbCombineClearC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - memset(dest, 0, width*sizeof(CARD32)); -} - -static FASTCALL void -fbCombineSrcC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineMaskValueC(src, mask, width); - MEMCPY_WRAPPED(dest, src, width*sizeof(CARD32)); -} - -static FASTCALL void -fbCombineOverC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 a = ~READ(mask + i); - - if (a != 0xffffffff) - { - if (a) - { - CARD32 d = READ(dest + i); - FbByteMulAddC(d, a, s); - s = d; - } - WRITE(dest + i, s); - } - } -} - -static FASTCALL void -fbCombineOverReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskValueC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 d = READ(dest + i); - CARD32 a = ~d >> 24; - - if (a) - { - CARD32 s = READ(src + i); - if (a != 0xff) - { - FbByteMulAdd(s, a, d); - } - WRITE(dest + i, s); - } - } -} - -static FASTCALL void -fbCombineInC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskValueC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 d = READ(dest + i); - CARD16 a = d >> 24; - CARD32 s = 0; - if (a) - { - s = READ(src + i); - if (a != 0xff) - { - FbByteMul(s, a); - } - } - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineInReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskAlphaC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 a = READ(mask + i); - - if (a != 0xffffffff) - { - CARD32 d = 0; - if (a) - { - d = READ(dest + i); - FbByteMulC(d, a); - } - WRITE(dest + i, d); - } - } -} - -static FASTCALL void -fbCombineOutC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskValueC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 d = READ(dest + i); - CARD16 a = ~d >> 24; - CARD32 s = 0; - if (a) - { - s = READ(src + i); - if (a != 0xff) - { - FbByteMul(s, a); - } - } - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineOutReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskAlphaC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 a = ~READ(mask + i); - - if (a != 0xffffffff) - { - CARD32 d = 0; - if (a) - { - d = READ(dest + i); - FbByteMulC(d, a); - } - WRITE(dest + i, d); - } - } -} - -static FASTCALL void -fbCombineAtopC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 d = READ(dest + i); - CARD32 s = READ(src + i); - CARD32 ad = ~READ(mask + i); - CARD16 as = d >> 24; - FbByteAddMulC(d, ad, s, as); - WRITE(dest + i, d); - } -} - -static FASTCALL void -fbCombineAtopReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskC(src, mask, width); - for (i = 0; i < width; ++i) { - - CARD32 d = READ(dest + i); - CARD32 s = READ(src + i); - CARD32 ad = READ(mask + i); - CARD16 as = ~d >> 24; - FbByteAddMulC(d, ad, s, as); - WRITE(dest + i, d); - } -} - -static FASTCALL void -fbCombineXorC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 d = READ(dest + i); - CARD32 s = READ(src + i); - CARD32 ad = ~READ(mask + i); - CARD16 as = ~d >> 24; - FbByteAddMulC(d, ad, s, as); - WRITE(dest + i, d); - } -} - -static FASTCALL void -fbCombineAddC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskValueC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 s = READ(src + i); - CARD32 d = READ(dest + i); - FbByteAdd(d, s); - WRITE(dest + i, d); - } -} - -static FASTCALL void -fbCombineSaturateC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - int i; - fbCombineMaskC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 s, d; - CARD16 sa, sr, sg, sb, da; - CARD16 t, u, v; - CARD32 m,n,o,p; - - d = READ(dest + i); - s = READ(src + i); - sa = (READ(mask + i) >> 24); - sr = (READ(mask + i) >> 16) & 0xff; - sg = (READ(mask + i) >> 8) & 0xff; - sb = (READ(mask + i) ) & 0xff; - da = ~d >> 24; - - if (sb <= da) - m = FbAdd(s,d,0,t); - else - m = FbGen (s, d, 0, (da << 8) / sb, 0xff, t, u, v); - - if (sg <= da) - n = FbAdd(s,d,8,t); - else - n = FbGen (s, d, 8, (da << 8) / sg, 0xff, t, u, v); - - if (sr <= da) - o = FbAdd(s,d,16,t); - else - o = FbGen (s, d, 16, (da << 8) / sr, 0xff, t, u, v); - - if (sa <= da) - p = FbAdd(s,d,24,t); - else - p = FbGen (s, d, 24, (da << 8) / sa, 0xff, t, u, v); - - WRITE(dest + i, m|n|o|p); - } -} - -static FASTCALL void -fbCombineDisjointGeneralC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width, CARD8 combine) -{ - int i; - fbCombineMaskC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 s, d; - CARD32 m,n,o,p; - CARD32 Fa, Fb; - CARD16 t, u, v; - CARD32 sa; - CARD8 da; - - s = READ(src + i); - sa = READ(mask + i); - d = READ(dest + i); - da = d >> 24; - - switch (combine & CombineA) { - default: - Fa = 0; - break; - case CombineAOut: - m = fbCombineDisjointOutPart ((CARD8) (sa >> 0), da); - n = fbCombineDisjointOutPart ((CARD8) (sa >> 8), da) << 8; - o = fbCombineDisjointOutPart ((CARD8) (sa >> 16), da) << 16; - p = fbCombineDisjointOutPart ((CARD8) (sa >> 24), da) << 24; - Fa = m|n|o|p; - break; - case CombineAIn: - m = fbCombineDisjointInPart ((CARD8) (sa >> 0), da); - n = fbCombineDisjointInPart ((CARD8) (sa >> 8), da) << 8; - o = fbCombineDisjointInPart ((CARD8) (sa >> 16), da) << 16; - p = fbCombineDisjointInPart ((CARD8) (sa >> 24), da) << 24; - Fa = m|n|o|p; - break; - case CombineA: - Fa = 0xffffffff; - break; - } - - switch (combine & CombineB) { - default: - Fb = 0; - break; - case CombineBOut: - m = fbCombineDisjointOutPart (da, (CARD8) (sa >> 0)); - n = fbCombineDisjointOutPart (da, (CARD8) (sa >> 8)) << 8; - o = fbCombineDisjointOutPart (da, (CARD8) (sa >> 16)) << 16; - p = fbCombineDisjointOutPart (da, (CARD8) (sa >> 24)) << 24; - Fb = m|n|o|p; - break; - case CombineBIn: - m = fbCombineDisjointInPart (da, (CARD8) (sa >> 0)); - n = fbCombineDisjointInPart (da, (CARD8) (sa >> 8)) << 8; - o = fbCombineDisjointInPart (da, (CARD8) (sa >> 16)) << 16; - p = fbCombineDisjointInPart (da, (CARD8) (sa >> 24)) << 24; - Fb = m|n|o|p; - break; - case CombineB: - Fb = 0xffffffff; - break; - } - m = FbGen (s,d,0,FbGet8(Fa,0),FbGet8(Fb,0),t, u, v); - n = FbGen (s,d,8,FbGet8(Fa,8),FbGet8(Fb,8),t, u, v); - o = FbGen (s,d,16,FbGet8(Fa,16),FbGet8(Fb,16),t, u, v); - p = FbGen (s,d,24,FbGet8(Fa,24),FbGet8(Fb,24),t, u, v); - s = m|n|o|p; - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineDisjointOverC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineDisjointGeneralC (dest, src, mask, width, CombineAOver); -} - -static FASTCALL void -fbCombineDisjointInC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineDisjointGeneralC (dest, src, mask, width, CombineAIn); -} - -static FASTCALL void -fbCombineDisjointInReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineDisjointGeneralC (dest, src, mask, width, CombineBIn); -} - -static FASTCALL void -fbCombineDisjointOutC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineDisjointGeneralC (dest, src, mask, width, CombineAOut); -} - -static FASTCALL void -fbCombineDisjointOutReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineDisjointGeneralC (dest, src, mask, width, CombineBOut); -} - -static FASTCALL void -fbCombineDisjointAtopC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineDisjointGeneralC (dest, src, mask, width, CombineAAtop); -} - -static FASTCALL void -fbCombineDisjointAtopReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineDisjointGeneralC (dest, src, mask, width, CombineBAtop); -} - -static FASTCALL void -fbCombineDisjointXorC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineDisjointGeneralC (dest, src, mask, width, CombineXor); -} - -static FASTCALL void -fbCombineConjointGeneralC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width, CARD8 combine) -{ - int i; - fbCombineMaskC(src, mask, width); - for (i = 0; i < width; ++i) { - CARD32 s, d; - CARD32 m,n,o,p; - CARD32 Fa, Fb; - CARD16 t, u, v; - CARD32 sa; - CARD8 da; - - s = READ(src + i); - sa = READ(mask + i); - d = READ(dest + i); - da = d >> 24; - - switch (combine & CombineA) { - default: - Fa = 0; - break; - case CombineAOut: - m = fbCombineConjointOutPart ((CARD8) (sa >> 0), da); - n = fbCombineConjointOutPart ((CARD8) (sa >> 8), da) << 8; - o = fbCombineConjointOutPart ((CARD8) (sa >> 16), da) << 16; - p = fbCombineConjointOutPart ((CARD8) (sa >> 24), da) << 24; - Fa = m|n|o|p; - break; - case CombineAIn: - m = fbCombineConjointInPart ((CARD8) (sa >> 0), da); - n = fbCombineConjointInPart ((CARD8) (sa >> 8), da) << 8; - o = fbCombineConjointInPart ((CARD8) (sa >> 16), da) << 16; - p = fbCombineConjointInPart ((CARD8) (sa >> 24), da) << 24; - Fa = m|n|o|p; - break; - case CombineA: - Fa = 0xffffffff; - break; - } - - switch (combine & CombineB) { - default: - Fb = 0; - break; - case CombineBOut: - m = fbCombineConjointOutPart (da, (CARD8) (sa >> 0)); - n = fbCombineConjointOutPart (da, (CARD8) (sa >> 8)) << 8; - o = fbCombineConjointOutPart (da, (CARD8) (sa >> 16)) << 16; - p = fbCombineConjointOutPart (da, (CARD8) (sa >> 24)) << 24; - Fb = m|n|o|p; - break; - case CombineBIn: - m = fbCombineConjointInPart (da, (CARD8) (sa >> 0)); - n = fbCombineConjointInPart (da, (CARD8) (sa >> 8)) << 8; - o = fbCombineConjointInPart (da, (CARD8) (sa >> 16)) << 16; - p = fbCombineConjointInPart (da, (CARD8) (sa >> 24)) << 24; - Fb = m|n|o|p; - break; - case CombineB: - Fb = 0xffffffff; - break; - } - m = FbGen (s,d,0,FbGet8(Fa,0),FbGet8(Fb,0),t, u, v); - n = FbGen (s,d,8,FbGet8(Fa,8),FbGet8(Fb,8),t, u, v); - o = FbGen (s,d,16,FbGet8(Fa,16),FbGet8(Fb,16),t, u, v); - p = FbGen (s,d,24,FbGet8(Fa,24),FbGet8(Fb,24),t, u, v); - s = m|n|o|p; - WRITE(dest + i, s); - } -} - -static FASTCALL void -fbCombineConjointOverC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineAOver); -} - -static FASTCALL void -fbCombineConjointOverReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineBOver); -} - -static FASTCALL void -fbCombineConjointInC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineAIn); -} - -static FASTCALL void -fbCombineConjointInReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineBIn); -} - -static FASTCALL void -fbCombineConjointOutC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineAOut); -} - -static FASTCALL void -fbCombineConjointOutReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineBOut); -} - -static FASTCALL void -fbCombineConjointAtopC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineAAtop); -} - -static FASTCALL void -fbCombineConjointAtopReverseC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineBAtop); -} - -static FASTCALL void -fbCombineConjointXorC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) -{ - fbCombineConjointGeneralC (dest, src, mask, width, CombineXor); -} - -static CombineFuncC fbCombineFuncC[] = { - fbCombineClearC, - fbCombineSrcC, - NULL, /* Dest */ - fbCombineOverC, - fbCombineOverReverseC, - fbCombineInC, - fbCombineInReverseC, - fbCombineOutC, - fbCombineOutReverseC, - fbCombineAtopC, - fbCombineAtopReverseC, - fbCombineXorC, - fbCombineAddC, - fbCombineSaturateC, - NULL, - NULL, - fbCombineClearC, /* 0x10 */ - fbCombineSrcC, - NULL, /* Dest */ - fbCombineDisjointOverC, - fbCombineSaturateC, /* DisjointOverReverse */ - fbCombineDisjointInC, - fbCombineDisjointInReverseC, - fbCombineDisjointOutC, - fbCombineDisjointOutReverseC, - fbCombineDisjointAtopC, - fbCombineDisjointAtopReverseC, - fbCombineDisjointXorC, /* 0x1b */ - NULL, - NULL, - NULL, - NULL, - fbCombineClearC, - fbCombineSrcC, - NULL, /* Dest */ - fbCombineConjointOverC, - fbCombineConjointOverReverseC, - fbCombineConjointInC, - fbCombineConjointInReverseC, - fbCombineConjointOutC, - fbCombineConjointOutReverseC, - fbCombineConjointAtopC, - fbCombineConjointAtopReverseC, - fbCombineConjointXorC, -}; - - -FbComposeFunctions composeFunctions = { - fbCombineFuncU, - fbCombineFuncC, - fbCombineMaskU -}; - - -static void fbFetchSolid(PicturePtr pict, int x, int y, int width, CARD32 *buffer) -{ - FbBits *bits; - FbStride stride; - int bpp; - int xoff, yoff; - CARD32 color; - CARD32 *end; - fetchPixelProc fetch = fetchPixelProcForPicture(pict); - miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; - - fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff); - bits += yoff*stride + (xoff*bpp >> FB_SHIFT); - - color = fetch(bits, 0, indexed); - - end = buffer + width; - while (buffer < end) - WRITE(buffer++, color); - fbFinishAccess (pict->pDrawable); -} - -static void fbFetch(PicturePtr pict, int x, int y, int width, CARD32 *buffer) -{ - FbBits *bits; - FbStride stride; - int bpp; - int xoff, yoff; - fetchProc fetch = fetchProcForPicture(pict); - miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; - - fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff); - x += xoff; - y += yoff; - - bits += y*stride; - - fetch(bits, x, width, buffer, indexed); - fbFinishAccess (pict->pDrawable); -} - -#define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b)) -#define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) :\ - ((a) - (b) + 1 - (((b) < 0) << 1)) / (b)) - - -static CARD32 gradientPixel(const SourcePictPtr pGradient, xFixed_48_16 pos, unsigned int spread) -{ - int ipos = (pos * PICT_GRADIENT_STOPTABLE_SIZE - 1) >> 16; - - /* calculate the actual offset. */ - if (ipos < 0 || ipos >= PICT_GRADIENT_STOPTABLE_SIZE) { - if (pGradient->type == SourcePictTypeConical || spread == RepeatNormal) { - ipos = ipos % PICT_GRADIENT_STOPTABLE_SIZE; - ipos = ipos < 0 ? PICT_GRADIENT_STOPTABLE_SIZE + ipos : ipos; - - } else if (spread == RepeatReflect) { - const int limit = PICT_GRADIENT_STOPTABLE_SIZE * 2 - 1; - ipos = ipos % limit; - ipos = ipos < 0 ? limit + ipos : ipos; - ipos = ipos >= PICT_GRADIENT_STOPTABLE_SIZE ? limit - ipos : ipos; - - } else if (spread == RepeatPad) { - if (ipos < 0) - ipos = 0; - else if (ipos >= PICT_GRADIENT_STOPTABLE_SIZE) - ipos = PICT_GRADIENT_STOPTABLE_SIZE-1; - } else { /* RepeatNone */ - return 0; - } - } - - assert(ipos >= 0); - assert(ipos < PICT_GRADIENT_STOPTABLE_SIZE); - - return pGradient->linear.colorTable[ipos]; -} - -static void fbFetchSourcePict(PicturePtr pict, int x, int y, int width, CARD32 *buffer) -{ - SourcePictPtr pGradient = pict->pSourcePict; - CARD32 *end = buffer + width; - - if (pGradient->type == SourcePictTypeSolidFill) { - register CARD32 color = pGradient->solidFill.color; - while (buffer < end) { - WRITE(buffer++, color); - } - } else if (pGradient->type == SourcePictTypeLinear) { - PictVector v, unit; - xFixed_32_32 l; - xFixed_48_16 dx, dy, a, b, off; - - /* reference point is the center of the pixel */ - v.vector[0] = IntToxFixed(x) + xFixed1/2; - v.vector[1] = IntToxFixed(y) + xFixed1/2; - v.vector[2] = xFixed1; - if (pict->transform) { - if (!PictureTransformPoint3d (pict->transform, &v)) - return; - unit.vector[0] = pict->transform->matrix[0][0]; - unit.vector[1] = pict->transform->matrix[1][0]; - unit.vector[2] = pict->transform->matrix[2][0]; - } else { - unit.vector[0] = xFixed1; - unit.vector[1] = 0; - unit.vector[2] = 0; - } - - dx = pGradient->linear.p2.x - pGradient->linear.p1.x; - dy = pGradient->linear.p2.y - pGradient->linear.p1.y; - l = dx*dx + dy*dy; - if (l != 0) { - a = (dx << 32) / l; - b = (dy << 32) / l; - off = (-a*pGradient->linear.p1.x - b*pGradient->linear.p1.y)>>16; - } - if (l == 0 || (unit.vector[2] == 0 && v.vector[2] == xFixed1)) { - xFixed_48_16 inc, t; - /* affine transformation only */ - if (l == 0) { - t = 0; - inc = 0; - } else { - t = ((a*v.vector[0] + b*v.vector[1]) >> 16) + off; - inc = (a * unit.vector[0] + b * unit.vector[1]) >> 16; - } - while (buffer < end) { - WRITE(buffer++, gradientPixel(pGradient, t, pict->repeatType)); - t += inc; - } - } else { - /* projective transformation */ - while (buffer < end) { - xFixed_48_16 t; - if (v.vector[2] == 0) { - t = 0; - } else { - xFixed_48_16 x, y; - x = ((xFixed_48_16)v.vector[0] << 16) / v.vector[2]; - y = ((xFixed_48_16)v.vector[1] << 16) / v.vector[2]; - t = ((a*x + b*y) >> 16) + off; - } - WRITE(buffer++, gradientPixel(pGradient, t, pict->repeatType)); - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } - } else { - /* radial or conical */ - Bool affine = TRUE; - double cx = 1.; - double cy = 0.; - double cz = 0.; - double rx = x; - double ry = y; - double rz = 1.; - - if (pict->transform) { - PictVector v; - /* reference point is the center of the pixel */ - v.vector[0] = IntToxFixed(x) + xFixed1/2; - v.vector[1] = IntToxFixed(y) + xFixed1/2; - v.vector[2] = xFixed1; - if (!PictureTransformPoint3d (pict->transform, &v)) - return; - - cx = pict->transform->matrix[0][0]/65536.; - cy = pict->transform->matrix[1][0]/65536.; - cz = pict->transform->matrix[2][0]/65536.; - rx = v.vector[0]/65536.; - ry = v.vector[1]/65536.; - rz = v.vector[2]/65536.; - affine = pict->transform->matrix[2][0] == 0 && v.vector[2] == xFixed1; - } - - if (pGradient->type == SourcePictTypeRadial) { - if (affine) { - rx -= pGradient->radial.fx; - ry -= pGradient->radial.fy; - - while (buffer < end) { - double b = 2*(rx*pGradient->radial.dx + ry*pGradient->radial.dy); - double c = -(rx*rx + ry*ry); - double det = (b * b) - (4 * pGradient->radial.a * c); - double s = (-b + sqrt(det))/(2. * pGradient->radial.a); - WRITE(buffer, gradientPixel(pGradient, - (xFixed_48_16)((s*pGradient->radial.m + pGradient->radial.b)*65536), - pict->repeatType)); - ++buffer; - rx += cx; - ry += cy; - } - } else { - while (buffer < end) { - double x, y; - double b, c, det, s; - if (rz != 0) { - x = rx/rz; - y = ry/rz; - } else { - x = y = 0.; - } - x -= pGradient->radial.fx; - y -= pGradient->radial.fy; - b = 2*(x*pGradient->radial.dx + y*pGradient->radial.dy); - c = -(x*x + y*y); - det = (b * b) - (4 * pGradient->radial.a * c); - s = (-b + sqrt(det))/(2. * pGradient->radial.a); - WRITE(buffer, gradientPixel(pGradient, - (xFixed_48_16)((s*pGradient->radial.m + pGradient->radial.b)*65536), - pict->repeatType)); - ++buffer; - rx += cx; - ry += cy; - rz += cz; - } - } - } else /* SourcePictTypeConical */ { - double a = pGradient->conical.angle/(180.*65536); - if (affine) { - rx -= pGradient->conical.center.x/65536.; - ry -= pGradient->conical.center.y/65536.; - - while (buffer < end) { - double angle = atan2(ry, rx) + a; - WRITE(buffer, gradientPixel(pGradient, (xFixed_48_16) (angle * (65536. / (2*M_PI))), - pict->repeatType)); - ++buffer; - rx += cx; - ry += cy; - } - } else { - - while (buffer < end) { - double x, y, angle; - if (rz != 0) { - x = rx/rz; - y = ry/rz; - } else { - x = y = 0.; - } - x -= pGradient->conical.center.x/65536.; - y -= pGradient->conical.center.y/65536.; - angle = atan2(y, x) + a; - WRITE(buffer, gradientPixel(pGradient, (xFixed_48_16) (angle * (65536. / (2*M_PI))), - pict->repeatType)); - ++buffer; - rx += cx; - ry += cy; - rz += cz; - } - } - } - } -} - - - -static void fbFetchTransformed(PicturePtr pict, int x, int y, int width, CARD32 *buffer) -{ - FbBits *bits; - FbStride stride; - int bpp; - int xoff, yoff, dx, dy; - fetchPixelProc fetch; - PictVector v; - PictVector unit; - int i; - BoxRec box; - miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; - Bool affine = TRUE; - - fetch = fetchPixelProcForPicture(pict); - - fbGetDrawable(pict->pDrawable, bits, stride, bpp, xoff, yoff); - x += xoff; - y += yoff; - - dx = pict->pDrawable->x; - dy = pict->pDrawable->y; - - /* reference point is the center of the pixel */ - v.vector[0] = IntToxFixed(x - dx) + xFixed1 / 2; - v.vector[1] = IntToxFixed(y - dy) + xFixed1 / 2; - v.vector[2] = xFixed1; - - /* when using convolution filters one might get here without a transform */ - if (pict->transform) { - if (!PictureTransformPoint3d (pict->transform, &v)) { - fbFinishAccess (pict->pDrawable); - return; - } - unit.vector[0] = pict->transform->matrix[0][0]; - unit.vector[1] = pict->transform->matrix[1][0]; - unit.vector[2] = pict->transform->matrix[2][0]; - affine = v.vector[2] == xFixed1 && unit.vector[2] == 0; - } else { - unit.vector[0] = xFixed1; - unit.vector[1] = 0; - unit.vector[2] = 0; - } - - if (pict->filter == PictFilterNearest) - { - if (pict->repeatType == RepeatNormal) { - if (REGION_NUM_RECTS(pict->pCompositeClip) == 1) { - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - if (!affine) { - y = MOD(DIV(v.vector[1],v.vector[2]), pict->pDrawable->height); - x = MOD(DIV(v.vector[0],v.vector[2]), pict->pDrawable->width); - } else { - y = MOD(v.vector[1]>>16, pict->pDrawable->height); - x = MOD(v.vector[0]>>16, pict->pDrawable->width); - } - WRITE(buffer + i, fetch(bits + (y + dy)*stride, x + dx, indexed)); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } else { - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - if (!affine) { - y = MOD(DIV(v.vector[1],v.vector[2]), pict->pDrawable->height); - x = MOD(DIV(v.vector[0],v.vector[2]), pict->pDrawable->width); - } else { - y = MOD(v.vector[1]>>16, pict->pDrawable->height); - x = MOD(v.vector[0]>>16, pict->pDrawable->width); - } - if (POINT_IN_REGION (0, pict->pCompositeClip, x + dx, y + dy, &box)) - WRITE(buffer + i, fetch(bits + (y + dy)*stride, x + dx, indexed)); - else - WRITE(buffer + i, 0); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } - } else { - if (REGION_NUM_RECTS(pict->pCompositeClip) == 1) { - box = pict->pCompositeClip->extents; - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - if (!affine) { - y = DIV(v.vector[1],v.vector[2]); - x = DIV(v.vector[0],v.vector[2]); - } else { - y = v.vector[1]>>16; - x = v.vector[0]>>16; - } - WRITE(buffer + i, ((x < box.x1-dx) | (x >= box.x2-dx) | (y < box.y1-dy) | (y >= box.y2-dy)) ? - 0 : fetch(bits + (y + dy)*stride, x + dx, indexed)); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } else { - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - if (!affine) { - y = DIV(v.vector[1],v.vector[2]); - x = DIV(v.vector[0],v.vector[2]); - } else { - y = v.vector[1]>>16; - x = v.vector[0]>>16; - } - if (POINT_IN_REGION (0, pict->pCompositeClip, x + dx, y + dy, &box)) - WRITE(buffer + i, fetch(bits + (y + dy)*stride, x + dx, indexed)); - else - WRITE(buffer + i, 0); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } - } - } else if (pict->filter == PictFilterBilinear) { - /* adjust vector for maximum contribution at 0.5, 0.5 of each texel. */ - v.vector[0] -= v.vector[2] / 2; - v.vector[1] -= v.vector[2] / 2; - unit.vector[0] -= unit.vector[2] / 2; - unit.vector[1] -= unit.vector[2] / 2; - - if (pict->repeatType == RepeatNormal) { - if (REGION_NUM_RECTS(pict->pCompositeClip) == 1) { - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - int x1, x2, y1, y2, distx, idistx, disty, idisty; - FbBits *b; - CARD32 tl, tr, bl, br, r; - CARD32 ft, fb; - - if (!affine) { - xFixed_48_16 div; - div = ((xFixed_48_16)v.vector[0] << 16)/v.vector[2]; - x1 = div >> 16; - distx = ((xFixed)div >> 8) & 0xff; - div = ((xFixed_48_16)v.vector[1] << 16)/v.vector[2]; - y1 = div >> 16; - disty = ((xFixed)div >> 8) & 0xff; - } else { - x1 = v.vector[0] >> 16; - distx = (v.vector[0] >> 8) & 0xff; - y1 = v.vector[1] >> 16; - disty = (v.vector[1] >> 8) & 0xff; - } - x2 = x1 + 1; - y2 = y1 + 1; - - idistx = 256 - distx; - idisty = 256 - disty; - - x1 = MOD (x1, pict->pDrawable->width); - x2 = MOD (x2, pict->pDrawable->width); - y1 = MOD (y1, pict->pDrawable->height); - y2 = MOD (y2, pict->pDrawable->height); - - b = bits + (y1 + dy)*stride; - - tl = fetch(b, x1 + dx, indexed); - tr = fetch(b, x2 + dx, indexed); - b = bits + (y2 + dy)*stride; - bl = fetch(b, x1 + dx, indexed); - br = fetch(b, x2 + dx, indexed); - - ft = FbGet8(tl,0) * idistx + FbGet8(tr,0) * distx; - fb = FbGet8(bl,0) * idistx + FbGet8(br,0) * distx; - r = (((ft * idisty + fb * disty) >> 16) & 0xff); - ft = FbGet8(tl,8) * idistx + FbGet8(tr,8) * distx; - fb = FbGet8(bl,8) * idistx + FbGet8(br,8) * distx; - r |= (((ft * idisty + fb * disty) >> 8) & 0xff00); - ft = FbGet8(tl,16) * idistx + FbGet8(tr,16) * distx; - fb = FbGet8(bl,16) * idistx + FbGet8(br,16) * distx; - r |= (((ft * idisty + fb * disty)) & 0xff0000); - ft = FbGet8(tl,24) * idistx + FbGet8(tr,24) * distx; - fb = FbGet8(bl,24) * idistx + FbGet8(br,24) * distx; - r |= (((ft * idisty + fb * disty) << 8) & 0xff000000); - WRITE(buffer + i, r); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } else { - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - int x1, x2, y1, y2, distx, idistx, disty, idisty; - FbBits *b; - CARD32 tl, tr, bl, br, r; - CARD32 ft, fb; - - if (!affine) { - xFixed_48_16 div; - div = ((xFixed_48_16)v.vector[0] << 16)/v.vector[2]; - x1 = div >> 16; - distx = ((xFixed)div >> 8) & 0xff; - div = ((xFixed_48_16)v.vector[1] << 16)/v.vector[2]; - y1 = div >> 16; - disty = ((xFixed)div >> 8) & 0xff; - } else { - x1 = v.vector[0] >> 16; - distx = (v.vector[0] >> 8) & 0xff; - y1 = v.vector[1] >> 16; - disty = (v.vector[1] >> 8) & 0xff; - } - x2 = x1 + 1; - y2 = y1 + 1; - - idistx = 256 - distx; - idisty = 256 - disty; - - x1 = MOD (x1, pict->pDrawable->width); - x2 = MOD (x2, pict->pDrawable->width); - y1 = MOD (y1, pict->pDrawable->height); - y2 = MOD (y2, pict->pDrawable->height); - - b = bits + (y1 + dy)*stride; - - tl = POINT_IN_REGION(0, pict->pCompositeClip, x1 + dx, y1 + dy, &box) - ? fetch(b, x1 + dx, indexed) : 0; - tr = POINT_IN_REGION(0, pict->pCompositeClip, x2 + dx, y1 + dy, &box) - ? fetch(b, x2 + dx, indexed) : 0; - b = bits + (y2 + dy)*stride; - bl = POINT_IN_REGION(0, pict->pCompositeClip, x1 + dx, y2 + dy, &box) - ? fetch(b, x1 + dx, indexed) : 0; - br = POINT_IN_REGION(0, pict->pCompositeClip, x2 + dx, y2 + dy, &box) - ? fetch(b, x2 + dx, indexed) : 0; - - ft = FbGet8(tl,0) * idistx + FbGet8(tr,0) * distx; - fb = FbGet8(bl,0) * idistx + FbGet8(br,0) * distx; - r = (((ft * idisty + fb * disty) >> 16) & 0xff); - ft = FbGet8(tl,8) * idistx + FbGet8(tr,8) * distx; - fb = FbGet8(bl,8) * idistx + FbGet8(br,8) * distx; - r |= (((ft * idisty + fb * disty) >> 8) & 0xff00); - ft = FbGet8(tl,16) * idistx + FbGet8(tr,16) * distx; - fb = FbGet8(bl,16) * idistx + FbGet8(br,16) * distx; - r |= (((ft * idisty + fb * disty)) & 0xff0000); - ft = FbGet8(tl,24) * idistx + FbGet8(tr,24) * distx; - fb = FbGet8(bl,24) * idistx + FbGet8(br,24) * distx; - r |= (((ft * idisty + fb * disty) << 8) & 0xff000000); - WRITE(buffer + i, r); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } - } else { - if (REGION_NUM_RECTS(pict->pCompositeClip) == 1) { - box = pict->pCompositeClip->extents; - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - int x1, x2, y1, y2, distx, idistx, disty, idisty, x_off; - FbBits *b; - CARD32 tl, tr, bl, br, r; - Bool x1_out, x2_out, y1_out, y2_out; - CARD32 ft, fb; - - if (!affine) { - xFixed_48_16 div; - div = ((xFixed_48_16)v.vector[0] << 16)/v.vector[2]; - x1 = div >> 16; - distx = ((xFixed)div >> 8) & 0xff; - div = ((xFixed_48_16)v.vector[1] << 16)/v.vector[2]; - y1 = div >> 16; - disty = ((xFixed)div >> 8) & 0xff; - } else { - x1 = v.vector[0] >> 16; - distx = (v.vector[0] >> 8) & 0xff; - y1 = v.vector[1] >> 16; - disty = (v.vector[1] >> 8) & 0xff; - } - x2 = x1 + 1; - y2 = y1 + 1; - - idistx = 256 - distx; - idisty = 256 - disty; - - b = bits + (y1 + dy)*stride; - x_off = x1 + dx; - - x1_out = (x1 < box.x1-dx) | (x1 >= box.x2-dx); - x2_out = (x2 < box.x1-dx) | (x2 >= box.x2-dx); - y1_out = (y1 < box.y1-dy) | (y1 >= box.y2-dy); - y2_out = (y2 < box.y1-dy) | (y2 >= box.y2-dy); - - tl = x1_out|y1_out ? 0 : fetch(b, x_off, indexed); - tr = x2_out|y1_out ? 0 : fetch(b, x_off + 1, indexed); - b += stride; - bl = x1_out|y2_out ? 0 : fetch(b, x_off, indexed); - br = x2_out|y2_out ? 0 : fetch(b, x_off + 1, indexed); - - ft = FbGet8(tl,0) * idistx + FbGet8(tr,0) * distx; - fb = FbGet8(bl,0) * idistx + FbGet8(br,0) * distx; - r = (((ft * idisty + fb * disty) >> 16) & 0xff); - ft = FbGet8(tl,8) * idistx + FbGet8(tr,8) * distx; - fb = FbGet8(bl,8) * idistx + FbGet8(br,8) * distx; - r |= (((ft * idisty + fb * disty) >> 8) & 0xff00); - ft = FbGet8(tl,16) * idistx + FbGet8(tr,16) * distx; - fb = FbGet8(bl,16) * idistx + FbGet8(br,16) * distx; - r |= (((ft * idisty + fb * disty)) & 0xff0000); - ft = FbGet8(tl,24) * idistx + FbGet8(tr,24) * distx; - fb = FbGet8(bl,24) * idistx + FbGet8(br,24) * distx; - r |= (((ft * idisty + fb * disty) << 8) & 0xff000000); - WRITE(buffer + i, r); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } else { - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - int x1, x2, y1, y2, distx, idistx, disty, idisty, x_off; - FbBits *b; - CARD32 tl, tr, bl, br, r; - CARD32 ft, fb; - - if (!affine) { - xFixed_48_16 div; - div = ((xFixed_48_16)v.vector[0] << 16)/v.vector[2]; - x1 = div >> 16; - distx = ((xFixed)div >> 8) & 0xff; - div = ((xFixed_48_16)v.vector[1] << 16)/v.vector[2]; - y1 = div >> 16; - disty = ((xFixed)div >> 8) & 0xff; - } else { - x1 = v.vector[0] >> 16; - distx = (v.vector[0] >> 8) & 0xff; - y1 = v.vector[1] >> 16; - disty = (v.vector[1] >> 8) & 0xff; - } - x2 = x1 + 1; - y2 = y1 + 1; - - idistx = 256 - distx; - idisty = 256 - disty; - - b = bits + (y1 + dy)*stride; - x_off = x1 + dx; - - tl = POINT_IN_REGION(0, pict->pCompositeClip, x1 + dx, y1 + dy, &box) - ? fetch(b, x_off, indexed) : 0; - tr = POINT_IN_REGION(0, pict->pCompositeClip, x2 + dx, y1 + dy, &box) - ? fetch(b, x_off + 1, indexed) : 0; - b += stride; - bl = POINT_IN_REGION(0, pict->pCompositeClip, x1 + dx, y2 + dy, &box) - ? fetch(b, x_off, indexed) : 0; - br = POINT_IN_REGION(0, pict->pCompositeClip, x2 + dx, y2 + dy, &box) - ? fetch(b, x_off + 1, indexed) : 0; - - ft = FbGet8(tl,0) * idistx + FbGet8(tr,0) * distx; - fb = FbGet8(bl,0) * idistx + FbGet8(br,0) * distx; - r = (((ft * idisty + fb * disty) >> 16) & 0xff); - ft = FbGet8(tl,8) * idistx + FbGet8(tr,8) * distx; - fb = FbGet8(bl,8) * idistx + FbGet8(br,8) * distx; - r |= (((ft * idisty + fb * disty) >> 8) & 0xff00); - ft = FbGet8(tl,16) * idistx + FbGet8(tr,16) * distx; - fb = FbGet8(bl,16) * idistx + FbGet8(br,16) * distx; - r |= (((ft * idisty + fb * disty)) & 0xff0000); - ft = FbGet8(tl,24) * idistx + FbGet8(tr,24) * distx; - fb = FbGet8(bl,24) * idistx + FbGet8(br,24) * distx; - r |= (((ft * idisty + fb * disty) << 8) & 0xff000000); - WRITE(buffer + i, r); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } - } - } else if (pict->filter == PictFilterConvolution) { - xFixed *params = pict->filter_params; - INT32 cwidth = xFixedToInt(params[0]); - INT32 cheight = xFixedToInt(params[1]); - int xoff = (params[0] - xFixed1) >> 1; - int yoff = (params[1] - xFixed1) >> 1; - params += 2; - for (i = 0; i < width; ++i) { - if (!v.vector[2]) { - WRITE(buffer + i, 0); - } else { - int x1, x2, y1, y2, x, y; - INT32 srtot, sgtot, sbtot, satot; - xFixed *p = params; - - if (!affine) { - xFixed_48_16 tmp; - tmp = ((xFixed_48_16)v.vector[0] << 16)/v.vector[2] - xoff; - x1 = xFixedToInt(tmp); - tmp = ((xFixed_48_16)v.vector[1] << 16)/v.vector[2] - yoff; - y1 = xFixedToInt(tmp); - } else { - x1 = xFixedToInt(v.vector[0] - xoff); - y1 = xFixedToInt(v.vector[1] - yoff); - } - x2 = x1 + cwidth; - y2 = y1 + cheight; - - srtot = sgtot = sbtot = satot = 0; - - for (y = y1; y < y2; y++) { - int ty = (pict->repeatType == RepeatNormal) ? MOD (y, pict->pDrawable->height) : y; - for (x = x1; x < x2; x++) { - if (*p) { - int tx = (pict->repeatType == RepeatNormal) ? MOD (x, pict->pDrawable->width) : x; - if (POINT_IN_REGION (0, pict->pCompositeClip, tx + dx, ty + dy, &box)) { - FbBits *b = bits + (ty + dy)*stride; - CARD32 c = fetch(b, tx + dx, indexed); - - srtot += Red(c) * *p; - sgtot += Green(c) * *p; - sbtot += Blue(c) * *p; - satot += Alpha(c) * *p; - } - } - p++; - } - } - - satot >>= 16; - srtot >>= 16; - sgtot >>= 16; - sbtot >>= 16; - - if (satot < 0) satot = 0; else if (satot > 0xff) satot = 0xff; - if (srtot < 0) srtot = 0; else if (srtot > 0xff) srtot = 0xff; - if (sgtot < 0) sgtot = 0; else if (sgtot > 0xff) sgtot = 0xff; - if (sbtot < 0) sbtot = 0; else if (sbtot > 0xff) sbtot = 0xff; - - WRITE(buffer + i, ((satot << 24) | - (srtot << 16) | - (sgtot << 8) | - (sbtot ))); - } - v.vector[0] += unit.vector[0]; - v.vector[1] += unit.vector[1]; - v.vector[2] += unit.vector[2]; - } - } - - fbFinishAccess (pict->pDrawable); -} - - -static void fbFetchExternalAlpha(PicturePtr pict, int x, int y, int width, CARD32 *buffer) -{ - int i; - CARD32 _alpha_buffer[SCANLINE_BUFFER_LENGTH]; - CARD32 *alpha_buffer = _alpha_buffer; - - if (!pict->alphaMap) { - fbFetchTransformed(pict, x, y, width, buffer); - return; - } - if (width > SCANLINE_BUFFER_LENGTH) - alpha_buffer = (CARD32 *) malloc(width*sizeof(CARD32)); - - fbFetchTransformed(pict, x, y, width, buffer); - fbFetchTransformed(pict->alphaMap, x - pict->alphaOrigin.x, y - pict->alphaOrigin.y, width, alpha_buffer); - for (i = 0; i < width; ++i) { - int a = alpha_buffer[i]>>24; - WRITE(buffer + i, (a << 24) - | (div_255(Red(READ(buffer + i)) * a) << 16) - | (div_255(Green(READ(buffer + i)) * a) << 8) - | (div_255(Blue(READ(buffer + i)) * a))); - } - - if (alpha_buffer != _alpha_buffer) - free(alpha_buffer); -} - -static void fbStore(PicturePtr pict, int x, int y, int width, CARD32 *buffer) -{ - FbBits *bits; - FbStride stride; - int bpp; - int xoff, yoff; - storeProc store = storeProcForPicture(pict); - miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; - - fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff); - x += xoff; - y += yoff; - - bits += y*stride; - store(bits, buffer, x, width, indexed); - fbFinishAccess (pict->pDrawable); -} - -static void fbStoreExternalAlpha(PicturePtr pict, int x, int y, int width, CARD32 *buffer) -{ - FbBits *bits, *alpha_bits; - FbStride stride, astride; - int bpp, abpp; - int xoff, yoff; - int ax, ay; - storeProc store; - storeProc astore; - miIndexedPtr indexed = (miIndexedPtr) pict->pFormat->index.devPrivate; - miIndexedPtr aindexed; - - if (!pict->alphaMap) { - fbStore(pict, x, y, width, buffer); - return; - } - - store = storeProcForPicture(pict); - astore = storeProcForPicture(pict->alphaMap); - aindexed = (miIndexedPtr) pict->alphaMap->pFormat->index.devPrivate; - - ax = x; - ay = y; - - fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff); - x += xoff; - y += yoff; - fbGetDrawable (pict->alphaMap->pDrawable, alpha_bits, astride, abpp, xoff, yoff); - ax += xoff; - ay += yoff; - - bits += y*stride; - alpha_bits += (ay - pict->alphaOrigin.y)*astride; - - - store(bits, buffer, x, width, indexed); - astore(alpha_bits, buffer, ax - pict->alphaOrigin.x, width, aindexed); - - fbFinishAccess (pict->alphaMap->pDrawable); - fbFinishAccess (pict->pDrawable); -} - -typedef void (*scanStoreProc)(PicturePtr , int , int , int , CARD32 *); -typedef void (*scanFetchProc)(PicturePtr , int , int , int , CARD32 *); - -static void -fbCompositeRect (const FbComposeData *data, CARD32 *scanline_buffer) -{ - CARD32 *src_buffer = scanline_buffer; - CARD32 *dest_buffer = src_buffer + data->width; - int i; - scanStoreProc store; - scanFetchProc fetchSrc = NULL, fetchMask = NULL, fetchDest = NULL; - - if (data->op == PictOpClear) - fetchSrc = NULL; - else if (!data->src->pDrawable) { - if (data->src->pSourcePict) - fetchSrc = fbFetchSourcePict; - } else if (data->src->alphaMap) - fetchSrc = fbFetchExternalAlpha; - else if (data->src->repeatType == RepeatNormal && - data->src->pDrawable->width == 1 && data->src->pDrawable->height == 1) - fetchSrc = fbFetchSolid; - else if (!data->src->transform && data->src->filter != PictFilterConvolution) - fetchSrc = fbFetch; - else - fetchSrc = fbFetchTransformed; - - if (data->mask && data->op != PictOpClear) { - if (!data->mask->pDrawable) { - if (data->mask->pSourcePict) - fetchMask = fbFetchSourcePict; - } else if (data->mask->alphaMap) - fetchMask = fbFetchExternalAlpha; - else if (data->mask->repeatType == RepeatNormal - && data->mask->pDrawable->width == 1 && data->mask->pDrawable->height == 1) - fetchMask = fbFetchSolid; - else if (!data->mask->transform && data->mask->filter != PictFilterConvolution) - fetchMask = fbFetch; - else - fetchMask = fbFetchTransformed; - } else { - fetchMask = NULL; - } - - if (data->dest->alphaMap) { - fetchDest = fbFetchExternalAlpha; - store = fbStoreExternalAlpha; - } else { - fetchDest = fbFetch; - store = fbStore; - } - if (data->op == PictOpClear || data->op == PictOpSrc) - fetchDest = NULL; - - if (fetchSrc && fetchMask && data->mask && data->mask->componentAlpha && PICT_FORMAT_RGB(data->mask->format)) { - CARD32 *mask_buffer = dest_buffer + data->width; - CombineFuncC compose = composeFunctions.combineC[data->op]; - if (!compose) - return; - - for (i = 0; i < data->height; ++i) - { - /* fill first half of scanline with source */ - fetchSrc(data->src, data->xSrc, data->ySrc + i, data->width, src_buffer); - fetchMask(data->mask, data->xMask, data->yMask + i, data->width, mask_buffer); - - /* fill dest into second half of scanline */ - if (fetchDest) - fetchDest(data->dest, data->xDest, data->yDest + i, data->width, dest_buffer); - - /* blend */ - compose(dest_buffer, src_buffer, mask_buffer, data->width); - - /* write back */ - store(data->dest, data->xDest, data->yDest + i, data->width, dest_buffer); - } - } else { - - CombineFuncU compose = composeFunctions.combineU[data->op]; - if (!compose) - return; - - if (fetchSrc == fbFetchSolid && (!fetchMask || fetchMask == fbFetchSolid)) { - fetchSrc(data->src, data->xSrc, data->ySrc, data->width, src_buffer); - if (fetchMask) { - fetchMask(data->mask, data->xMask, data->yMask, data->width, dest_buffer); - composeFunctions.combineMaskU(src_buffer, dest_buffer, data->width); - } - fetchSrc = NULL; - fetchMask = NULL; - } - - for (i = 0; i < data->height; ++i) - { - /* fill first half of scanline with source */ - if (fetchSrc) { - fetchSrc(data->src, data->xSrc, data->ySrc + i, data->width, src_buffer); - - /* add in mask */ - if (fetchMask) { - fetchMask(data->mask, data->xMask, data->yMask + i, data->width, dest_buffer); - composeFunctions.combineMaskU(src_buffer, dest_buffer, data->width); - } - } - - /* fill dest into second half of scanline */ - if (fetchDest) - fetchDest(data->dest, data->xDest, data->yDest + i, data->width, dest_buffer); - - /* blend */ - compose(dest_buffer, src_buffer, data->width); - - /* write back */ - store(data->dest, data->xDest, data->yDest + i, data->width, dest_buffer); - } - } -} - -void -fbCompositeGeneral (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - RegionRec region; - int n; - BoxPtr pbox; - Bool srcRepeat = FALSE; - Bool maskRepeat = FALSE; - int w, h; - CARD32 _scanline_buffer[SCANLINE_BUFFER_LENGTH*3]; - CARD32 *scanline_buffer = _scanline_buffer; - FbComposeData compose_data; - - if (pSrc->pDrawable) - srcRepeat = pSrc->repeatType == RepeatNormal && !pSrc->transform - && (pSrc->pDrawable->width != 1 || pSrc->pDrawable->height != 1); - - if (pMask && pMask->pDrawable) - maskRepeat = pMask->repeatType == RepeatNormal && !pMask->transform - && (pMask->pDrawable->width != 1 || pMask->pDrawable->height != 1); - - if (op == PictOpOver && !pMask && !pSrc->transform && !PICT_FORMAT_A(pSrc->format) && !pSrc->alphaMap) - op = PictOpSrc; - - if (!miComputeCompositeRegion (®ion, - pSrc, - pMask, - pDst, - xSrc, - ySrc, - xMask, - yMask, - xDst, - yDst, - width, - height)) - return; - - compose_data.op = op; - compose_data.src = pSrc; - compose_data.mask = pMask; - compose_data.dest = pDst; - if (width > SCANLINE_BUFFER_LENGTH) - scanline_buffer = (CARD32 *) malloc(width * 3 * sizeof(CARD32)); - - n = REGION_NUM_RECTS (®ion); - pbox = REGION_RECTS (®ion); - while (n--) - { - h = pbox->y2 - pbox->y1; - compose_data.ySrc = pbox->y1 - yDst + ySrc; - compose_data.yMask = pbox->y1 - yDst + yMask; - compose_data.yDest = pbox->y1; - while (h) - { - compose_data.height = h; - w = pbox->x2 - pbox->x1; - compose_data.xSrc = pbox->x1 - xDst + xSrc; - compose_data.xMask = pbox->x1 - xDst + xMask; - compose_data.xDest = pbox->x1; - if (maskRepeat) - { - compose_data.yMask = mod (compose_data.yMask, pMask->pDrawable->height); - if (compose_data.height > pMask->pDrawable->height - compose_data.yMask) - compose_data.height = pMask->pDrawable->height - compose_data.yMask; - } - if (srcRepeat) - { - compose_data.ySrc = mod (compose_data.ySrc, pSrc->pDrawable->height); - if (compose_data.height > pSrc->pDrawable->height - compose_data.ySrc) - compose_data.height = pSrc->pDrawable->height - compose_data.ySrc; - } - while (w) - { - compose_data.width = w; - if (maskRepeat) - { - compose_data.xMask = mod (compose_data.xMask, pMask->pDrawable->width); - if (compose_data.width > pMask->pDrawable->width - compose_data.xMask) - compose_data.width = pMask->pDrawable->width - compose_data.xMask; - } - if (srcRepeat) - { - compose_data.xSrc = mod (compose_data.xSrc, pSrc->pDrawable->width); - if (compose_data.width > pSrc->pDrawable->width - compose_data.xSrc) - compose_data.width = pSrc->pDrawable->width - compose_data.xSrc; - } - fbCompositeRect(&compose_data, scanline_buffer); - w -= compose_data.width; - compose_data.xSrc += compose_data.width; - compose_data.xMask += compose_data.width; - compose_data.xDest += compose_data.width; - } - h -= compose_data.height; - compose_data.ySrc += compose_data.height; - compose_data.yMask += compose_data.height; - compose_data.yDest += compose_data.height; - } - pbox++; - } - REGION_UNINIT (pDst->pDrawable->pScreen, ®ion); - - if (scanline_buffer != _scanline_buffer) - free(scanline_buffer); -} - -#endif diff --git a/fb/fbmmx.c b/fb/fbmmx.c index 5bbede10b..53459a000 100644 --- a/fb/fbmmx.c +++ b/fb/fbmmx.c @@ -85,30 +85,40 @@ typedef unsigned long long ullong; +#ifdef __GNUC__ +typedef ullong mmxdatafield; +#endif +#ifdef _MSC_VER +typedef unsigned __int64 ullong; +typedef __m64 mmxdatafield; +#endif + typedef struct { - ullong mmx_4x00ff; - ullong mmx_4x0080; - ullong mmx_565_rgb; - ullong mmx_565_unpack_multiplier; - ullong mmx_565_r; - ullong mmx_565_g; - ullong mmx_565_b; - ullong mmx_mask_0; - ullong mmx_mask_1; - ullong mmx_mask_2; - ullong mmx_mask_3; - ullong mmx_full_alpha; - ullong mmx_ffff0000ffff0000; - ullong mmx_0000ffff00000000; - ullong mmx_000000000000ffff; + mmxdatafield mmx_4x00ff; + mmxdatafield mmx_4x0080; + mmxdatafield mmx_565_rgb; + mmxdatafield mmx_565_unpack_multiplier; + mmxdatafield mmx_565_r; + mmxdatafield mmx_565_g; + mmxdatafield mmx_565_b; + mmxdatafield mmx_mask_0; + mmxdatafield mmx_mask_1; + mmxdatafield mmx_mask_2; + mmxdatafield mmx_mask_3; + mmxdatafield mmx_full_alpha; + mmxdatafield mmx_ffff0000ffff0000; + mmxdatafield mmx_0000ffff00000000; + mmxdatafield mmx_000000000000ffff; } MMXData; static const MMXData c = { +#ifdef __GNUC__ .mmx_4x00ff = 0x00ff00ff00ff00ffULL, .mmx_4x0080 = 0x0080008000800080ULL, .mmx_565_rgb = 0x000001f0003f001fULL, + .mmx_565_unpack_multiplier = 0x0000008404100840ULL, .mmx_565_r = 0x000000f800000000ULL, .mmx_565_g = 0x0000000000fc0000ULL, .mmx_565_b = 0x00000000000000f8ULL, @@ -117,15 +127,42 @@ static const MMXData c = .mmx_mask_2 = 0xffff0000ffffffffULL, .mmx_mask_3 = 0x0000ffffffffffffULL, .mmx_full_alpha = 0x00ff000000000000ULL, - .mmx_565_unpack_multiplier = 0x0000008404100840ULL, .mmx_ffff0000ffff0000 = 0xffff0000ffff0000ULL, .mmx_0000ffff00000000 = 0x0000ffff00000000ULL, .mmx_000000000000ffff = 0x000000000000ffffULL, +#endif +#ifdef _MSC_VER + { 0x00ff00ff00ff00ffUI64 }, + { 0x0080008000800080UI64 }, + { 0x000001f0003f001fUI64 }, + { 0x0000008404100840UI64 }, + { 0x000000f800000000UI64 }, + { 0x0000000000fc0000UI64 }, + { 0x00000000000000f8UI64 }, + { 0xffffffffffff0000UI64 }, + { 0xffffffff0000ffffUI64 }, + { 0xffff0000ffffffffUI64 }, + { 0x0000ffffffffffffUI64 }, + { 0x00ff000000000000UI64 }, + { 0xffff0000ffff0000UI64 }, + { 0x0000ffff00000000UI64 }, + { 0x000000000000ffffUI64 }, +#endif }; +#ifdef _MSC_VER +#undef inline +#define inline __forceinline +#endif + +#ifdef __GNUC__ #define MC(x) ((__m64) c.mmx_##x) +#endif +#ifdef _MSC_VER +#define MC(x) c.mmx_##x +#endif -static __inline__ __m64 +static inline __m64 shift (__m64 v, int s) { if (s > 0) @@ -136,13 +173,13 @@ shift (__m64 v, int s) return v; } -static __inline__ __m64 +static inline __m64 negate (__m64 mask) { return _mm_xor_si64 (mask, MC(4x00ff)); } -static __inline__ __m64 +static inline __m64 pix_multiply (__m64 a, __m64 b) { __m64 res; @@ -155,7 +192,7 @@ pix_multiply (__m64 a, __m64 b) return res; } -static __inline__ __m64 +static inline __m64 pix_add (__m64 a, __m64 b) { return _mm_adds_pu8 (a, b); @@ -163,19 +200,19 @@ pix_add (__m64 a, __m64 b) #ifdef USE_SSE -static __inline__ __m64 +static inline __m64 expand_alpha (__m64 pixel) { return _mm_shuffle_pi16 (pixel, _MM_SHUFFLE(3, 3, 3, 3)); } -static __inline__ __m64 +static inline __m64 expand_alpha_rev (__m64 pixel) { return _mm_shuffle_pi16 (pixel, _MM_SHUFFLE(0, 0, 0, 0)); } -static __inline__ __m64 +static inline __m64 invert_colors (__m64 pixel) { return _mm_shuffle_pi16 (pixel, _MM_SHUFFLE(3, 0, 1, 2)); @@ -183,7 +220,7 @@ invert_colors (__m64 pixel) #else -static __inline__ __m64 +static inline __m64 expand_alpha (__m64 pixel) { __m64 t1, t2; @@ -197,7 +234,7 @@ expand_alpha (__m64 pixel) return t1; } -static __inline__ __m64 +static inline __m64 expand_alpha_rev (__m64 pixel) { __m64 t1, t2; @@ -214,7 +251,7 @@ expand_alpha_rev (__m64 pixel) return t1; } -static __inline__ __m64 +static inline __m64 invert_colors (__m64 pixel) { __m64 x, y, z; @@ -236,13 +273,13 @@ invert_colors (__m64 pixel) #endif -static __inline__ __m64 +static inline __m64 over (__m64 src, __m64 srca, __m64 dest) { return _mm_adds_pu8 (src, pix_multiply(dest, negate(srca))); } -static __inline__ __m64 +static inline __m64 over_rev_non_pre (__m64 src, __m64 dest) { __m64 srca = expand_alpha (src); @@ -251,14 +288,23 @@ over_rev_non_pre (__m64 src, __m64 dest) return over(pix_multiply(invert_colors(src), srcfaaa), srca, dest); } -static __inline__ __m64 +static inline __m64 in (__m64 src, __m64 mask) { return pix_multiply (src, mask); } -static __inline__ __m64 +static inline __m64 +in_over_full_src_alpha (__m64 src, __m64 mask, __m64 dest) +{ + src = _mm_or_si64 (src, MC(full_alpha)); + + return over(in (src, mask), mask, dest); +} + +#ifndef _MSC_VER +static inline __m64 in_over (__m64 src, __m64 srca, __m64 mask, @@ -266,20 +312,23 @@ in_over (__m64 src, { return over(in(src, mask), pix_multiply(srca, mask), dest); } +#else +#define in_over(src, srca, mask, dest) over(in(src, mask), pix_multiply(srca, mask), dest) +#endif -static __inline__ __m64 +static inline __m64 load8888 (CARD32 v) { return _mm_unpacklo_pi8 (_mm_cvtsi32_si64 (v), _mm_setzero_si64()); } -static __inline__ __m64 +static inline __m64 pack8888 (__m64 lo, __m64 hi) { return _mm_packs_pu16 (lo, hi); } -static __inline__ CARD32 +static inline CARD32 store8888 (__m64 v) { return _mm_cvtsi64_si32(pack8888(v, _mm_setzero_si64())); @@ -299,7 +348,7 @@ store8888 (__m64 v) * Note the trick here - the top word is shifted by another nibble to * avoid it bumping into the middle word */ -static __inline__ __m64 +static inline __m64 expand565 (__m64 pixel, int pos) { __m64 p = pixel; @@ -319,7 +368,7 @@ expand565 (__m64 pixel, int pos) return _mm_srli_pi16 (pixel, 8); } -static __inline__ __m64 +static inline __m64 expand8888 (__m64 in, int pos) { if (pos == 0) @@ -328,7 +377,7 @@ expand8888 (__m64 in, int pos) return _mm_unpackhi_pi8 (in, _mm_setzero_si64()); } -static __inline__ __m64 +static inline __m64 pack565 (__m64 pixel, __m64 target, int pos) { __m64 p = pixel; @@ -358,20 +407,28 @@ pack565 (__m64 pixel, __m64 target, int pos) return _mm_or_si64 (b, p); } -static __inline__ __m64 +#ifndef _MSC_VER +static inline __m64 pix_add_mul (__m64 x, __m64 a, __m64 y, __m64 b) { - x = _mm_mullo_pi16 (x, a); - y = _mm_mullo_pi16 (y, b); - x = _mm_srli_pi16(x, 1); - y = _mm_srli_pi16(y, 1); - x = _mm_adds_pu16 (x, y); - x = _mm_adds_pu16 (x, _mm_srli_pi16 (x, 8)); + x = _mm_mullo_pi16 (x, a); + y = _mm_mullo_pi16 (y, b); x = _mm_adds_pu16 (x, MC(4x0080)); - x = _mm_srli_pi16 (x, 7); + x = _mm_adds_pu16 (x, y); + x = _mm_adds_pu16 (x, _mm_srli_pi16 (x, 8)); + x = _mm_srli_pi16 (x, 8); return x; } +#else +#define pix_add_mul(x, a, y, b) \ +( x = _mm_mullo_pi16 (x, a), \ + y = _mm_mullo_pi16 (y, b), \ + x = _mm_adds_pu16 (x, MC(4x0080)), \ + x = _mm_adds_pu16 (x, y), \ + x = _mm_adds_pu16 (x, _mm_srli_pi16 (x, 8)), \ + _mm_srli_pi16 (x, 8) ) +#endif /* --------------- MMX code patch for fbcompose.c --------------------- */ @@ -590,8 +647,8 @@ mmxCombineSaturateU (CARD32 *dest, const CARD32 *src, int width) CARD32 da = ~d >> 24; if (sa > da) { - __m64 msa = load8888(FbIntDiv(da, sa)); - msa = expand_alpha_rev(msa); + __m64 msa = load8888(FbIntDiv(da, sa) << 24); + msa = expand_alpha(msa); ms = pix_multiply(ms, msa); } md = pix_add(md, ms); @@ -821,10 +878,15 @@ mmxCombineAddC (CARD32 *dest, CARD32 *src, CARD32 *mask, int width) _mm_empty(); } +#if 0 +/* FIXME: this should be reinstated after adding fbmmx to pixman */ extern FbComposeFunctions composeFunctions; +#endif void fbComposeSetupMMX(void) { +#if 0 +/* FIXME: this should be reinstated after adding fbmmx to pixman */ /* check if we have MMX support and initialize accordingly */ if (fbHaveMMX()) { composeFunctions.combineU[PictOpOver] = mmxCombineOverU; @@ -853,6 +915,7 @@ void fbComposeSetupMMX(void) composeFunctions.combineMaskU = mmxCombineMaskU; } +#endif } @@ -1140,23 +1203,22 @@ fbCompositeSrc_8888x8x8888mmx (CARD8 op, { CARD32 *dstLine, *dst; CARD32 *srcLine, *src; - CARD8 *maskLine; CARD32 mask; __m64 vmask; - FbStride dstStride, srcStride, maskStride; + FbStride dstStride, srcStride; CARD16 w; __m64 srca; - + CHECKPOINT(); - + fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1); fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1); - fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1); - mask = *maskLine << 24 | *maskLine << 16 | *maskLine << 8 | *maskLine; + fbComposeGetSolid (pMask, mask, pDst->format); + mask = mask | mask >> 8 | mask >> 16 | mask >> 24; vmask = load8888 (mask); srca = MC(4x00ff); - + while (height--) { dst = dstLine; @@ -1169,94 +1231,129 @@ fbCompositeSrc_8888x8x8888mmx (CARD8 op, { __m64 s = load8888 (*src); __m64 d = load8888 (*dst); - - *dst = store8888 (in_over (s, srca, vmask, d)); - + + *dst = store8888 (in_over (s, expand_alpha (s), vmask, d)); + w--; dst++; src++; } - while (w >= 16) + while (w >= 2) { - __m64 vd0 = *(__m64 *)(dst + 0); - __m64 vd1 = *(__m64 *)(dst + 2); - __m64 vd2 = *(__m64 *)(dst + 4); - __m64 vd3 = *(__m64 *)(dst + 6); - __m64 vd4 = *(__m64 *)(dst + 8); - __m64 vd5 = *(__m64 *)(dst + 10); - __m64 vd6 = *(__m64 *)(dst + 12); - __m64 vd7 = *(__m64 *)(dst + 14); - - __m64 vs0 = *(__m64 *)(src + 0); - __m64 vs1 = *(__m64 *)(src + 2); - __m64 vs2 = *(__m64 *)(src + 4); - __m64 vs3 = *(__m64 *)(src + 6); - __m64 vs4 = *(__m64 *)(src + 8); - __m64 vs5 = *(__m64 *)(src + 10); - __m64 vs6 = *(__m64 *)(src + 12); - __m64 vs7 = *(__m64 *)(src + 14); - - vd0 = (__m64)pack8888 ( - in_over (expand8888 (vs0, 0), srca, vmask, expand8888 (vd0, 0)), - in_over (expand8888 (vs0, 1), srca, vmask, expand8888 (vd0, 1))); - - vd1 = (__m64)pack8888 ( - in_over (expand8888 (vs1, 0), srca, vmask, expand8888 (vd1, 0)), - in_over (expand8888 (vs1, 1), srca, vmask, expand8888 (vd1, 1))); - - vd2 = (__m64)pack8888 ( - in_over (expand8888 (vs2, 0), srca, vmask, expand8888 (vd2, 0)), - in_over (expand8888 (vs2, 1), srca, vmask, expand8888 (vd2, 1))); - - vd3 = (__m64)pack8888 ( - in_over (expand8888 (vs3, 0), srca, vmask, expand8888 (vd3, 0)), - in_over (expand8888 (vs3, 1), srca, vmask, expand8888 (vd3, 1))); - - vd4 = (__m64)pack8888 ( - in_over (expand8888 (vs4, 0), srca, vmask, expand8888 (vd4, 0)), - in_over (expand8888 (vs4, 1), srca, vmask, expand8888 (vd4, 1))); - - vd5 = (__m64)pack8888 ( - in_over (expand8888 (vs5, 0), srca, vmask, expand8888 (vd5, 0)), - in_over (expand8888 (vs5, 1), srca, vmask, expand8888 (vd5, 1))); - - vd6 = (__m64)pack8888 ( - in_over (expand8888 (vs6, 0), srca, vmask, expand8888 (vd6, 0)), - in_over (expand8888 (vs6, 1), srca, vmask, expand8888 (vd6, 1))); - - vd7 = (__m64)pack8888 ( - in_over (expand8888 (vs7, 0), srca, vmask, expand8888 (vd7, 0)), - in_over (expand8888 (vs7, 1), srca, vmask, expand8888 (vd7, 1))); - - *(__m64 *)(dst + 0) = vd0; - *(__m64 *)(dst + 2) = vd1; - *(__m64 *)(dst + 4) = vd2; - *(__m64 *)(dst + 6) = vd3; - *(__m64 *)(dst + 8) = vd4; - *(__m64 *)(dst + 10) = vd5; - *(__m64 *)(dst + 12) = vd6; - *(__m64 *)(dst + 14) = vd7; - - w -= 16; - dst += 16; - src += 16; + __m64 vs = *(__m64 *)src; + __m64 vd = *(__m64 *)dst; + __m64 vsrc0 = expand8888 (vs, 0); + __m64 vsrc1 = expand8888 (vs, 1); + + *(__m64 *)dst = pack8888 ( + in_over (vsrc0, expand_alpha (vsrc0), vmask, expand8888 (vd, 0)), + in_over (vsrc1, expand_alpha (vsrc1), vmask, expand8888 (vd, 1))); + + w -= 2; + dst += 2; + src += 2; } - + while (w) { __m64 s = load8888 (*src); __m64 d = load8888 (*dst); - + + *dst = store8888 (in_over (s, expand_alpha (s), vmask, d)); + + w--; + dst++; + src++; + } + } + + _mm_empty(); +} + +void +fbCompositeSrc_x888x8x8888mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + CARD32 *dstLine, *dst; + CARD32 *srcLine, *src; + CARD32 mask; + __m64 vmask; + FbStride dstStride, srcStride; + CARD16 w; + __m64 srca; + + CHECKPOINT(); + + fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1); + fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1); + fbComposeGetSolid (pMask, mask, pDst->format); + + mask = mask | mask >> 8 | mask >> 16 | mask >> 24; + vmask = load8888 (mask); + srca = MC(4x00ff); + + while (height--) + { + dst = dstLine; + dstLine += dstStride; + src = srcLine; + srcLine += srcStride; + w = width; + + while (w && (unsigned long)dst & 7) + { + __m64 s = load8888 (*src | 0xff000000); + __m64 d = load8888 (*dst); + *dst = store8888 (in_over (s, srca, vmask, d)); + + w--; + dst++; + src++; + } + + while (w >= 2) + { + __m64 vd0 = *(__m64 *)(dst); + __m64 vs0 = *(__m64 *)(src); + + vd0 = pack8888 ( + in_over_full_src_alpha (expand8888 (vs0, 0), vmask, expand8888 (vd0, 0)), + in_over_full_src_alpha (expand8888 (vs0, 1), vmask, expand8888 (vd0, 1))); + + *(__m64 *)(dst) = vd0; + + w -= 2; + dst += 2; + src += 2; + } + + while (w) + { + __m64 s = load8888 (*src | 0xff000000); + __m64 d = load8888 (*dst); + + *dst = store8888 (in_over (s, srca, vmask, d)); + w--; dst++; src++; } } - _mm_empty(); + _mm_empty(); } void @@ -1552,6 +1649,270 @@ fbCompositeSolidMask_nx8x8888mmx (CARD8 op, } +Bool +fbSolidFillmmx (DrawablePtr pDraw, + int x, + int y, + int width, + int height, + FbBits xor) +{ + FbStride stride; + int bpp; + ullong fill; + __m64 vfill; + CARD32 byte_width; + CARD8 *byte_line; + FbBits *bits; + int xoff, yoff; +#ifdef __GNUC__ + __m64 v1, v2, v3, v4, v5, v6, v7; +#endif + + CHECKPOINT(); + + fbGetDrawable(pDraw, bits, stride, bpp, xoff, yoff); + + if (bpp == 16 && (xor >> 16 != (xor & 0xffff))) + return FALSE; + + if (bpp != 16 && bpp != 32) + return FALSE; + + if (bpp == 16) + { + stride = stride * sizeof (FbBits) / 2; + byte_line = (CARD8 *)(((CARD16 *)bits) + stride * (y + yoff) + (x + xoff)); + byte_width = 2 * width; + stride *= 2; + } + else + { + stride = stride * sizeof (FbBits) / 4; + byte_line = (CARD8 *)(((CARD32 *)bits) + stride * (y + yoff) + (x + xoff)); + byte_width = 4 * width; + stride *= 4; + } + + fill = ((ullong)xor << 32) | xor; + vfill = (__m64)fill; + +#ifdef __GNUC__ + __asm__ ( + "movq %7, %0\n" + "movq %7, %1\n" + "movq %7, %2\n" + "movq %7, %3\n" + "movq %7, %4\n" + "movq %7, %5\n" + "movq %7, %6\n" + : "=y" (v1), "=y" (v2), "=y" (v3), + "=y" (v4), "=y" (v5), "=y" (v6), "=y" (v7) + : "y" (vfill)); +#endif + + while (height--) + { + int w; + CARD8 *d = byte_line; + byte_line += stride; + w = byte_width; + + while (w >= 2 && ((unsigned long)d & 3)) + { + *(CARD16 *)d = xor; + w -= 2; + d += 2; + } + + while (w >= 4 && ((unsigned long)d & 7)) + { + *(CARD32 *)d = xor; + + w -= 4; + d += 4; + } + + while (w >= 64) + { +#ifdef __GNUC__ + __asm__ ( + "movq %1, (%0)\n" + "movq %2, 8(%0)\n" + "movq %3, 16(%0)\n" + "movq %4, 24(%0)\n" + "movq %5, 32(%0)\n" + "movq %6, 40(%0)\n" + "movq %7, 48(%0)\n" + "movq %8, 56(%0)\n" + : + : "r" (d), + "y" (vfill), "y" (v1), "y" (v2), "y" (v3), + "y" (v4), "y" (v5), "y" (v6), "y" (v7) + : "memory"); +#else + *(__m64*) (d + 0) = vfill; + *(__m64*) (d + 8) = vfill; + *(__m64*) (d + 16) = vfill; + *(__m64*) (d + 24) = vfill; + *(__m64*) (d + 32) = vfill; + *(__m64*) (d + 40) = vfill; + *(__m64*) (d + 48) = vfill; + *(__m64*) (d + 56) = vfill; +#endif + w -= 64; + d += 64; + } + + while (w >= 4) + { + *(CARD32 *)d = xor; + + w -= 4; + d += 4; + } + if (w >= 2) + { + *(CARD16 *)d = xor; + w -= 2; + d += 2; + } + } + + _mm_empty(); + return TRUE; +} + +void +fbCompositeSolidMaskSrc_nx8x8888mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + CARD32 src, srca; + CARD32 *dstLine, *dst; + CARD8 *maskLine, *mask; + FbStride dstStride, maskStride; + CARD16 w; + __m64 vsrc, vsrca; + ullong srcsrc; + + CHECKPOINT(); + + fbComposeGetSolid(pSrc, src, pDst->format); + + srca = src >> 24; + if (srca == 0) + { + fbSolidFillmmx (pDst->pDrawable, xDst, yDst, width, height, 0); + return; + } + + srcsrc = (ullong)src << 32 | src; + + fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1); + fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1); + + vsrc = load8888 (src); + vsrca = expand_alpha (vsrc); + + while (height--) + { + dst = dstLine; + dstLine += dstStride; + mask = maskLine; + maskLine += maskStride; + w = width; + + CHECKPOINT(); + + while (w && (unsigned long)dst & 7) + { + ullong m = *mask; + + if (m) + { + __m64 vdest = in(vsrc, expand_alpha_rev ((__m64)m)); + *dst = store8888(vdest); + } + else + { + *dst = 0; + } + + w--; + mask++; + dst++; + } + + CHECKPOINT(); + + while (w >= 2) + { + ullong m0, m1; + m0 = *mask; + m1 = *(mask + 1); + + if (srca == 0xff && (m0 & m1) == 0xff) + { + *(ullong *)dst = srcsrc; + } + else if (m0 | m1) + { + __m64 vdest; + __m64 dest0, dest1; + + vdest = *(__m64 *)dst; + + dest0 = in(vsrc, expand_alpha_rev ((__m64)m0)); + dest1 = in(vsrc, expand_alpha_rev ((__m64)m1)); + + *(__m64 *)dst = pack8888(dest0, dest1); + } + else + { + *(ullong *)dst = 0; + } + + mask += 2; + dst += 2; + w -= 2; + } + + CHECKPOINT(); + + while (w) + { + ullong m = *mask; + + if (m) + { + __m64 vdest = load8888(*dst); + vdest = in(vsrc, expand_alpha_rev ((__m64)m)); + *dst = store8888(vdest); + } + else + { + *dst = 0; + } + + w--; + mask++; + dst++; + } + } + + _mm_empty(); +} + void fbCompositeSolidMask_nx8x0565mmx (CARD8 op, PicturePtr pSrc, @@ -2003,6 +2364,232 @@ fbCompositeSolidMask_nx8888x0565Cmmx (CARD8 op, } void +fbCompositeIn_nx8x8mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + CARD8 *dstLine, *dst; + CARD8 *maskLine, *mask; + FbStride dstStride, maskStride; + CARD16 w; + CARD32 src; + CARD8 sa; + __m64 vsrc, vsrca; + + fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 1); + fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1); + + fbComposeGetSolid(pSrc, src, pDst->format); + + sa = src >> 24; + if (sa == 0) + return; + + vsrc = load8888(src); + vsrca = expand_alpha(vsrc); + + while (height--) + { + dst = dstLine; + dstLine += dstStride; + mask = maskLine; + maskLine += maskStride; + w = width; + + if ((((unsigned long)pDst & 3) == 0) && + (((unsigned long)pSrc & 3) == 0)) + { + while (w >= 4) + { + CARD32 m; + __m64 vmask; + __m64 vdest; + + m = 0; + + vmask = load8888 (*(CARD32 *)mask); + vdest = load8888 (*(CARD32 *)dst); + + *(CARD32 *)dst = store8888 (in (in (vsrca, vmask), vdest)); + + dst += 4; + mask += 4; + w -= 4; + } + } + + while (w--) + { + CARD16 tmp; + CARD8 a; + CARD32 m, d; + CARD32 r; + + a = *mask++; + d = *dst; + + m = FbInU (sa, 0, a, tmp); + r = FbInU (m, 0, d, tmp); + + *dst++ = r; + } + } + + _mm_empty(); +} + +void +fbCompositeIn_8x8mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + CARD8 *dstLine, *dst; + CARD8 *srcLine, *src; + FbStride srcStride, dstStride; + CARD16 w; + + fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 1); + fbComposeGetStart (pSrc, xSrc, ySrc, CARD8, srcStride, srcLine, 1); + + while (height--) + { + dst = dstLine; + dstLine += dstStride; + src = srcLine; + srcLine += srcStride; + w = width; + + if ((((unsigned long)pDst & 3) == 0) && + (((unsigned long)pSrc & 3) == 0)) + { + while (w >= 4) + { + CARD32 *s = (CARD32 *)src; + CARD32 *d = (CARD32 *)dst; + + *d = store8888 (in (load8888 (*s), load8888 (*d))); + + w -= 4; + dst += 4; + src += 4; + } + } + + while (w--) + { + CARD8 s, d; + CARD16 tmp; + + s = *src; + d = *dst; + + *dst = FbInU (s, 0, d, tmp); + + src++; + dst++; + } + } + + _mm_empty (); +} + +void +fbCompositeSrcAdd_8888x8x8mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + CARD8 *dstLine, *dst; + CARD8 *maskLine, *mask; + FbStride dstStride, maskStride; + CARD16 w; + CARD32 src; + CARD8 sa; + __m64 vsrc, vsrca; + + fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 1); + fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1); + + fbComposeGetSolid(pSrc, src, pDst->format); + + sa = src >> 24; + if (sa == 0) + return; + + vsrc = load8888(src); + vsrca = expand_alpha(vsrc); + + while (height--) + { + dst = dstLine; + dstLine += dstStride; + mask = maskLine; + maskLine += maskStride; + w = width; + + if ((((unsigned long)pMask & 3) == 0) && + (((unsigned long)pDst & 3) == 0)) + { + while (w >= 4) + { + __m64 vmask = load8888 (*(CARD32 *)mask); + __m64 vdest = load8888 (*(CARD32 *)dst); + + *(CARD32 *)dst = store8888 (_mm_adds_pu8 (in (vsrca, vmask), vdest)); + + w -= 4; + dst += 4; + mask += 4; + } + } + + while (w--) + { + CARD16 tmp; + CARD16 a; + CARD32 m, d; + CARD32 r; + + a = *mask++; + d = *dst; + + m = FbInU (sa, 0, a, tmp); + r = FbAdd (m, d, 0, tmp); + + *dst++ = r; + } + } + + _mm_empty(); +} + +void fbCompositeSrcAdd_8000x8000mmx (CARD8 op, PicturePtr pSrc, PicturePtr pMask, @@ -2135,126 +2722,6 @@ fbCompositeSrcAdd_8888x8888mmx (CARD8 op, } Bool -fbSolidFillmmx (DrawablePtr pDraw, - int x, - int y, - int width, - int height, - FbBits xor) -{ - FbStride stride; - int bpp; - ullong fill; - __m64 vfill; - CARD32 byte_width; - CARD8 *byte_line; - FbBits *bits; - int xoff, yoff; - __m64 v1, v2, v3, v4, v5, v6, v7; - - CHECKPOINT(); - - fbGetDrawable(pDraw, bits, stride, bpp, xoff, yoff); - - if (bpp == 16 && (xor >> 16 != (xor & 0xffff))) - return FALSE; - - if (bpp != 16 && bpp != 32) - return FALSE; - - if (bpp == 16) - { - stride = stride * sizeof (FbBits) / 2; - byte_line = (CARD8 *)(((CARD16 *)bits) + stride * (y + yoff) + (x + xoff)); - byte_width = 2 * width; - stride *= 2; - } - else - { - stride = stride * sizeof (FbBits) / 4; - byte_line = (CARD8 *)(((CARD32 *)bits) + stride * (y + yoff) + (x + xoff)); - byte_width = 4 * width; - stride *= 4; - } - - fill = ((ullong)xor << 32) | xor; - vfill = (__m64)fill; - - __asm__ ( - "movq %7, %0\n" - "movq %7, %1\n" - "movq %7, %2\n" - "movq %7, %3\n" - "movq %7, %4\n" - "movq %7, %5\n" - "movq %7, %6\n" - : "=y" (v1), "=y" (v2), "=y" (v3), - "=y" (v4), "=y" (v5), "=y" (v6), "=y" (v7) - : "y" (vfill)); - - while (height--) - { - int w; - CARD8 *d = byte_line; - byte_line += stride; - w = byte_width; - - while (w >= 2 && ((unsigned long)d & 3)) - { - *(CARD16 *)d = xor; - w -= 2; - d += 2; - } - - while (w >= 4 && ((unsigned long)d & 7)) - { - *(CARD32 *)d = xor; - - w -= 4; - d += 4; - } - - while (w >= 64) - { - __asm__ ( - "movq %1, (%0)\n" - "movq %2, 8(%0)\n" - "movq %3, 16(%0)\n" - "movq %4, 24(%0)\n" - "movq %5, 32(%0)\n" - "movq %6, 40(%0)\n" - "movq %7, 48(%0)\n" - "movq %8, 56(%0)\n" - : - : "r" (d), - "y" (vfill), "y" (v1), "y" (v2), "y" (v3), - "y" (v4), "y" (v5), "y" (v6), "y" (v7) - : "memory"); - - w -= 64; - d += 64; - } - - while (w >= 4) - { - *(CARD32 *)d = xor; - - w -= 4; - d += 4; - } - if (w >= 2) - { - *(CARD16 *)d = xor; - w -= 2; - d += 2; - } - } - - _mm_empty(); - return TRUE; -} - -Bool fbCopyAreammx (DrawablePtr pSrc, DrawablePtr pDst, int src_x, @@ -2335,6 +2802,7 @@ fbCopyAreammx (DrawablePtr pSrc, while (w >= 64) { +#ifdef __GNUC__ __asm__ ( "movq (%1), %%mm0\n" "movq 8(%1), %%mm1\n" @@ -2358,6 +2826,24 @@ fbCopyAreammx (DrawablePtr pSrc, : "memory", "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7"); +#else + __m64 v0 = *(__m64 *)(s + 0); + __m64 v1 = *(__m64 *)(s + 8); + __m64 v2 = *(__m64 *)(s + 16); + __m64 v3 = *(__m64 *)(s + 24); + __m64 v4 = *(__m64 *)(s + 32); + __m64 v5 = *(__m64 *)(s + 40); + __m64 v6 = *(__m64 *)(s + 48); + __m64 v7 = *(__m64 *)(s + 56); + *(__m64 *)(d + 0) = v0; + *(__m64 *)(d + 8) = v1; + *(__m64 *)(d + 16) = v2; + *(__m64 *)(d + 24) = v3; + *(__m64 *)(d + 32) = v4; + *(__m64 *)(d + 40) = v5; + *(__m64 *)(d + 48) = v6; + *(__m64 *)(d + 56) = v7; +#endif w -= 64; s += 64; diff --git a/fb/fbmmx.h b/fb/fbmmx.h index b3e4d71ef..ca9c7e796 100644 --- a/fb/fbmmx.h +++ b/fb/fbmmx.h @@ -82,6 +82,32 @@ void fbCompositeSrc_8888x8888mmx (CARD8 op, INT16 yDst, CARD16 width, CARD16 height); +void +fbCompositeSolidMaskSrc_nx8x8888mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height); +void +fbCompositeSrc_x888x8x8888mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height); void fbCompositeSolidMask_nx8888x8888Cmmx (CARD8 op, PicturePtr pSrc, PicturePtr pMask, @@ -106,6 +132,42 @@ void fbCompositeSolidMask_nx8x8888mmx (CARD8 op, INT16 yDst, CARD16 width, CARD16 height); +void fbCompositeIn_nx8x8mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height); +void fbCompositeIn_8x8mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height); +void fbCompositeSrcAdd_8888x8x8mmx (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height); void fbCompositeSrcAdd_8000x8000mmx (CARD8 op, PicturePtr pSrc, PicturePtr pMask, diff --git a/fb/fbpict.c b/fb/fbpict.c index cd6cac277..eb78ceda6 100644 --- a/fb/fbpict.c +++ b/fb/fbpict.c @@ -1,6 +1,7 @@ /* * * Copyright © 2000 SuSE, Inc. + * Copyright © 2007 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -29,6 +30,7 @@ #include <string.h> #include "fb.h" +#include <pixman/pixman.h> #ifdef RENDER @@ -37,870 +39,257 @@ #include "fbpict.h" #include "fbmmx.h" -typedef void (*CompositeFunc) (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -CARD32 -fbOver (CARD32 x, CARD32 y) +static pixman_image_t * +create_solid_fill_image (PicturePtr pict) { - CARD16 a = ~x >> 24; - CARD16 t; - CARD32 m,n,o,p; - - m = FbOverU(x,y,0,a,t); - n = FbOverU(x,y,8,a,t); - o = FbOverU(x,y,16,a,t); - p = FbOverU(x,y,24,a,t); - return m|n|o|p; + PictSolidFill *solid = &pict->pSourcePict->solidFill; + pixman_color_t color; + CARD32 a, r, g, b; + + a = (solid->color & 0xff000000) >> 24; + r = (solid->color & 0x00ff0000) >> 16; + g = (solid->color & 0x0000ff00) >> 8; + b = (solid->color & 0x000000ff) >> 0; + + color.alpha = (a << 8) | a; + color.red = (r << 8) | r; + color.green = (g << 8) | g; + color.blue = (b << 8) | b; + + return pixman_image_create_solid_fill (&color); } -CARD32 -fbOver24 (CARD32 x, CARD32 y) +static pixman_image_t * +create_linear_gradient_image (PictGradient *gradient) { - CARD16 a = ~x >> 24; - CARD16 t; - CARD32 m,n,o; - - m = FbOverU(x,y,0,a,t); - n = FbOverU(x,y,8,a,t); - o = FbOverU(x,y,16,a,t); - return m|n|o; + PictLinearGradient *linear = (PictLinearGradient *)gradient; + pixman_point_fixed_t p1; + pixman_point_fixed_t p2; + + p1.x = linear->p1.x; + p1.y = linear->p1.y; + p2.x = linear->p2.x; + p2.y = linear->p2.y; + + return pixman_image_create_linear_gradient ( + &p1, &p2, (pixman_gradient_stop_t *)gradient->stops, gradient->nstops); } -CARD32 -fbIn (CARD32 x, CARD8 y) +static pixman_image_t * +create_radial_gradient_image (PictGradient *gradient) { - CARD16 a = y; - CARD16 t; - CARD32 m,n,o,p; - - m = FbInU(x,0,a,t); - n = FbInU(x,8,a,t); - o = FbInU(x,16,a,t); - p = FbInU(x,24,a,t); - return m|n|o|p; + PictRadialGradient *radial = (PictRadialGradient *)gradient; + pixman_point_fixed_t c1; + pixman_point_fixed_t c2; + + c1.x = radial->c1.x; + c1.y = radial->c1.y; + c2.x = radial->c2.x; + c2.y = radial->c2.y; + + return pixman_image_create_radial_gradient ( + &c1, &c2, radial->c1.radius, + radial->c2.radius, + (pixman_gradient_stop_t *)gradient->stops, gradient->nstops); } -/* - * Naming convention: - * - * opSRCxMASKxDST - */ - -void -fbCompositeSolidMask_nx8x8888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) +static pixman_image_t * +create_conical_gradient_image (PictGradient *gradient) { - CARD32 src, srca; - CARD32 *dstLine, *dst, d, dstMask; - CARD8 *maskLine, *mask, m; - FbStride dstStride, maskStride; - CARD16 w; - - fbComposeGetSolid(pSrc, src, pDst->format); - - dstMask = FbFullMask (pDst->pDrawable->depth); - srca = src >> 24; - if (src == 0) - return; - - fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1); - fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1); - - while (height--) - { - dst = dstLine; - dstLine += dstStride; - mask = maskLine; - maskLine += maskStride; - w = width; - - while (w--) - { - m = READ(mask++); - if (m == 0xff) - { - if (srca == 0xff) - WRITE(dst, src & dstMask); - else - WRITE(dst, fbOver (src, READ(dst)) & dstMask); - } - else if (m) - { - d = fbIn (src, m); - WRITE(dst, fbOver (d, READ(dst)) & dstMask); - } - dst++; - } - } - - fbFinishAccess (pMask->pDrawable); - fbFinishAccess (pDst->pDrawable); + PictConicalGradient *conical = (PictConicalGradient *)gradient; + pixman_point_fixed_t center; + + center.x = conical->center.x; + center.y = conical->center.y; + + return pixman_image_create_conical_gradient ( + ¢er, conical->angle, (pixman_gradient_stop_t *)gradient->stops, + gradient->nstops); } -void -fbCompositeSolidMask_nx8888x8888C (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) +static pixman_image_t * +create_bits_picture (PicturePtr pict) { - CARD32 src, srca; - CARD32 *dstLine, *dst, d, dstMask; - CARD32 *maskLine, *mask, ma; - FbStride dstStride, maskStride; - CARD16 w; - CARD32 m, n, o, p; - - fbComposeGetSolid(pSrc, src, pDst->format); - - dstMask = FbFullMask (pDst->pDrawable->depth); - srca = src >> 24; - if (src == 0) - return; - - fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1); - fbComposeGetStart (pMask, xMask, yMask, CARD32, maskStride, maskLine, 1); - - while (height--) - { - dst = dstLine; - dstLine += dstStride; - mask = maskLine; - maskLine += maskStride; - w = width; + FbBits *bits; + FbStride stride; + int bpp, xoff, yoff; + pixman_image_t *image; + + fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff); + + bits += yoff * stride + xoff; + + image = pixman_image_create_bits ( + pict->format, + pict->pDrawable->width, pict->pDrawable->height, + (uint32_t *)bits, stride * sizeof (FbStride)); + + +#ifdef FB_ACCESS_WRAPPER +#if FB_SHIFT==5 + + pixman_image_set_accessors (image, + (pixman_read_memory_func_t)wfbReadMemory, + (pixman_write_memory_func_t)wfbWriteMemory); + +#else + +#error The pixman library only works when FbBits is 32 bits wide + +#endif +#endif + + /* pCompositeClip is undefined for source pictures, so + * only set the clip region for pictures with drawables + */ + pixman_image_set_clip_region (image, pict->pCompositeClip); + + /* Indexed table */ + if (pict->pFormat->index.devPrivate) + pixman_image_set_indexed (image, pict->pFormat->index.devPrivate); + + fbFinishAccess (pict->pDrawable); - while (w--) - { - ma = READ(mask++); - if (ma == 0xffffffff) - { - if (srca == 0xff) - WRITE(dst, src & dstMask); - else - WRITE(dst, fbOver (src, READ(dst)) & dstMask); - } - else if (ma) - { - d = READ(dst); -#define FbInOverC(src,srca,msk,dst,i,result) { \ - CARD16 __a = FbGet8(msk,i); \ - CARD32 __t, __ta; \ - CARD32 __i; \ - __t = FbIntMult (FbGet8(src,i), __a,__i); \ - __ta = (CARD8) ~FbIntMult (srca, __a,__i); \ - __t = __t + FbIntMult(FbGet8(dst,i),__ta,__i); \ - __t = (CARD32) (CARD8) (__t | (-(__t >> 8))); \ - result = __t << (i); \ + return image; } - FbInOverC (src, srca, ma, d, 0, m); - FbInOverC (src, srca, ma, d, 8, n); - FbInOverC (src, srca, ma, d, 16, o); - FbInOverC (src, srca, ma, d, 24, p); - WRITE(dst, m|n|o|p); - } - dst++; - } - } - fbFinishAccess (pMask->pDrawable); - fbFinishAccess (pDst->pDrawable); -} +static pixman_image_t *image_from_pict (PicturePtr pict); -void -fbCompositeSolidMask_nx8x0888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) +static void +set_image_properties (pixman_image_t *image, PicturePtr pict) { - CARD32 src, srca; - CARD8 *dstLine, *dst; - CARD32 d; - CARD8 *maskLine, *mask, m; - FbStride dstStride, maskStride; - CARD16 w; - - fbComposeGetSolid(pSrc, src, pDst->format); - - srca = src >> 24; - if (src == 0) - return; - - fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 3); - fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1); - - while (height--) + pixman_repeat_t repeat; + pixman_filter_t filter; + + if (pict->transform) { - dst = dstLine; - dstLine += dstStride; - mask = maskLine; - maskLine += maskStride; - w = width; - - while (w--) - { - m = READ(mask++); - if (m == 0xff) - { - if (srca == 0xff) - d = src; - else - { - d = Fetch24(dst); - d = fbOver24 (src, d); - } - Store24(dst,d); - } - else if (m) - { - d = fbOver24 (fbIn(src,m), Fetch24(dst)); - Store24(dst,d); - } - dst += 3; - } + pixman_image_set_transform ( + image, (pixman_transform_t *)pict->transform); } - - fbFinishAccess (pMask->pDrawable); - fbFinishAccess (pDst->pDrawable); -} - -void -fbCompositeSolidMask_nx8x0565 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - CARD32 src, srca; - CARD16 *dstLine, *dst; - CARD32 d; - CARD8 *maskLine, *mask, m; - FbStride dstStride, maskStride; - CARD16 w; - - fbComposeGetSolid(pSrc, src, pDst->format); - - srca = src >> 24; - if (src == 0) - return; - - fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1); - fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1); - - while (height--) + + switch (pict->repeatType) { - dst = dstLine; - dstLine += dstStride; - mask = maskLine; - maskLine += maskStride; - w = width; - - while (w--) - { - m = READ(mask++); - if (m == 0xff) - { - if (srca == 0xff) - d = src; - else - { - d = READ(dst); - d = fbOver24 (src, cvt0565to8888(d)); - } - WRITE(dst, cvt8888to0565(d)); - } - else if (m) - { - d = READ(dst); - d = fbOver24 (fbIn(src,m), cvt0565to8888(d)); - WRITE(dst, cvt8888to0565(d)); - } - dst++; - } + default: + case RepeatNone: + repeat = PIXMAN_REPEAT_NONE; + break; + + case RepeatPad: + repeat = PIXMAN_REPEAT_PAD; + break; + + case RepeatNormal: + repeat = PIXMAN_REPEAT_NORMAL; + break; + + case RepeatReflect: + repeat = PIXMAN_REPEAT_REFLECT; + break; } - - fbFinishAccess (pMask->pDrawable); - fbFinishAccess (pDst->pDrawable); -} - -void -fbCompositeSolidMask_nx8888x0565C (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - CARD32 src, srca; - CARD16 src16; - CARD16 *dstLine, *dst; - CARD32 d; - CARD32 *maskLine, *mask, ma; - FbStride dstStride, maskStride; - CARD16 w; - CARD32 m, n, o; - - fbComposeGetSolid(pSrc, src, pDst->format); - - srca = src >> 24; - if (src == 0) - return; - - src16 = cvt8888to0565(src); - - fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1); - fbComposeGetStart (pMask, xMask, yMask, CARD32, maskStride, maskLine, 1); - - while (height--) + + pixman_image_set_repeat (image, repeat); + + if (pict->alphaMap) { - dst = dstLine; - dstLine += dstStride; - mask = maskLine; - maskLine += maskStride; - w = width; - - while (w--) - { - ma = READ(mask++); - if (ma == 0xffffffff) - { - if (srca == 0xff) - { - WRITE(dst, src16); - } - else - { - d = READ(dst); - d = fbOver24 (src, cvt0565to8888(d)); - WRITE(dst, cvt8888to0565(d)); - } - } - else if (ma) - { - d = READ(dst); - d = cvt0565to8888(d); - FbInOverC (src, srca, ma, d, 0, m); - FbInOverC (src, srca, ma, d, 8, n); - FbInOverC (src, srca, ma, d, 16, o); - d = m|n|o; - WRITE(dst, cvt8888to0565(d)); - } - dst++; - } + pixman_image_t *alpha_map = image_from_pict (pict->alphaMap); + + pixman_image_set_alpha_map ( + image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y); + + pixman_image_unref (alpha_map); } + + pixman_image_set_component_alpha (image, pict->componentAlpha); - fbFinishAccess (pMask->pDrawable); - fbFinishAccess (pDst->pDrawable); -} - -void -fbCompositeSrc_8888x8888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - CARD32 *dstLine, *dst, dstMask; - CARD32 *srcLine, *src, s; - FbStride dstStride, srcStride; - CARD8 a; - CARD16 w; - - fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1); - fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1); - - dstMask = FbFullMask (pDst->pDrawable->depth); - - while (height--) + switch (pict->filter) { - dst = dstLine; - dstLine += dstStride; - src = srcLine; - srcLine += srcStride; - w = width; - - while (w--) - { - s = READ(src++); - a = s >> 24; - if (a == 0xff) - WRITE(dst, s & dstMask); - else if (a) - WRITE(dst, fbOver (s, READ(dst)) & dstMask); - dst++; - } + default: + case PictFilterNearest: + case PictFilterFast: + filter = PIXMAN_FILTER_NEAREST; + break; + + case PictFilterBilinear: + case PictFilterGood: + filter = PIXMAN_FILTER_BILINEAR; + break; + + case PictFilterConvolution: + filter = PIXMAN_FILTER_CONVOLUTION; + break; } - - fbFinishAccess (pSrc->pDrawable); - fbFinishAccess (pDst->pDrawable); + + pixman_image_set_filter (image, filter, (pixman_fixed_t *)pict->filter_params, pict->filter_nparams); } -void -fbCompositeSrc_8888x0888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) +static pixman_image_t * +image_from_pict (PicturePtr pict) { - CARD8 *dstLine, *dst; - CARD32 d; - CARD32 *srcLine, *src, s; - CARD8 a; - FbStride dstStride, srcStride; - CARD16 w; + pixman_image_t *image = NULL; - fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 3); - fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1); + if (!pict) + return NULL; - while (height--) + if (pict->pDrawable) { - dst = dstLine; - dstLine += dstStride; - src = srcLine; - srcLine += srcStride; - w = width; - - while (w--) - { - s = READ(src++); - a = s >> 24; - if (a) - { - if (a == 0xff) - d = s; - else - d = fbOver24 (s, Fetch24(dst)); - Store24(dst,d); - } - dst += 3; - } + image = create_bits_picture (pict); } - - fbFinishAccess (pSrc->pDrawable); - fbFinishAccess (pDst->pDrawable); -} - -void -fbCompositeSrc_8888x0565 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - CARD16 *dstLine, *dst; - CARD32 d; - CARD32 *srcLine, *src, s; - CARD8 a; - FbStride dstStride, srcStride; - CARD16 w; - - fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1); - fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1); - - while (height--) + else if (pict->pSourcePict) { - dst = dstLine; - dstLine += dstStride; - src = srcLine; - srcLine += srcStride; - w = width; - - while (w--) + SourcePict *sp = pict->pSourcePict; + + if (sp->type == SourcePictTypeSolidFill) { - s = READ(src++); - a = s >> 24; - if (a) - { - if (a == 0xff) - d = s; - else - { - d = READ(dst); - d = fbOver24 (s, cvt0565to8888(d)); - } - WRITE(dst, cvt8888to0565(d)); - } - dst++; + image = create_solid_fill_image (pict); } - } - - fbFinishAccess (pDst->pDrawable); - fbFinishAccess (pSrc->pDrawable); -} - -void -fbCompositeSrc_0565x0565 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - CARD16 *dstLine, *dst; - CARD16 *srcLine, *src; - FbStride dstStride, srcStride; - CARD16 w; - - fbComposeGetStart (pSrc, xSrc, ySrc, CARD16, srcStride, srcLine, 1); - - fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1); - - while (height--) - { - dst = dstLine; - dstLine += dstStride; - src = srcLine; - srcLine += srcStride; - w = width; - - while (w--) - WRITE(dst, READ(src++)); - } - - fbFinishAccess (pDst->pDrawable); - fbFinishAccess (pSrc->pDrawable); -} - -void -fbCompositeSrcAdd_8000x8000 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - CARD8 *dstLine, *dst; - CARD8 *srcLine, *src; - FbStride dstStride, srcStride; - CARD16 w; - CARD8 s, d; - CARD16 t; - - fbComposeGetStart (pSrc, xSrc, ySrc, CARD8, srcStride, srcLine, 1); - fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 1); - - while (height--) - { - dst = dstLine; - dstLine += dstStride; - src = srcLine; - srcLine += srcStride; - w = width; - - while (w--) + else { - s = READ(src++); - if (s) - { - if (s != 0xff) - { - d = READ(dst); - t = d + s; - s = t | (0 - (t >> 8)); - } - WRITE(dst, s); - } - dst++; + PictGradient *gradient = &pict->pSourcePict->gradient; + + if (sp->type == SourcePictTypeLinear) + image = create_linear_gradient_image (gradient); + else if (sp->type == SourcePictTypeRadial) + image = create_radial_gradient_image (gradient); + else if (sp->type == SourcePictTypeConical) + image = create_conical_gradient_image (gradient); } } - - fbFinishAccess (pDst->pDrawable); - fbFinishAccess (pSrc->pDrawable); -} - -void -fbCompositeSrcAdd_8888x8888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - CARD32 *dstLine, *dst; - CARD32 *srcLine, *src; - FbStride dstStride, srcStride; - CARD16 w; - CARD32 s, d; - CARD16 t; - CARD32 m,n,o,p; - - fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1); - fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1); - - while (height--) - { - dst = dstLine; - dstLine += dstStride; - src = srcLine; - srcLine += srcStride; - w = width; - - while (w--) - { - s = READ(src++); - if (s) - { - if (s != 0xffffffff) - { - d = READ(dst); - if (d) - { - m = FbAdd(s,d,0,t); - n = FbAdd(s,d,8,t); - o = FbAdd(s,d,16,t); - p = FbAdd(s,d,24,t); - s = m|n|o|p; - } - } - WRITE(dst, s); - } - dst++; - } - } - - fbFinishAccess (pDst->pDrawable); - fbFinishAccess (pSrc->pDrawable); + + if (image) + set_image_properties (image, pict); + + return image; } -void -fbCompositeSrcAdd_1000x1000 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - FbBits *dstBits, *srcBits; - FbStride dstStride, srcStride; - int dstBpp, srcBpp; - int dstXoff, dstYoff; - int srcXoff, srcYoff; - - fbGetDrawable(pSrc->pDrawable, srcBits, srcStride, srcBpp, srcXoff, srcYoff); - - fbGetDrawable(pDst->pDrawable, dstBits, dstStride, dstBpp, dstXoff, dstYoff); - - fbBlt (srcBits + srcStride * (ySrc + srcYoff), - srcStride, - xSrc + srcXoff, - - dstBits + dstStride * (yDst + dstYoff), - dstStride, - xDst + dstXoff, - - width, - height, - - GXor, - FB_ALLONES, - srcBpp, - - FALSE, - FALSE); - - fbFinishAccess(pDst->pDrawable); - fbFinishAccess(pSrc->pDrawable); -} +#define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b)) void -fbCompositeSolidMask_nx1xn (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) -{ - FbBits *dstBits; - FbStip *maskBits; - FbStride dstStride, maskStride; - int dstBpp, maskBpp; - int dstXoff, dstYoff; - int maskXoff, maskYoff; - FbBits src; - - fbComposeGetSolid(pSrc, src, pDst->format); - - if ((src & 0xff000000) != 0xff000000) - { - fbCompositeGeneral (op, pSrc, pMask, pDst, - xSrc, ySrc, xMask, yMask, xDst, yDst, - width, height); - return; - } - fbGetStipDrawable (pMask->pDrawable, maskBits, maskStride, maskBpp, maskXoff, maskYoff); - fbGetDrawable (pDst->pDrawable, dstBits, dstStride, dstBpp, dstXoff, dstYoff); - - switch (dstBpp) { - case 32: - break; - case 24: - break; - case 16: - src = cvt8888to0565(src); - break; - } - - src = fbReplicatePixel (src, dstBpp); - - fbBltOne (maskBits + maskStride * (yMask + maskYoff), - maskStride, - xMask + maskXoff, - - dstBits + dstStride * (yDst + dstYoff), - dstStride, - (xDst + dstXoff) * dstBpp, - dstBpp, - - width * dstBpp, - height, - - 0x0, - src, - FB_ALLONES, - 0x0); - - fbFinishAccess (pDst->pDrawable); - fbFinishAccess (pMask->pDrawable); -} - -# define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b)) - -void -fbComposite (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height) +fbWalkCompositeRegion (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height, + Bool srcRepeat, + Bool maskRepeat, + CompositeFunc compositeRect) { RegionRec region; int n; BoxPtr pbox; - CompositeFunc func = NULL; - Bool srcRepeat = pSrc->pDrawable && pSrc->repeat; - Bool maskRepeat = FALSE; - Bool srcAlphaMap = pSrc->alphaMap != 0; - Bool maskAlphaMap = FALSE; - Bool dstAlphaMap = pDst->alphaMap != 0; - int x_msk, y_msk, x_src, y_src, x_dst, y_dst; int w, h, w_this, h_this; - -#ifdef USE_MMX - static Bool mmx_setup = FALSE; - if (!mmx_setup) { - fbComposeSetupMMX(); - mmx_setup = TRUE; - } -#endif - + int x_msk, y_msk, x_src, y_src, x_dst, y_dst; + xDst += pDst->pDrawable->x; yDst += pDst->pDrawable->y; - if (pSrc->pDrawable) { + if (pSrc->pDrawable) + { xSrc += pSrc->pDrawable->x; ySrc += pSrc->pDrawable->y; } @@ -908,441 +297,12 @@ fbComposite (CARD8 op, { xMask += pMask->pDrawable->x; yMask += pMask->pDrawable->y; - maskRepeat = pMask->repeat == RepeatNormal; - maskAlphaMap = pMask->alphaMap != 0; - } - - if (pSrc->pDrawable && (!pMask || pMask->pDrawable) - && !pSrc->transform && !(pMask && pMask->transform) - && !maskAlphaMap && !srcAlphaMap && !dstAlphaMap - && (pSrc->filter != PictFilterConvolution) - && (!pMask || pMask->filter != PictFilterConvolution)) - switch (op) { - case PictOpSrc: -#ifdef USE_MMX - if (!pMask && pSrc->format == pDst->format && - pSrc->format != PICT_a8 && pSrc->pDrawable != pDst->pDrawable) - { - func = fbCompositeCopyAreammx; - } -#endif - break; - case PictOpOver: - if (pMask) - { - if (fbCanGetSolid(pSrc) && - !maskRepeat) - { - srcRepeat = FALSE; - if (PICT_FORMAT_COLOR(pSrc->format)) { - switch (pMask->format) { - case PICT_a8: - switch (pDst->format) { - case PICT_r5g6b5: - case PICT_b5g6r5: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSolidMask_nx8x0565mmx; - else -#endif - func = fbCompositeSolidMask_nx8x0565; - break; - case PICT_r8g8b8: - case PICT_b8g8r8: - func = fbCompositeSolidMask_nx8x0888; - break; - case PICT_a8r8g8b8: - case PICT_x8r8g8b8: - case PICT_a8b8g8r8: - case PICT_x8b8g8r8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSolidMask_nx8x8888mmx; - else -#endif - func = fbCompositeSolidMask_nx8x8888; - break; - default: - break; - } - break; - case PICT_a8r8g8b8: - if (pMask->componentAlpha) { - switch (pDst->format) { - case PICT_a8r8g8b8: - case PICT_x8r8g8b8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSolidMask_nx8888x8888Cmmx; - else -#endif - func = fbCompositeSolidMask_nx8888x8888C; - break; - case PICT_r5g6b5: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSolidMask_nx8888x0565Cmmx; - else -#endif - func = fbCompositeSolidMask_nx8888x0565C; - break; - default: - break; - } - } - break; - case PICT_a8b8g8r8: - if (pMask->componentAlpha) { - switch (pDst->format) { - case PICT_a8b8g8r8: - case PICT_x8b8g8r8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSolidMask_nx8888x8888Cmmx; - else -#endif - func = fbCompositeSolidMask_nx8888x8888C; - break; - case PICT_b5g6r5: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSolidMask_nx8888x0565Cmmx; - else -#endif - func = fbCompositeSolidMask_nx8888x0565C; - break; - default: - break; - } - } - break; - case PICT_a1: - switch (pDst->format) { - case PICT_r5g6b5: - case PICT_b5g6r5: - case PICT_r8g8b8: - case PICT_b8g8r8: - case PICT_a8r8g8b8: - case PICT_x8r8g8b8: - case PICT_a8b8g8r8: - case PICT_x8b8g8r8: - func = fbCompositeSolidMask_nx1xn; - break; - default: - break; - } - break; - default: - break; - } - default: - break; - } - } - else if (! srcRepeat) /* has mask and non-repeating source */ - { - if (pSrc->pDrawable == pMask->pDrawable && - xSrc == xMask && ySrc == yMask && - !pMask->componentAlpha && !maskRepeat) - { - /* source == mask: non-premultiplied data */ - switch (pSrc->format) { - case PICT_x8b8g8r8: - switch (pMask->format) { - case PICT_a8r8g8b8: - case PICT_a8b8g8r8: - switch (pDst->format) { - case PICT_a8r8g8b8: - case PICT_x8r8g8b8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888RevNPx8888mmx; -#endif - break; - case PICT_r5g6b5: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888RevNPx0565mmx; -#endif - break; - default: - break; - } - break; - default: - break; - } - break; - case PICT_x8r8g8b8: - switch (pMask->format) { - case PICT_a8r8g8b8: - case PICT_a8b8g8r8: - switch (pDst->format) { - case PICT_a8b8g8r8: - case PICT_x8b8g8r8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888RevNPx8888mmx; -#endif - break; - case PICT_r5g6b5: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888RevNPx0565mmx; -#endif - break; - default: - break; - } - break; - default: - break; - } - break; - default: - break; - } - break; - } - else - { - /* non-repeating source, repeating mask => translucent window */ - if (fbCanGetSolid(pMask)) - { - if (pSrc->format == PICT_x8r8g8b8 && - pDst->format == PICT_x8r8g8b8 && - pMask->format == PICT_a8) - { -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888x8x8888mmx; -#endif - } - } - } - } - } - else /* no mask */ - { - if (fbCanGetSolid(pSrc)) - { - /* no mask and repeating source */ - switch (pSrc->format) { - case PICT_a8r8g8b8: - switch (pDst->format) { - case PICT_a8r8g8b8: - case PICT_x8r8g8b8: -#ifdef USE_MMX - if (fbHaveMMX()) - { - srcRepeat = FALSE; - func = fbCompositeSolid_nx8888mmx; - } -#endif - break; - case PICT_r5g6b5: -#ifdef USE_MMX - if (fbHaveMMX()) - { - srcRepeat = FALSE; - func = fbCompositeSolid_nx0565mmx; - } -#endif - break; - default: - break; - } - break; - default: - break; - } - } - else if (! srcRepeat) - { - switch (pSrc->format) { - case PICT_a8r8g8b8: - switch (pDst->format) { - case PICT_a8r8g8b8: - case PICT_x8r8g8b8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888x8888mmx; - else -#endif - func = fbCompositeSrc_8888x8888; - break; - case PICT_r8g8b8: - func = fbCompositeSrc_8888x0888; - break; - case PICT_r5g6b5: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888x0565mmx; - else -#endif - func = fbCompositeSrc_8888x0565; - break; - default: - break; - } - break; - case PICT_x8r8g8b8: - switch (pDst->format) { - case PICT_a8r8g8b8: - case PICT_x8r8g8b8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeCopyAreammx; -#endif - break; - default: - break; - } - case PICT_x8b8g8r8: - switch (pDst->format) { - case PICT_a8b8g8r8: - case PICT_x8b8g8r8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeCopyAreammx; -#endif - break; - default: - break; - } - break; - case PICT_a8b8g8r8: - switch (pDst->format) { - case PICT_a8b8g8r8: - case PICT_x8b8g8r8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888x8888mmx; - else -#endif - func = fbCompositeSrc_8888x8888; - break; - case PICT_b8g8r8: - func = fbCompositeSrc_8888x0888; - break; - case PICT_b5g6r5: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrc_8888x0565mmx; - else -#endif - func = fbCompositeSrc_8888x0565; - break; - default: - break; - } - break; - case PICT_r5g6b5: - switch (pDst->format) { - case PICT_r5g6b5: - func = fbCompositeSrc_0565x0565; - break; - default: - break; - } - break; - case PICT_b5g6r5: - switch (pDst->format) { - case PICT_b5g6r5: - func = fbCompositeSrc_0565x0565; - break; - default: - break; - } - break; - default: - break; - } - } - } - break; - case PictOpAdd: - if (pMask == 0) - { - switch (pSrc->format) { - case PICT_a8r8g8b8: - switch (pDst->format) { - case PICT_a8r8g8b8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrcAdd_8888x8888mmx; - else -#endif - func = fbCompositeSrcAdd_8888x8888; - break; - default: - break; - } - break; - case PICT_a8b8g8r8: - switch (pDst->format) { - case PICT_a8b8g8r8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrcAdd_8888x8888mmx; - else -#endif - func = fbCompositeSrcAdd_8888x8888; - break; - default: - break; - } - break; - case PICT_a8: - switch (pDst->format) { - case PICT_a8: -#ifdef USE_MMX - if (fbHaveMMX()) - func = fbCompositeSrcAdd_8000x8000mmx; - else -#endif - func = fbCompositeSrcAdd_8000x8000; - break; - default: - break; - } - break; - case PICT_a1: - switch (pDst->format) { - case PICT_a1: - func = fbCompositeSrcAdd_1000x1000; - break; - default: - break; - } - break; - default: - break; - } - } - break; - } - - if (!func) { - /* no fast path, use the general code */ - fbCompositeGeneral(op, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask, xDst, yDst, width, height); - return; } - if (!miComputeCompositeRegion (®ion, - pSrc, - pMask, - pDst, - xSrc, - ySrc, - xMask, - yMask, - xDst, - yDst, - width, - height)) + if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst, xSrc, ySrc, + xMask, yMask, xDst, yDst, width, height)) return; - + n = REGION_NUM_RECTS (®ion); pbox = REGION_RECTS (®ion); while (n--) @@ -1389,9 +349,9 @@ fbComposite (CARD8 op, w_this = pSrc->pDrawable->width - x_src; x_src += pSrc->pDrawable->x; } - (*func) (op, pSrc, pMask, pDst, - x_src, y_src, x_msk, y_msk, x_dst, y_dst, - w_this, h_this); + (*compositeRect) (op, pSrc, pMask, pDst, + x_src, y_src, x_msk, y_msk, x_dst, y_dst, + w_this, h_this); w -= w_this; x_src += w_this; x_msk += w_this; @@ -1407,6 +367,67 @@ fbComposite (CARD8 op, REGION_UNINIT (pDst->pDrawable->pScreen, ®ion); } +void +fbComposite (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + pixman_region16_t region; + pixman_image_t *src, *mask, *dest; + + if (!miComputeCompositeRegion (®ion, pSrc, pMask, pDst, xSrc, ySrc, + xMask, yMask, xDst, yDst, width, height)) + return; + + src = image_from_pict (pSrc); + mask = image_from_pict (pMask); + dest = image_from_pict (pDst); + + if (src && dest && !(pMask && !mask)) + { + pixman_image_composite (op, src, mask, dest, + xSrc, ySrc, xMask, yMask, xDst, yDst, + width, height, ®ion); + } + + pixman_region_fini (®ion); + + if (src) + pixman_image_unref (src); + if (mask) + pixman_image_unref (mask); + if (dest) + pixman_image_unref (dest); +} + +void +fbCompositeGeneral (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height) +{ + return fbComposite (op, pSrc, pMask, pDst, + xSrc, ySrc, xMask, yMask, xDst, yDst, + width, height); +} + #endif /* RENDER */ Bool @@ -1455,7 +476,7 @@ enum CPUFeatures { static unsigned int detectCPUFeatures(void) { unsigned int features = 0; - unsigned int result; + unsigned int result = 0; #ifdef HAVE_GETISAX if (getisax(&result, 1)) { @@ -1472,8 +493,13 @@ static unsigned int detectCPUFeatures(void) { } #else char vendor[13]; +#ifdef _MSC_VER + int vendor0 = 0, vendor1, vendor2; +#endif vendor[0] = 0; vendor[12] = 0; + +#ifdef __GNUC__ /* see p. 118 of amd64 instruction set manual Vol3 */ /* We need to be careful about the handling of %ebx and * %esp here. We can't declare either one as clobbered @@ -1492,7 +518,7 @@ static unsigned int detectCPUFeatures(void) { "pop %%eax\n" "mov $0x0, %%edx\n" "xor %%ecx, %%eax\n" - "jz 1\n" + "jz 1f\n" "mov $0x00000000, %%eax\n" "push %%ebx\n" @@ -1516,6 +542,45 @@ static unsigned int detectCPUFeatures(void) { : "%eax", "%ecx", "%edx" ); +#elif defined (_MSC_VER) + + _asm { + pushfd + pop eax + mov ecx, eax + xor eax, 00200000h + push eax + popfd + pushfd + pop eax + mov edx, 0 + xor eax, ecx + jz nocpuid + + mov eax, 0 + push ebx + cpuid + mov eax, ebx + pop ebx + mov vendor0, eax + mov vendor1, edx + mov vendor2, ecx + mov eax, 1 + push ebx + cpuid + pop ebx + nocpuid: + mov result, edx + } + memmove (vendor+0, &vendor0, 4); + memmove (vendor+4, &vendor1, 4); + memmove (vendor+8, &vendor2, 4); + +#else +# error unsupported compiler +#endif + + features = 0; if (result) { /* result now contains the standard feature bits */ if (result & (1 << 15)) @@ -1530,14 +595,13 @@ static unsigned int detectCPUFeatures(void) { (strcmp(vendor, "AuthenticAMD") == 0 || strcmp(vendor, "Geode by NSC") == 0)) { /* check for AMD MMX extensions */ - - unsigned int result; +#ifdef __GNUC__ __asm__("push %%ebx\n" "mov $0x80000000, %%eax\n" "cpuid\n" "xor %%edx, %%edx\n" "cmp $0x1, %%eax\n" - "jge 2\n" + "jge 2f\n" "mov $0x80000001, %%eax\n" "cpuid\n" "2:\n" @@ -1547,11 +611,27 @@ static unsigned int detectCPUFeatures(void) { : : "%eax", "%ecx", "%edx" ); +#elif defined _MSC_VER + _asm { + push ebx + mov eax, 80000000h + cpuid + xor edx, edx + cmp eax, 1 + jge notamd + mov eax, 80000001h + cpuid + notamd: + pop ebx + mov result, edx + } +#endif if (result & (1<<22)) features |= MMX_Extensions; } } #endif /* HAVE_GETISAX */ + return features; } diff --git a/fb/fbpict.h b/fb/fbpict.h index 434526e32..3bd0a78a3 100644 --- a/fb/fbpict.h +++ b/fb/fbpict.h @@ -121,7 +121,15 @@ fbCanGetSolid(PicturePtr pict) break; \ case 16: \ (bits) = READ((CARD16 *) __bits__); \ - (bits) = cvt0565to8888(bits); \ + (bits) = cvt0565to0888(bits); \ + break; \ + case 8: \ + (bits) = READ((CARD8 *) __bits__); \ + (bits) = (bits) << 24; \ + break; \ + case 1: \ + (bits) = READ((CARD32 *) __bits__); \ + (bits) = FbLeftStipBits((bits),1) ? 0xff000000 : 0x00000000;\ break; \ default: \ return; \ @@ -153,7 +161,7 @@ fbCanGetSolid(PicturePtr pict) #define cvt8888to0565(s) ((((s) >> 3) & 0x001f) | \ (((s) >> 5) & 0x07e0) | \ (((s) >> 8) & 0xf800)) -#define cvt0565to8888(s) (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \ +#define cvt0565to0888(s) (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \ ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \ ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000))) @@ -375,6 +383,9 @@ typedef struct _FbComposeData { CARD16 height; } FbComposeData; +void +fbCompositeRect (const FbComposeData *data, CARD32 *scanline_buffer); + typedef FASTCALL void (*CombineMaskU) (CARD32 *src, const CARD32 *mask, int width); typedef FASTCALL void (*CombineFuncU) (CARD32 *dest, const CARD32 *src, int width); typedef FASTCALL void (*CombineFuncC) (CARD32 *dest, CARD32 *src, CARD32 *mask, int width); @@ -414,197 +425,6 @@ fbRasterizeEdges (FbBits *buf, xFixed b); /* fbpict.c */ -CARD32 -fbOver (CARD32 x, CARD32 y); - -CARD32 -fbOver24 (CARD32 x, CARD32 y); - -CARD32 -fbIn (CARD32 x, CARD8 y); - -void -fbCompositeSolidMask_nx8x8888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSolidMask_nx8x0888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSolidMask_nx8888x8888C (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSolidMask_nx8x0565 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSolidMask_nx8888x0565C (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSrc_8888x8888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSrc_8888x0888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSrc_8888x0565 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSrc_0565x0565 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSrcAdd_8000x8000 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSrcAdd_8888x8888 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSrcAdd_1000x1000 (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - -void -fbCompositeSolidMask_nx1xn (CARD8 op, - PicturePtr pSrc, - PicturePtr pMask, - PicturePtr pDst, - INT16 xSrc, - INT16 ySrc, - INT16 xMask, - INT16 yMask, - INT16 xDst, - INT16 yDst, - CARD16 width, - CARD16 height); - void fbComposite (CARD8 op, PicturePtr pSrc, @@ -619,6 +439,36 @@ fbComposite (CARD8 op, CARD16 width, CARD16 height); +typedef void (*CompositeFunc) (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height); + +void +fbWalkCompositeRegion (CARD8 op, + PicturePtr pSrc, + PicturePtr pMask, + PicturePtr pDst, + INT16 xSrc, + INT16 ySrc, + INT16 xMask, + INT16 yMask, + INT16 xDst, + INT16 yDst, + CARD16 width, + CARD16 height, + Bool srcRepeat, + Bool maskRepeat, + CompositeFunc compositeRect); + /* fbtrap.c */ void diff --git a/fb/fbtrap.c b/fb/fbtrap.c index 4c67bcdfb..478a80f4f 100644 --- a/fb/fbtrap.c +++ b/fb/fbtrap.c @@ -117,6 +117,9 @@ fbRasterizeTrapezoid (PicturePtr pPicture, RenderEdge l, r; xFixed t, b; + if (!xTrapezoidValid (trap)) + return; + fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); width = pPicture->pDrawable->width; |