From a6fc59ad6ca8adb3c5f23460ec2ced21fcb2d03e Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Wed, 15 Feb 2017 20:30:52 +0100 Subject: [PATCH] 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 --- src/driver/fb_accel.cpp | 1 - src/driver/fb_accel_cs_hd1.cpp | 3 ++- src/driver/fb_accel_cs_hd2.cpp | 3 ++- src/driver/fb_accel_glfb.cpp | 3 ++- src/driver/fb_accel_sti.cpp | 1 + src/driver/fb_accel_td.cpp | 3 ++- src/driver/fb_generic.cpp | 5 ++--- src/driver/fb_generic.h | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/driver/fb_accel.cpp b/src/driver/fb_accel.cpp index d8391ab34..ba8e052ce 100644 --- a/src/driver/fb_accel.cpp +++ b/src/driver/fb_accel.cpp @@ -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) { int line = 0; - int swidth = stride / sizeof(fb_pixel_t); fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * y); int pos; while (line < dy) diff --git a/src/driver/fb_accel_cs_hd1.cpp b/src/driver/fb_accel_cs_hd1.cpp index 4b3df3d20..9b20091cc 100644 --- a/src/driver/fb_accel_cs_hd1.cpp +++ b/src/driver/fb_accel_cs_hd1.cpp @@ -335,6 +335,7 @@ int CFbAccelCSHD1::setMode(unsigned int, unsigned int, unsigned int) return -1; } stride = _fix.line_length; + swidth = stride / sizeof(fb_pixel_t); if (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0) printf("screen unblanking failed\n"); xRes = screeninfo.xres; @@ -344,7 +345,7 @@ int CFbAccelCSHD1::setMode(unsigned int, unsigned int, unsigned int) int needmem = stride * yRes * 2; if (available >= needmem) { - backbuffer = lfb + stride / sizeof(fb_pixel_t) * yRes; + backbuffer = lfb + swidth * yRes; return 0; } fprintf(stderr, LOGTAG "not enough FB memory (have %d, need %d)\n", available, needmem); diff --git a/src/driver/fb_accel_cs_hd2.cpp b/src/driver/fb_accel_cs_hd2.cpp index bc2983560..7e24aabf8 100644 --- a/src/driver/fb_accel_cs_hd2.cpp +++ b/src/driver/fb_accel_cs_hd2.cpp @@ -194,6 +194,7 @@ int CFbAccelCSHD2::setMode(unsigned int, unsigned int, unsigned int) return -1; } stride = _fix.line_length; + swidth = stride / sizeof(fb_pixel_t); if (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0) printf("screen unblanking failed\n"); xRes = screeninfo.xres; @@ -203,7 +204,7 @@ int CFbAccelCSHD2::setMode(unsigned int, unsigned int, unsigned int) int needmem = stride * yRes * 2; if (available >= needmem) { - backbuffer = lfb + stride / sizeof(fb_pixel_t) * yRes; + backbuffer = lfb + swidth * yRes; return 0; } fprintf(stderr, LOGTAG "not enough FB memory (have %d, need %d)\n", available, needmem); diff --git a/src/driver/fb_accel_glfb.cpp b/src/driver/fb_accel_glfb.cpp index f6784c48f..cc4054258 100644 --- a/src/driver/fb_accel_glfb.cpp +++ b/src/driver/fb_accel_glfb.cpp @@ -54,6 +54,7 @@ void CFbAccelGLFB::init(const char *) } screeninfo = glfb->getScreenInfo(); stride = 4 * screeninfo.xres; + swidth = screeninfo.xres; available = glfb->getOSDBuffer()->size(); /* allocated in glfb constructor */ lbb = lfb = reinterpret_cast(glfb->getOSDBuffer()->data()); @@ -135,7 +136,7 @@ int CFbAccelGLFB::setMode(unsigned int, unsigned int, unsigned int) int needmem = stride * yRes * 2; if (available >= needmem) { - backbuffer = lfb + stride / sizeof(fb_pixel_t) * yRes; + backbuffer = lfb + swidth * yRes; return 0; } fprintf(stderr, LOGTAG " not enough FB memory (have %d, need %d)\n", available, needmem); diff --git a/src/driver/fb_accel_sti.cpp b/src/driver/fb_accel_sti.cpp index 446fc3828..dfe0ac5c3 100644 --- a/src/driver/fb_accel_sti.cpp +++ b/src/driver/fb_accel_sti.cpp @@ -512,6 +512,7 @@ int CFbAccelSTi::setMode(unsigned int, unsigned int, unsigned int) yRes = screeninfo.yres = screeninfo.yres_virtual = DEFAULT_YRES; bpp = screeninfo.bits_per_pixel = DEFAULT_BPP; stride = screeninfo.xres * screeninfo.bits_per_pixel / 8; + swidth = screeninfo.xres; return 0; } diff --git a/src/driver/fb_accel_td.cpp b/src/driver/fb_accel_td.cpp index 7033ed0bc..7ecc562c2 100644 --- a/src/driver/fb_accel_td.cpp +++ b/src/driver/fb_accel_td.cpp @@ -156,6 +156,7 @@ void CFbAccelTD::init(const char *) lbb = lfb; /* the memory area to draw to... */ available = fix.smem_len; stride = fix.line_length; + swidth = stride / sizeof(fb_pixel_t); xRes = screeninfo.xres; yRes = screeninfo.yres; bpp = screeninfo.bits_per_pixel; @@ -169,7 +170,7 @@ int CFbAccelTD::setMode(unsigned int, unsigned int, unsigned int) int needmem = stride * yRes * 2; if (available >= needmem) { - backbuffer = lfb + stride / sizeof(fb_pixel_t) * yRes; + backbuffer = lfb + swidth * yRes; return 0; } fprintf(stderr, LOGTAG " not enough FB memory (have %d, need %d)\n", available, needmem); diff --git a/src/driver/fb_generic.cpp b/src/driver/fb_generic.cpp index 1160b9c44..1ae1ba24c 100644 --- a/src/driver/fb_generic.cpp +++ b/src/driver/fb_generic.cpp @@ -340,6 +340,7 @@ int CFrameBuffer::setMode(unsigned int /*nxRes*/, unsigned int /*nyRes*/, unsign } 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, "Not using graphics" ); @@ -623,7 +624,6 @@ void CFrameBuffer::paintBoxRel(const int x, const int y, const int dx, const int line++; } } else { - int swidth = stride / sizeof(fb_pixel_t); fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * y); int line = 0; while (line < dy) { @@ -934,7 +934,7 @@ void CFrameBuffer::paintPixel(const int x, const int y, const fb_pixel_t col) return; fb_pixel_t * pos = getFrameBufferPointer(); - pos += (stride / sizeof(fb_pixel_t)) * y; + pos += swidth * y; pos += x; *pos = col; @@ -1624,7 +1624,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 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* data = (fb_pixel_t*)boxBuf; diff --git a/src/driver/fb_generic.h b/src/driver/fb_generic.h index 7112a8226..c1a2d14d2 100644 --- a/src/driver/fb_generic.h +++ b/src/driver/fb_generic.h @@ -112,7 +112,7 @@ class CFrameBuffer : public sigc::trackable fb_pixel_t backgroundColor; std::string backgroundFilename; bool useBackgroundPaint; - unsigned int xRes, yRes, stride, bpp; + unsigned int xRes, yRes, stride, swidth, bpp; t_fb_var_screeninfo screeninfo; fb_cmap cmap; __u16 red[256], green[256], blue[256], trans[256];