X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/78c828aae07db0b15a66577d9230cb848fe536fa..d1455ab44c24de50db9c4ed7efb2ac2a523b9fdd:/lib/gdi/gpixmap.cpp diff --git a/lib/gdi/gpixmap.cpp b/lib/gdi/gpixmap.cpp index 9e8219a5..8fc26399 100644 --- a/lib/gdi/gpixmap.cpp +++ b/lib/gdi/gpixmap.cpp @@ -1,5 +1,6 @@ #include #include +#include gLookup::gLookup() :size(0), lookup(0) @@ -48,48 +49,79 @@ void gLookup::build(int _size, const gPalette &pal, const gRGB &start, const gRG } } -gSurface::~gSurface() +gSurface::gSurface() { + x = 0; + y = 0; + bpp = 0; + bypp = 0; + stride = 0; + data = 0; + data_phys = 0; + clut.colors = 0; + clut.data = 0; + type = 0; } -gSurfaceSystem::gSurfaceSystem(eSize size, int _bpp) +gSurface::gSurface(eSize size, int _bpp, int accel) { - x=size.width(); - y=size.height(); - bpp=_bpp; + x = size.width(); + y = size.height(); + bpp = _bpp; + switch (bpp) { case 8: - bypp=1; + bypp = 1; break; case 15: case 16: - bypp=2; + bypp = 2; break; case 24: // never use 24bit mode case 32: - bypp=4; + bypp = 4; break; default: - bypp=(bpp+7)/8; + bypp = (bpp+7)/8; } - stride=x*bypp; - if (bpp==8) - { - clut.colors=256; - clut.data=new gRGB[clut.colors]; - } else + + stride = x*bypp; + + data = 0; + data_phys = 0; + + if (accel) { - clut.colors=0; - clut.data=0; + stride += 63; + stride &=~63; + + if (gAccel::getInstance()) + eDebug("accel memory: %d", gAccel::getInstance()->accelAlloc(data, data_phys, y * stride)); + else + eDebug("no accel available"); } - data=malloc(x*y*bypp); + + clut.colors = 0; + clut.data = 0; + + if (!data) + data = malloc(y * stride); + + type = 1; } -gSurfaceSystem::~gSurfaceSystem() +gSurface::~gSurface() { - free(data); - delete[] clut.data; + if (type) + { + if (data_phys) + gAccel::getInstance()->accelFree(data_phys); + else + free(data); + + delete[] clut.data; + } } gPixmap *gPixmap::lock() @@ -111,26 +143,34 @@ void gPixmap::fill(const gRegion ®ion, const gColor &color) const eRect &area = region.rects[i]; if ((area.height()<=0) || (area.width()<=0)) continue; + if (surface->bpp == 8) { for (int y=area.top(); ydata)+y*surface->stride+area.left(), color.color, area.width()); } else if (surface->bpp == 32) + { + __u32 col; + + if (surface->clut.data && color < surface->clut.colors) + col=(surface->clut.data[color].a<<24)|(surface->clut.data[color].r<<16)|(surface->clut.data[color].g<<8)|(surface->clut.data[color].b); + else + col=0x10101*color; + + col^=0xFF000000; + + if (surface->data_phys && gAccel::getInstance()) + if (!gAccel::getInstance()->fill(surface, area, col)) + continue; + for (int y=area.top(); ydata)+y*surface->stride+area.left()*surface->bypp); int x=area.width(); - __u32 col; - - if (surface->clut.data && color < surface->clut.colors) - col=(surface->clut.data[color].a<<24)|(surface->clut.data[color].r<<16)|(surface->clut.data[color].g<<8)|(surface->clut.data[color].b); - else - col=0x10101*color; - col^=0xFF000000; while (x--) *dst++=col; } - else + } else eWarning("couldn't fill %d bpp", surface->bpp); } } @@ -148,6 +188,11 @@ void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag eRect srcarea=area; srcarea.moveBy(-pos.x(), -pos.y()); + if ((surface->data_phys && src.surface->data_phys) && (gAccel::getInstance())) + if (!gAccel::getInstance()->blit(surface, src.surface, area.topLeft(), srcarea, flag)) + continue; + flag &= ~ blitAlphaBlend; + if ((surface->bpp == 8) && (src.surface->bpp==8)) { __u8 *srcptr=(__u8*)src.surface->data; @@ -178,6 +223,64 @@ void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag srcptr+=src.surface->stride; dstptr+=surface->stride; } + } else if ((surface->bpp == 32) && (src.surface->bpp==32)) + { + __u32 *srcptr=(__u32*)src.surface->data; + __u32 *dstptr=(__u32*)surface->data; + + srcptr+=srcarea.left()+srcarea.top()*src.surface->stride/4; + dstptr+=area.left()+area.top()*surface->stride/4; + for (int y=0; ybypp); + srcptr+=src.surface->stride/4; + dstptr+=surface->stride/4; + } } else if ((surface->bpp == 32) && (src.surface->bpp==8)) { __u8 *srcptr=(__u8*)src.surface->data; @@ -231,10 +334,9 @@ void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag void gPixmap::mergePalette(const gPixmap &target) { - eDebug("merge palette! %p %p", surface, target.surface); if ((!surface->clut.colors) || (!target.surface->clut.colors)) return; -#if 0 + gColor *lookup=new gColor[surface->clut.colors]; for (int i=0; iclut.colors; i++) @@ -255,7 +357,6 @@ void gPixmap::mergePalette(const gPixmap &target) } delete [] lookup; -#endif } static inline int sgn(int a) @@ -368,6 +469,10 @@ fail: gColor gPalette::findColor(const gRGB &rgb) const { + /* grayscale? */ + if (!data) + return (rgb.r + rgb.g + rgb.b) / 3; + int difference=1<<30, best_choice=0; for (int t=0; t