fb_generic: add swidth variable, "stride in fb_pixel_t units"

this should allow to use fb_pixel_t pointer arithmetics more often
instead of byte pointers
This commit is contained in:
Stefan Seyfried
2017-02-15 20:30:52 +01:00
committed by M. Liebmann
parent b7110faaf6
commit 7c7d5f08dd
8 changed files with 12 additions and 9 deletions

View File

@@ -82,7 +82,6 @@ void CFbAccel::paintBoxRel(const int x, const int y, const int dx, const int dy,
void CFbAccel::paintRect(const int x, const int y, const int dx, const int dy, const fb_pixel_t col) void CFbAccel::paintRect(const int x, const int y, const int dx, const int dy, const fb_pixel_t col)
{ {
int line = 0; int line = 0;
int swidth = stride / sizeof(fb_pixel_t);
fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * y); fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * y);
int pos; int pos;
while (line < dy) while (line < dy)

View File

@@ -346,6 +346,7 @@ int CFbAccelCSHD1::setMode(unsigned int, unsigned int, unsigned int)
return -1; return -1;
} }
stride = _fix.line_length; stride = _fix.line_length;
swidth = stride / sizeof(fb_pixel_t);
if (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0) if (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0)
printf("screen unblanking failed\n"); printf("screen unblanking failed\n");
xRes = screeninfo.xres; xRes = screeninfo.xres;
@@ -355,7 +356,7 @@ int CFbAccelCSHD1::setMode(unsigned int, unsigned int, unsigned int)
int needmem = stride * yRes * 2; int needmem = stride * yRes * 2;
if (available >= needmem) if (available >= needmem)
{ {
backbuffer = lfb + stride / sizeof(fb_pixel_t) * yRes; backbuffer = lfb + swidth * yRes;
return 0; return 0;
} }
fprintf(stderr, LOGTAG "not enough FB memory (have %d, need %d)\n", available, needmem); fprintf(stderr, LOGTAG "not enough FB memory (have %d, need %d)\n", available, needmem);

View File

@@ -216,6 +216,7 @@ int CFbAccelCSHD2::setMode(unsigned int, unsigned int, unsigned int)
return -1; return -1;
} }
stride = _fix.line_length; stride = _fix.line_length;
swidth = stride / sizeof(fb_pixel_t);
if (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0) if (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0)
printf("screen unblanking failed\n"); printf("screen unblanking failed\n");
xRes = screeninfo.xres; xRes = screeninfo.xres;
@@ -225,7 +226,7 @@ int CFbAccelCSHD2::setMode(unsigned int, unsigned int, unsigned int)
int needmem = stride * yRes * 2; int needmem = stride * yRes * 2;
if (available >= needmem) if (available >= needmem)
{ {
backbuffer = lfb + stride / sizeof(fb_pixel_t) * yRes; backbuffer = lfb + swidth * yRes;
return 0; return 0;
} }
fprintf(stderr, LOGTAG "not enough FB memory (have %d, need %d)\n", available, needmem); fprintf(stderr, LOGTAG "not enough FB memory (have %d, need %d)\n", available, needmem);

View File

@@ -54,6 +54,7 @@ void CFbAccelGLFB::init(const char *)
} }
screeninfo = glfb->getScreenInfo(); screeninfo = glfb->getScreenInfo();
stride = 4 * screeninfo.xres; stride = 4 * screeninfo.xres;
swidth = screeninfo.xres;
available = glfb->getOSDBuffer()->size(); /* allocated in glfb constructor */ available = glfb->getOSDBuffer()->size(); /* allocated in glfb constructor */
lbb = lfb = reinterpret_cast<fb_pixel_t*>(glfb->getOSDBuffer()->data()); lbb = lfb = reinterpret_cast<fb_pixel_t*>(glfb->getOSDBuffer()->data());
@@ -135,7 +136,7 @@ int CFbAccelGLFB::setMode(unsigned int, unsigned int, unsigned int)
int needmem = stride * yRes * 2; int needmem = stride * yRes * 2;
if (available >= needmem) if (available >= needmem)
{ {
backbuffer = lfb + stride / sizeof(fb_pixel_t) * yRes; backbuffer = lfb + swidth * yRes;
return 0; return 0;
} }
fprintf(stderr, LOGTAG " not enough FB memory (have %d, need %d)\n", available, needmem); fprintf(stderr, LOGTAG " not enough FB memory (have %d, need %d)\n", available, needmem);

View File

