* cfbimgblt.c
@ 2002-08-21 23:23 Antonino Daplas
2002-08-22 18:27 ` cfbimgblt.c James Simmons
0 siblings, 1 reply; 4+ messages in thread
From: Antonino Daplas @ 2002-08-21 23:23 UTC (permalink / raw)
To: fbdev
[-- Attachment #1: Type: text/plain, Size: 885 bytes --]
Hi,
I want to address some of the limitations of cfbimgblt.c, but
unfortunately I ended up practically rewriting the whole code. In
theory, the code (slow_imageblit):
a. supports all possible bit depths
b. should be able to handle destination writes that are not aligned by
an unsigned long
c. should be able to handle fix->line_length not a multiple of an
unsigned long
d. framebuffer access is always the size of an unsigned long and aligned
e. preliminary code for drawing the logo.
f. added Paul Mackerra's endianness patch (plus some of my own), but I
have no big-endian machine, so it's untested, and perhaps incorrect.
The only tests I've done for slow_imageblit is at 8, 16, 24, and 32 bpp,
and forcibly misaligning image->dx by 1 pixel. The code is slow, so I
included fast_imageblit for 8, 16 and 32 bpp which is an implementation
of fbcon-cfb8/16/32.c.
Tony
[-- Attachment #2: cfbimgblt.c --]
[-- Type: text/x-c, Size: 9731 bytes --]
/*
* Generic BitBLT function for frame buffer with packed pixels of any depth.
*
* Copyright (C) June 1999 James Simmons
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*
* NOTES:
*
* This function copys a image from system memory to video memory. The
* image can be a bitmap where each 0 represents the background color and
* each 1 represents the foreground color. Great for font handling. It can
* also be a color image. This is determined by image_depth. The color image
* must be laid out exactly in the same format as the framebuffer. Yes I know
* their are cards with hardware that coverts images of various depths to the
* framebuffer depth. But not every card has this. All images must be rounded
* up to the nearest byte. For example a bitmap 12 bits wide must be two
* bytes width.
*
* FIXME
* The code for 24 bit is horrible. It copies byte by byte size instead of
* longs like the other sizes. Needs to be optimized.
*
* Tony:
* Incorporate mask tables similar to fbcon-cfb*.c in 2.4 API. This speeds
* up the code significantly.
*
* Code for depths not multiples of BITS_PER_LONG is still kludgy, which is
* still processed a bit at a time.
*
* Also need to add code to deal with cards endians that are different than
* the native cpu endians. I also need to deal with MSB position in the word.
*
*/
#include <linux/string.h>
#include <linux/fb.h>
#include <asm/types.h>
#include <video/fbcon.h>
#define DEBUG
#ifdef DEBUG
#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt,__FUNCTION__,## args)
#else
#define DPRINTK(fmt, args...)
#endif
static u32 cfb_tab8[] = {
#if defined(__BIG_ENDIAN)
0x00000000,0x000000ff,0x0000ff00,0x0000ffff,
0x00ff0000,0x00ff00ff,0x00ffff00,0x00ffffff,
0xff000000,0xff0000ff,0xff00ff00,0xff00ffff,
0xffff0000,0xffff00ff,0xffffff00,0xffffffff
#elif defined(__LITTLE_ENDIAN)
0x00000000,0xff000000,0x00ff0000,0xffff0000,
0x0000ff00,0xff00ff00,0x00ffff00,0xffffff00,
0x000000ff,0xff0000ff,0x00ff00ff,0xffff00ff,
0x0000ffff,0xff00ffff,0x00ffffff,0xffffffff
#else
#error FIXME: No endianness??
#endif
};
static u32 cfb_tab16[] = {
#if defined(__BIG_ENDIAN)
0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
#elif defined(__LITTLE_ENDIAN)
0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
#else
#error FIXME: No endianness??
#endif
};
static u32 cfb_tab32[] = {
0x00000000, 0xffffffff
};
#if BITS_PER_LONG == 32
#define FB_WRITEL(x,y) fb_writel(x,y)
#define FB_READL(x) fb_readl(x)
#else
#define FB_WRITEL(x,y) fb_writeq(x,y)
#define FB_READL(x) fb_readq(x)
#endif
#if defined (__BIG_ENDIAN)
#define LEFT_POS(bpp) (BITS_PER_LONG - bpp)
#define NEXT_POS(pos, bpp) ((pos) -= (bpp))
#define SHIFT_HIGH(val, bits) ((val) >> (bits))
#define SHIFT_LOW(val, bits) ((val) << (bits))
#else
#define LEFT_POS(bpp) (0)
#define NEXT_POS(pos, bpp) ((pos) += (bpp))
#define SHIFT_HIGH(val, bits) ((val) << (bits))
#define SHIFT_LOW(val, bits) ((val) >> (bits))
#endif
static inline void color_imageblit(struct fb_image *image, struct fb_info *p, u8 *dst1,
unsigned long start_index, unsigned long pitch_index)
{
/* Draw the penguin */
int i, n;
unsigned long bitmask = SHIFT_LOW(~0UL, BITS_PER_LONG - p->var.bits_per_pixel);
unsigned long *palette = (unsigned long *) p->pseudo_palette;
unsigned long *dst, *dst2, color = 0, val, shift;
unsigned long null_bits = BITS_PER_LONG - p->var.bits_per_pixel;
u8 *src = image->data;
dst2 = (unsigned long *) dst1;
for (i = image->height; i--; ) {
n = image->width;
dst = (unsigned long *) dst1;
shift = 0;
val = 0;
if (start_index) {
unsigned long start_mask = ~(SHIFT_HIGH(~0UL, start_index));
val = FB_READL(dst) & start_mask;
shift = start_index;
}
while (n--) {
if (p->fix.visual == FB_VISUAL_PSEUDOCOLOR)
color = *src & bitmask;
if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
p->fix.visual == FB_VISUAL_DIRECTCOLOR )
color = palette[*src] & bitmask;
val |= SHIFT_HIGH(color, shift);
if (shift >= null_bits) {
FB_WRITEL(val, dst++);
if (shift == null_bits)
val = 0;
else
val = SHIFT_LOW(color, BITS_PER_LONG - shift);
}
shift += p->var.bits_per_pixel;
shift &= (BITS_PER_LONG - 1);
src++;
}
if (shift) {
unsigned long end_mask = SHIFT_HIGH(~0UL, shift);
FB_WRITEL((FB_READL(dst) & end_mask) | val, dst);
}
dst1 += p->fix.line_length;
if (pitch_index) {
dst2 += p->fix.line_length;
dst1 = (char *) dst2;
(unsigned long) dst1 &= ~(sizeof(unsigned long) - 1);
start_index += pitch_index;
start_index &= BITS_PER_LONG - 1;
}
}
}
static inline void slow_imageblit(struct fb_image *image, struct fb_info *p, u8 *dst1,
unsigned long fgcolor, unsigned long bgcolor,
unsigned long start_index, unsigned long pitch_index)
{
unsigned long i, j, l = 8;
unsigned long shift, color, bpp = p->var.bits_per_pixel;
unsigned long *dst, *dst2, val, pitch = p->fix.line_length;
unsigned long null_bits = BITS_PER_LONG - bpp;
u8 *src = image->data;
dst2 = (unsigned long *) dst1;
for (i = image->height; i--; ) {
shift = 0;
val = 0;
j = image->width;
dst = (unsigned long *) dst1;
/* write start bits, if any */
if (start_index) {
unsigned long start_mask = ~(SHIFT_HIGH(~0UL, start_index));
val = FB_READL(dst) & start_mask;
shift = start_index;
}
while (j--) {
l--;
if (*src & (1 << l))
color = fgcolor;
else
color = bgcolor;
val |= SHIFT_HIGH(color, shift);
/* Did the bitshift spill bits to the next long? */
if (shift >= null_bits) {
FB_WRITEL(val, dst++);
if (shift == null_bits)
val = 0;
else
val = SHIFT_LOW(color, BITS_PER_LONG - shift);
}
shift += bpp;
shift &= (BITS_PER_LONG - 1);
if (!l) { l = 8; src++; };
}
/* write end bits, if any*/
if (shift) {
unsigned long end_mask = SHIFT_HIGH(~0UL, shift);
FB_WRITEL((FB_READL(dst) & end_mask) | val, dst);
}
dst1 += pitch;
if (pitch_index) {
dst2 += pitch;
dst1 = (char *) dst2;
(unsigned long) dst1 &= ~(sizeof(unsigned long) - 1);
start_index += pitch_index;
start_index &= BITS_PER_LONG - 1;
}
}
}
static inline void fast_imageblit(struct fb_image *image, struct fb_info *p, u8 *dst1,
unsigned long fgcolor, unsigned long bgcolor)
{
int i, j, k, l = 8, n;
unsigned long bit_mask, end_mask, eorx;
unsigned long fgx = fgcolor, bgx = bgcolor, pad, bpp = p->var.bits_per_pixel;
unsigned long tmp = (1 << bpp) - 1;
unsigned long ppw = BITS_PER_LONG/bpp, ppos;
unsigned long *dst;
u32 *tab = NULL;
char *src = image->data;
switch (ppw) {
case 4:
tab = cfb_tab8;
break;
case 2:
tab = cfb_tab16;
break;
case 1:
tab = cfb_tab32;
break;
}
for (i = ppw-1; i--; ) {
fgx <<= bpp;
bgx <<= bpp;
fgx |= fgcolor;
bgx |= bgcolor;
}
n = ((image->width + 7) / 8);
pad = (n * 8) - image->width;
n = image->width % ppw;
bit_mask = (1 << ppw) - 1;
eorx = fgx ^ bgx;
k = image->width/ppw;
for (i = image->height; i--; ) {
dst = (unsigned long *) dst1;
for (j = k; j--; ) {
l -= ppw;
end_mask = tab[(*src >> l) & bit_mask];
FB_WRITEL((end_mask & eorx)^bgx, dst++);
if (!l) { l = 8; src++; }
}
if (n) {
end_mask = 0;
ppos = LEFT_POS(bpp);
for (j = n; j > 0; j--) {
l--;
if (*src & (1 << l))
end_mask |= tmp << ppos;
NEXT_POS(ppos, bpp);
if (!l) { l = 8; src++; }
}
FB_WRITEL((end_mask & eorx)^bgx, dst++);
}
l -= pad;
dst1 += p->fix.line_length;
}
}
void cfb_imageblit(struct fb_info *p, struct fb_image *image)
{
int x2, y2;
unsigned long fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
unsigned long bpl = sizeof(unsigned long), bpp = p->var.bits_per_pixel;
u8 *dst1;
/*
* We could use hardware clipping but on many cards you get around hardware
* clipping by writing to framebuffer directly like we are doing here.
*/
x2 = image->dx + image->width;
y2 = image->dy + image->height;
image->dx = image->dx > 0 ? image->dx : 0;
image->dy = image->dy > 0 ? image->dy : 0;
x2 = x2 < p->var.xres_virtual ? x2 : p->var.xres_virtual;
y2 = y2 < p->var.yres_virtual ? y2 : p->var.yres_virtual;
image->width = x2 - image->dx;
image->height = y2 - image->dy;
bitstart = (image->dy * p->fix.line_length * 8) + (image->dx * bpp);
start_index = bitstart & (BITS_PER_LONG - 1);
pitch_index = (p->fix.line_length & (bpl - 1)) * 8;
bitstart /= 8;
bitstart &= ~(bpl - 1);
dst1 = p->screen_base + bitstart;
if (image->depth == 1) {
if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
p->fix.visual == FB_VISUAL_DIRECTCOLOR) {
fgcolor = ((u32 *)(p->pseudo_palette))[image->fg_color];
bgcolor = ((u32 *)(p->pseudo_palette))[image->bg_color];
} else {
fgcolor = image->fg_color;
bgcolor = image->bg_color;
}
if (BITS_PER_LONG % bpp == 0 && !start_index && !pitch_index &&
bpp >= 8 && bpp <= 32)
fast_imageblit(image, p, dst1, fgcolor, bgcolor);
else
slow_imageblit(image, p, dst1, fgcolor, bgcolor, start_index, pitch_index);
}
else if (image->depth == bpp)
color_imageblit(image, p, dst1, start_index, pitch_index);
}
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: cfbimgblt.c
2002-08-21 23:23 cfbimgblt.c Antonino Daplas
@ 2002-08-22 18:27 ` James Simmons
2002-08-24 12:33 ` cfbimgblt.c Paul Mackerras
[not found] ` <15719.32025.236298.592156@argo.ozlabs.ibm.com>
0 siblings, 2 replies; 4+ messages in thread
From: James Simmons @ 2002-08-22 18:27 UTC (permalink / raw)
To: Antonino Daplas, Paul Mackerras; +Cc: fbdev, Linux Kernel Mailing List
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1523 bytes --]
> Hi,
>
> I want to address some of the limitations of cfbimgblt.c, but
> unfortunately I ended up practically rewriting the whole code. In
> theory, the code (slow_imageblit):
Done.
> a. supports all possible bit depths
Needs to added.
> b. should be able to handle destination writes that are not aligned by
> an unsigned long
Not added.
> c. should be able to handle fix->line_length not a multiple of an
> unsigned long
Access is also a unsigned long but currently is not aligned. It will be
fixed.
> d. framebuffer access is always the size of an unsigned long and aligned
Yeah!!!
> e. preliminary code for drawing the logo.
Paul please test the code.
> f. added Paul Mackerra's endianness patch (plus some of my own), but I
> have no big-endian machine, so it's untested, and perhaps incorrect.
> The only tests I've done for slow_imageblit is at 8, 16, 24, and 32 bpp,
> and forcibly misaligning image->dx by 1 pixel. The code is slow, so I
> included fast_imageblit for 8, 16 and 32 bpp which is an implementation
> of fbcon-cfb8/16/32.c.
Will begin testing today.
MS: (n) 1. A debilitating and surprisingly widespread affliction that
renders the sufferer barely able to perform the simplest task. 2. A disease.
James Simmons [jsimmons@users.sf.net] ____/|
fbdev/console/gfx developer \ o.O|
http://www.linux-fbdev.org =(_)=
http://linuxgfx.sourceforge.net U
http://linuxconsole.sourceforge.net
[-- Attachment #2: Type: TEXT/PLAIN, Size: 9770 bytes --]
/*
* Generic BitBLT function for frame buffer with packed pixels of any depth.
*
* Copyright (C) June 2002 James Simmons <jsimmons@users.sf.net>
8 Antonino Daplas <adaplas@pol.net>
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*
* NOTES:
*
* This function copys a image from system memory to video memory. The
* image can be a bitmap where each 0 represents the background color and
* each 1 represents the foreground color. Great for font handling. It can
* also be a color image. This is determined by image_depth. The color image
* must be laid out exactly in the same format as the framebuffer. Yes I know
* their are cards with hardware that coverts images of various depths to the
* framebuffer depth. But not every card has this. All images must be rounded
* up to the nearest byte. For example a bitmap 12 bits wide must be two
* bytes width.
*
* FIXME
* The code for 24 bit is horrible. It copies byte by byte size instead of
* longs like the other sizes. Needs to be optimized.
*
* Tony:
* Incorporate mask tables similar to fbcon-cfb*.c in 2.4 API. This speeds
* up the code significantly.
*
* Code for depths not multiples of BITS_PER_LONG is still kludgy, which is
* still processed a bit at a time.
*
* Also need to add code to deal with cards endians that are different than
* the native cpu endians. I also need to deal with MSB position in the word.
*
*/
#include <linux/string.h>
#include <linux/fb.h>
#include <asm/types.h>
#define DEBUG
#ifdef DEBUG
#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt,__FUNCTION__,## args)
#else
#define DPRINTK(fmt, args...)
#endif
static u32 cfb_tab8[] = {
#if defined(__BIG_ENDIAN)
0x00000000,0x000000ff,0x0000ff00,0x0000ffff,
0x00ff0000,0x00ff00ff,0x00ffff00,0x00ffffff,
0xff000000,0xff0000ff,0xff00ff00,0xff00ffff,
0xffff0000,0xffff00ff,0xffffff00,0xffffffff
#elif defined(__LITTLE_ENDIAN)
0x00000000,0xff000000,0x00ff0000,0xffff0000,
0x0000ff00,0xff00ff00,0x00ffff00,0xffffff00,
0x000000ff,0xff0000ff,0x00ff00ff,0xffff00ff,
0x0000ffff,0xff00ffff,0x00ffffff,0xffffffff
#else
#error FIXME: No endianness??
#endif
};
static u32 cfb_tab16[] = {
#if defined(__BIG_ENDIAN)
0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
#elif defined(__LITTLE_ENDIAN)
0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
#else
#error FIXME: No endianness??
#endif
};
static u32 cfb_tab32[] = {
0x00000000, 0xffffffff
};
#if BITS_PER_LONG == 32
#define FB_WRITEL(x,y) fb_writel(x,y)
#define FB_READL(x) fb_readl(x)
#else
#define FB_WRITEL(x,y) fb_writeq(x,y)
#define FB_READL(x) fb_readq(x)
#endif
#if defined (__BIG_ENDIAN)
#define LEFT_POS(bpp) (BITS_PER_LONG - bpp)
#define NEXT_POS(pos, bpp) ((pos) -= (bpp))
#define SHIFT_HIGH(val, bits) ((val) >> (bits))
#define SHIFT_LOW(val, bits) ((val) << (bits))
#else
#define LEFT_POS(bpp) (0)
#define NEXT_POS(pos, bpp) ((pos) += (bpp))
#define SHIFT_HIGH(val, bits) ((val) << (bits))
#define SHIFT_LOW(val, bits) ((val) >> (bits))
#endif
static inline void color_imageblit(struct fb_image *image, struct fb_info *p, u8 *dst1,
unsigned long start_index, unsigned long pitch_index)
{
/* Draw the penguin */
int i, n;
unsigned long bitmask = SHIFT_LOW(~0UL, BITS_PER_LONG - p->var.bits_per_pixel);
unsigned long *palette = (unsigned long *) p->pseudo_palette;
unsigned long *dst, *dst2, color = 0, val, shift;
unsigned long null_bits = BITS_PER_LONG - p->var.bits_per_pixel;
u8 *src = image->data;
dst2 = (unsigned long *) dst1;
for (i = image->height; i--; ) {
n = image->width;
dst = (unsigned long *) dst1;
shift = 0;
val = 0;
if (start_index) {
unsigned long start_mask = ~(SHIFT_HIGH(~0UL, start_index));
val = FB_READL(dst) & start_mask;
shift = start_index;
}
while (n--) {
if (p->fix.visual == FB_VISUAL_PSEUDOCOLOR)
color = *src & bitmask;
if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
p->fix.visual == FB_VISUAL_DIRECTCOLOR )
color = palette[*src] & bitmask;
val |= SHIFT_HIGH(color, shift);
if (shift >= null_bits) {
FB_WRITEL(val, dst++);
if (shift == null_bits)
val = 0;
else
val = SHIFT_LOW(color, BITS_PER_LONG - shift);
}
shift += p->var.bits_per_pixel;
shift &= (BITS_PER_LONG - 1);
src++;
}
if (shift) {
unsigned long end_mask = SHIFT_HIGH(~0UL, shift);
FB_WRITEL((FB_READL(dst) & end_mask) | val, dst);
}
dst1 += p->fix.line_length;
if (pitch_index) {
dst2 += p->fix.line_length;
dst1 = (char *) dst2;
(unsigned long) dst1 &= ~(sizeof(unsigned long) - 1);
start_index += pitch_index;
start_index &= BITS_PER_LONG - 1;
}
}
}
static inline void slow_imageblit(struct fb_image *image, struct fb_info *p, u8 *dst1,
unsigned long fgcolor, unsigned long bgcolor,
unsigned long start_index, unsigned long pitch_index)
{
unsigned long i, j, l = 8;
unsigned long shift, color, bpp = p->var.bits_per_pixel;
unsigned long *dst, *dst2, val, pitch = p->fix.line_length;
unsigned long null_bits = BITS_PER_LONG - bpp;
u8 *src = image->data;
dst2 = (unsigned long *) dst1;
for (i = image->height; i--; ) {
shift = 0;
val = 0;
j = image->width;
dst = (unsigned long *) dst1;
/* write start bits, if any */
if (start_index) {
unsigned long start_mask = ~(SHIFT_HIGH(~0UL, start_index));
val = FB_READL(dst) & start_mask;
shift = start_index;
}
while (j--) {
l--;
if (*src & (1 << l))
color = fgcolor;
else
color = bgcolor;
val |= SHIFT_HIGH(color, shift);
/* Did the bitshift spill bits to the next long? */
if (shift >= null_bits) {
FB_WRITEL(val, dst++);
if (shift == null_bits)
val = 0;
else
val = SHIFT_LOW(color, BITS_PER_LONG - shift);
}
shift += bpp;
shift &= (BITS_PER_LONG - 1);
if (!l) { l = 8; src++; };
}
/* write end bits, if any */
if (shift) {
unsigned long end_mask = SHIFT_HIGH(~0UL, shift);
FB_WRITEL((FB_READL(dst) & end_mask) | val, dst);
}
dst1 += pitch;
if (pitch_index) {
dst2 += pitch;
dst1 = (char *) dst2;
(unsigned long) dst1 &= ~(sizeof(unsigned long) - 1);
start_index += pitch_index;
start_index &= BITS_PER_LONG - 1;
}
}
}
static inline void fast_imageblit(struct fb_image *image, struct fb_info *p, u8 *dst1,
unsigned long fgcolor, unsigned long bgcolor)
{
int i, j, k, l = 8, n;
unsigned long bit_mask, end_mask, eorx;
unsigned long fgx = fgcolor, bgx = bgcolor, pad, bpp = p->var.bits_per_pixel;
unsigned long tmp = (1 << bpp) - 1;
unsigned long ppw = BITS_PER_LONG/bpp, ppos;
unsigned long *dst;
u32 *tab = NULL;
char *src = image->data;
switch (ppw) {
case 4:
tab = cfb_tab8;
break;
case 2:
tab = cfb_tab16;
break;
case 1:
tab = cfb_tab32;
break;
}
for (i = ppw-1; i--; ) {
fgx <<= bpp;
bgx <<= bpp;
fgx |= fgcolor;
bgx |= bgcolor;
}
n = ((image->width + 7) / 8);
pad = (n * 8) - image->width;
n = image->width % ppw;
bit_mask = (1 << ppw) - 1;
eorx = fgx ^ bgx;
k = image->width/ppw;
for (i = image->height; i--; ) {
dst = (unsigned long *) dst1;
for (j = k; j--; ) {
l -= ppw;
end_mask = tab[(*src >> l) & bit_mask];
FB_WRITEL((end_mask & eorx)^bgx, dst++);
if (!l) { l = 8; src++; }
}
if (n) {
end_mask = 0;
ppos = LEFT_POS(bpp);
for (j = n; j > 0; j--) {
l--;
if (*src & (1 << l))
end_mask |= tmp << ppos;
NEXT_POS(ppos, bpp);
if (!l) { l = 8; src++; }
}
FB_WRITEL((end_mask & eorx)^bgx, dst++);
}
l -= pad;
dst1 += p->fix.line_length;
}
}
void cfb_imageblit(struct fb_info *p, struct fb_image *image)
{
int x2, y2;
unsigned long fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
unsigned long bpl = sizeof(unsigned long), bpp = p->var.bits_per_pixel;
u8 *dst1;
/*
* We could use hardware clipping but on many cards you get around hardware
* clipping by writing to framebuffer directly like we are doing here.
*/
x2 = image->dx + image->width;
y2 = image->dy + image->height;
image->dx = image->dx > 0 ? image->dx : 0;
image->dy = image->dy > 0 ? image->dy : 0;
x2 = x2 < p->var.xres_virtual ? x2 : p->var.xres_virtual;
y2 = y2 < p->var.yres_virtual ? y2 : p->var.yres_virtual;
image->width = x2 - image->dx;
image->height = y2 - image->dy;
bitstart = (image->dy * p->fix.line_length * 8) + (image->dx * bpp);
start_index = bitstart & (BITS_PER_LONG - 1);
pitch_index = (p->fix.line_length & (bpl - 1)) * 8;
bitstart /= 8;
bitstart &= ~(bpl - 1);
dst1 = p->screen_base + bitstart;
if (image->depth == 1) {
if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
p->fix.visual == FB_VISUAL_DIRECTCOLOR) {
fgcolor = ((u32 *)(p->pseudo_palette))[image->fg_color];
bgcolor = ((u32 *)(p->pseudo_palette))[image->bg_color];
} else {
fgcolor = image->fg_color;
bgcolor = image->bg_color;
}
if (BITS_PER_LONG % bpp == 0 && !start_index && !pitch_index &&
bpp >= 8 && bpp <= 32)
fast_imageblit(image, p, dst1, fgcolor, bgcolor);
else
slow_imageblit(image, p, dst1, fgcolor, bgcolor, start_index, pitch_index);
}
else if (image->depth == bpp)
color_imageblit(image, p, dst1, start_index, pitch_index);
}
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: cfbimgblt.c
2002-08-22 18:27 ` cfbimgblt.c James Simmons
@ 2002-08-24 12:33 ` Paul Mackerras
[not found] ` <15719.32025.236298.592156@argo.ozlabs.ibm.com>
1 sibling, 0 replies; 4+ messages in thread
From: Paul Mackerras @ 2002-08-24 12:33 UTC (permalink / raw)
To: James Simmons; +Cc: Antonino Daplas, fbdev, Linux Kernel Mailing List
James Simmons writes:
> Paul please test the code.
(The new cfbimgblt.c, that is.)
It mostly seems to be fine, except there are some problems with the
cursor. I have only tested it with the standard 8x16 font so far
though. I had to add a #include <video/fbcon.h> near the top to get
the definitions of fb_readl and fb_writel.
It seems to be not erasing the cursor image when it should. So, if I
am logged in on the console and I type a few characters and then press
backspace a few times, it leaves those character positions entirely
white. Also, when I press return it leaves the cursor image on that
line as well as drawing the cursor after the shell prompt on the next
line.
I just tried with the old cfbimgblt.c and it also does the same
thing. So it's not the new cfbimgblt.c that is doing this, it's
something else in your fbcon changes (or just possibly mine :). This
is with atyfb with my patches.
Paul.
-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone? Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
^ permalink raw reply [flat|nested] 4+ messages in thread[parent not found: <15719.32025.236298.592156@argo.ozlabs.ibm.com>]
* Re: cfbimgblt.c
[not found] ` <15719.32025.236298.592156@argo.ozlabs.ibm.com>
@ 2002-08-24 22:59 ` Antonino Daplas
0 siblings, 0 replies; 4+ messages in thread
From: Antonino Daplas @ 2002-08-24 22:59 UTC (permalink / raw)
To: Paul Mackerras; +Cc: James Simmons, fbdev, Linux Kernel Mailing List
[-- Attachment #1: Type: text/plain, Size: 1534 bytes --]
On Sat, 2002-08-24 at 20:33, Paul Mackerras wrote:
Hi Paul,
> James Simmons writes:
>
> > Paul please test the code.
>
> (The new cfbimgblt.c, that is.)
>
Thanks for testing the code :)
> It mostly seems to be fine, except there are some problems with the
> cursor. I have only tested it with the standard 8x16 font so far
> though. I had to add a #include <video/fbcon.h> near the top to get
> the definitions of fb_readl and fb_writel.
>
Can you test it with a bit depth not a multiple of 32/64? Or just force
the code to always call slow_imageblit? I'm concerned about
slow_imageblit not correct with big endian machines.
> It seems to be not erasing the cursor image when it should. So, if I
> am logged in on the console and I type a few characters and then press
> backspace a few times, it leaves those character positions entirely
> white. Also, when I press return it leaves the cursor image on that
> line as well as drawing the cursor after the shell prompt on the next
> line.
>
It looks like a fillrect problem.
> I just tried with the old cfbimgblt.c and it also does the same
> thing. So it's not the new cfbimgblt.c that is doing this, it's
> something else in your fbcon changes (or just possibly mine :). This
> is with atyfb with my patches.
> Paul.
I'm also attaching cfbfillrect.c which hopefully addresses some of the
problems which Geert mentioned before (access/pitch alignment, support
for all bit depths, etc).
Tony
PS. Sorry about the attachment, my mailer mangles inline text.
[-- Attachment #2: cfbfillrect.c --]
[-- Type: text/x-c, Size: 4433 bytes --]
/*
* Generic fillrect for frame buffers with packed pixels of any depth.
*
* Copyright (C) 2000 James Simmons (jsimmons@linux-fbdev.org)
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*
* NOTES:
*
* The code for depths like 24 that don't have integer number of pixels per
* long is broken and needs to be fixed. For now I turned these types of
* mode off.
*
* Also need to add code to deal with cards endians that are different than
* the native cpu endians. I also need to deal with MSB position in the word.
*
*/
#include <linux/string.h>
#include <linux/fb.h>
#include <asm/types.h>
#include <video/fbcon.h>
#if BITS_PER_LONG == 32
#define FB_WRITEL(x,y) fb_writel(x,y)
#define FB_READL(x) fb_readl(x)
#else
#define FB_WRITEL(x,y) fb_writeq(x,y)
#define FB_READL(x) fb_readq(x)
#endif
#if defined (__BIG_ENDIAN)
#define SHIFT_HIGH(val, bits) ((val) >> (bits))
#define SHIFT_LOW(val, bits) ((val) << (bits))
#else
#define SHIFT_HIGH(val, bits) ((val) << (bits))
#define SHIFT_LOW(val, bits) ((val) >> (bits))
#endif
void cfb_fillrect(struct fb_info *p, struct fb_fillrect *rect)
{
unsigned long start_index, pitch_index;
unsigned long height, fg, bitstart, shift, color;
unsigned long bpp = p->var.bits_per_pixel;
unsigned long null_bits = BITS_PER_LONG - bpp;
unsigned long n, x2, y2, linesize = p->fix.line_length;
unsigned long bpl = sizeof(unsigned long);
unsigned long *dst = NULL;
char *dst1, *dst2;
if (!rect->width || !rect->height)
return;
/* We could use hardware clipping but on many cards you get around
* hardware clipping by writing to framebuffer directly. */
x2 = rect->dx + rect->width;
y2 = rect->dy + rect->height;
x2 = x2 < p->var.xres_virtual ? x2 : p->var.xres_virtual;
y2 = y2 < p->var.yres_virtual ? y2 : p->var.yres_virtual;
rect->width = x2 - rect->dx;
height = y2 - rect->dy;
if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
p->fix.visual == FB_VISUAL_DIRECTCOLOR )
fg = ((u32 *) (p->pseudo_palette))[rect->color];
else
fg = rect->color;
bitstart = (((rect->dy * linesize) * 8) +
rect->dx * bpp);
start_index = bitstart & (BITS_PER_LONG - 1);
/* line_length not a multiple of an unsigned long? */
pitch_index = (linesize & (bpl - 1)) * 8;
bitstart /= 8;
bitstart &= ~(bpl - 1);
dst1 = dst2 = p->screen_base + bitstart;
switch (rect->rop) {
case ROP_COPY:
do {
dst = (unsigned long *) dst1;
shift = 0;
color = 0;
n = rect->width;
/*
* read leading bits
*/
if (start_index) {
unsigned long start_mask = ~(SHIFT_HIGH(~0UL, start_index));
color = FB_READL(dst) & start_mask;
shift = start_index;
}
while (n--) {
color |= SHIFT_HIGH(fg, shift);
if (shift >= null_bits) {
FB_WRITEL(color, dst++);
if (shift == null_bits)
color = 0;
else
color = SHIFT_LOW(color, BITS_PER_LONG - shift);
}
shift += bpp;
shift &= (BITS_PER_LONG - 1);
}
/*
* write trailing bits
*/
if (shift) {
unsigned long end_mask = SHIFT_HIGH(~0UL, shift);
FB_WRITEL((FB_READL(dst) & end_mask) | color, dst);
}
if (!pitch_index) {
dst1 += linesize;
}
else {
dst2 += linesize;
dst1 = dst2;
(unsigned long) dst1 &= ~(bpl - 1);
start_index += pitch_index;
start_index &= BITS_PER_LONG - 1;
}
} while (--height);
break;
case ROP_XOR:
do {
dst = (unsigned long *) dst1;
shift = start_index;
color = 0;
n = rect->width;
while (n--) {
color |= SHIFT_HIGH(fg, shift);
if (shift >= null_bits) {
FB_WRITEL(FB_READL(dst) ^ color, dst);
dst++;
if (shift == null_bits)
color = 0;
else
color = SHIFT_LOW(color, BITS_PER_LONG - shift);
}
shift += bpp;
shift &= (BITS_PER_LONG - 1);
}
if (shift)
FB_WRITEL(FB_READL(dst) ^ color, dst);
if (!pitch_index) {
dst1 += linesize;
}
else {
dst2 += linesize;
dst1 = dst2;
(unsigned long) dst1 &= ~(bpl - 1);
start_index += pitch_index;
start_index &= BITS_PER_LONG - 1;
}
} while (--height);
break;
}
return;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-08-24 22:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-21 23:23 cfbimgblt.c Antonino Daplas
2002-08-22 18:27 ` cfbimgblt.c James Simmons
2002-08-24 12:33 ` cfbimgblt.c Paul Mackerras
[not found] ` <15719.32025.236298.592156@argo.ozlabs.ibm.com>
2002-08-24 22:59 ` cfbimgblt.c Antonino Daplas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).