@@ -512,6 +512,7 @@ int CFbAccelSTi::setMode(unsigned int, unsigned int, unsigned int)
yRes = screeninfo.yres = screeninfo.yres_virtual = DEFAULT_YRES; yRes = screeninfo.yres = screeninfo.yres_virtual = DEFAULT_YRES;
bpp = screeninfo.bits_per_pixel = DEFAULT_BPP; bpp = screeninfo.bits_per_pixel = DEFAULT_BPP;
stride = screeninfo.xres * screeninfo.bits_per_pixel / 8; stride = screeninfo.xres * screeninfo.bits_per_pixel / 8;
swidth = screeninfo.xres;
return 0; return 0;
} }

View File

@@ -156,6 +156,7 @@ void CFbAccelTD::init(const char *)
lbb = lfb; /* the memory area to draw to... */ lbb = lfb; /* the memory area to draw to... */
available = fix.smem_len; available = fix.smem_len;
stride = fix.line_length; stride = fix.line_length;
swidth = stride / sizeof(fb_pixel_t);
xRes = screeninfo.xres; xRes = screeninfo.xres;
yRes = screeninfo.yres; yRes = screeninfo.yres;
bpp = screeninfo.bits_per_pixel; bpp = screeninfo.bits_per_pixel;
@@ -169,7 +170,7 @@ int CFbAccelTD::setMode(unsigned int, unsigned int, unsigned int)
int needmem = stride * yRes * 2; int needmem = stride * yRes * 2;
if (available >= needmem) if (available >= needmem)
{ {
backbuffer = lfb + stride / sizeof(fb_pixel_t) * yRes; backbuffer = lfb + swidth * yRes;
return 0; return 0;
} }
fprintf(stderr, LOGTAG " not enough FB memory (have %d, need %d)\n", available, needmem); fprintf(stderr, LOGTAG " not enough FB memory (have %d, need %d)\n", available, needmem);

View File

@@ -340,6 +340,7 @@ int CFrameBuffer::setMode(unsigned int /*nxRes*/, unsigned int /*nyRes*/, unsign
} }
stride = _fix.line_length; stride = _fix.line_length;
swidth = stride / sizeof(fb_pixel_t);
printf("FB: %dx%dx%d line length %d. %s accelerator.\n", xRes, yRes, bpp, stride, printf("FB: %dx%dx%d line length %d. %s accelerator.\n", xRes, yRes, bpp, stride,
"Not using graphics" "Not using graphics"
); );
@@ -623,7 +624,6 @@ void CFrameBuffer::paintBoxRel(const int x, const int y, const int dx, const int
line++; line++;
} }
} else { } else {
int swidth = stride / sizeof(fb_pixel_t);
fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * y); fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * y);
int line = 0; int line = 0;
while (line < dy) { while (line < dy) {
@@ -934,7 +934,7 @@ void CFrameBuffer::paintPixel(const int x, const int y, const fb_pixel_t col)
return; return;
fb_pixel_t * pos = getFrameBufferPointer(); fb_pixel_t * pos = getFrameBufferPointer();
pos += (stride / sizeof(fb_pixel_t)) * y; pos += swidth * y;
pos += x; pos += x;
*pos = col; *pos = col;
@@ -1680,7 +1680,6 @@ void CFrameBuffer::blitBox2FB(const fb_pixel_t* boxBuf, uint32_t width, uint32_t
uint32_t xc = (width > xRes) ? (uint32_t)xRes : width; uint32_t xc = (width > xRes) ? (uint32_t)xRes : width;
uint32_t yc = (height > yRes) ? (uint32_t)yRes : height; uint32_t yc = (height > yRes) ? (uint32_t)yRes : height;
uint32_t swidth = stride / sizeof(fb_pixel_t);
fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * yoff); fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * yoff);
fb_pixel_t* data = (fb_pixel_t*)boxBuf; fb_pixel_t* data = (fb_pixel_t*)boxBuf;

View File

@@ -112,7 +112,7 @@ class CFrameBuffer : public sigc::trackable
fb_pixel_t backgroundColor; fb_pixel_t backgroundColor;
std::string backgroundFilename; std::string backgroundFilename;
bool useBackgroundPaint; bool useBackgroundPaint;
unsigned int xRes, yRes, stride, bpp; unsigned int xRes, yRes, stride, swidth, bpp;
t_fb_var_screeninfo screeninfo; t_fb_var_screeninfo screeninfo;
fb_cmap cmap; fb_cmap cmap;
__u16 red[256], green[256], blue[256], trans[256]; __u16 red[256], green[256], blue[256], trans[256];