diff options
author | Philipp Zabel <p.zabel@pengutronix.de> | 2016-06-02 11:49:37 +0200 |
---|---|---|
committer | Philipp Zabel <p.zabel@pengutronix.de> | 2016-06-13 16:29:16 +0200 |
commit | 902444bf2076921417851d9d4a0d1c6c6bb37c14 (patch) | |
tree | fd342f2449adaf2909eb7ecd4deaebc099b38704 | |
parent | 13831afd261b7d91b2241634d59004d62999c2ce (diff) | |
download | kmsfbwrap-902444bf2076921417851d9d4a0d1c6c6bb37c14.tar.gz kmsfbwrap-902444bf2076921417851d9d4a0d1c6c6bb37c14.tar.xz |
move framebuffer pattern fill into separate function
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
-rw-r--r-- | src/kmsfb-manage.c | 202 |
1 files changed, 103 insertions, 99 deletions
diff --git a/src/kmsfb-manage.c b/src/kmsfb-manage.c index 4f7f917..c3d0a03 100644 --- a/src/kmsfb-manage.c +++ b/src/kmsfb-manage.c @@ -1299,6 +1299,107 @@ static int fb_splash(struct kms_fb *fb, char *filename) return 0; } +static void fb_fill(struct kms_fb *fb) +{ + int x, y; + + if (fb->format == DRM_FORMAT_XRGB8888 || + fb->format == DRM_FORMAT_ARGB8888 || + fb->format == DRM_FORMAT_XBGR8888 || + fb->format == DRM_FORMAT_ABGR8888) { + uint32_t *pix; + + for (y = 0; y < fb->yres; y++) { + for (x = 0; x < fb->xres; x++) { + pix = fb->fb + x * 4 + y * fb->pitch; + *pix = ((x & 0xff) << 8) | + (0xff - (y & 0xff)) | + (((0xff - x) & 0xff) << 16) | + ((((x ^ y) & 1) ? 0x00 : 0xff) << 24); + } + } + } else if (fb->format == DRM_FORMAT_RGBX8888 || + fb->format == DRM_FORMAT_RGBA8888 || + fb->format == DRM_FORMAT_BGRX8888 || + fb->format == DRM_FORMAT_BGRA8888 || + fb->format == DRM_FORMAT_RGBX8888_A8 || + fb->format == DRM_FORMAT_BGRX8888_A8) { + uint32_t *pix; + uint8_t *alpha; + + for (y = 0; y < fb->yres; y++) { + for (x = 0; x < fb->xres; x++) { + pix = fb->fb + x * 4 + y * fb->pitch; + *pix = ((x & 0xff) << 16) | + ((0xff - (y & 0xff)) << 8) | + (((0xff - x) & 0xff) << 24) | + (((x ^ y) & 1) ? 0x00 : 0xff); + if (fb->format == DRM_FORMAT_RGBX8888 || + fb->format == DRM_FORMAT_RGBA8888 || + fb->format == DRM_FORMAT_BGRX8888 || + fb->format == DRM_FORMAT_BGRA8888) + continue; + alpha = fb->fb + fb->yres * fb->pitch + + x + y * ((fb->pitch + 3) / 4); + *alpha = ((x ^ y) & 1) ? 0x00 : 0xff; + } + } + } else if (fb->format == DRM_FORMAT_BGR888 || + fb->format == DRM_FORMAT_RGB888 || + fb->format == DRM_FORMAT_BGR888_A8 || + fb->format == DRM_FORMAT_RGB888_A8) { + uint8_t *pix, *alpha; + + for (y = 0; y < fb->yres; y++) { + for (x = 0; x < fb->xres; x++) { + pix = fb->fb + x * 3 + y * fb->pitch; + pix[0] = (0xff - x) & 0xff; + pix[1] = x & 0xff; + pix[2] = 0xff - (y & 0xff); + if (fb->format == DRM_FORMAT_BGR888 || + fb->format == DRM_FORMAT_RGB888) + continue; + alpha = fb->fb + fb->yres * fb->pitch + + x + y * ((fb->pitch + 2) / 3); + *alpha = ((x ^ y) & 1) ? 0x00 : 0xff; + } + } + } else if (fb->format == DRM_FORMAT_RGB565 || + fb->format == DRM_FORMAT_BGR565 || + fb->format == DRM_FORMAT_RGB565_A8 || + fb->format == DRM_FORMAT_BGR565_A8) { + uint16_t *pix; + uint8_t *alpha; + + for (y = 0; y < fb->yres; y++) { + for (x = 0; x < fb->xres; x++) { + pix = fb->fb + x * 2 + y * fb->pitch; + *pix = ((x & 0x3f) << 5) | + (0x1f - (y & 0x1f)) | + (((0x1f - x) & 0x1f) << 11); + if (fb->format == DRM_FORMAT_RGB565 || + fb->format == DRM_FORMAT_BGR565) + continue; + alpha = fb->fb + fb->yres * fb->pitch + + x + y * ((fb->pitch + 1) / 2); + *alpha = ((x ^ y) & 1) ? 0x00 : 0xff; + } + } + } else if (fb->format == DRM_FORMAT_ARGB1555) { + uint16_t *pix; + + for (y = 0; y < fb->yres; y++) { + for (x = 0; x < fb->xres; x++) { + pix = fb->fb + x * 2 + y * fb->pitch; + *pix = ((x & 0x1f) << 5) | + (0x1f - (y & 0x1f)) | + (((0x1f - x) & 0x1f) << 10) | + ((((x ^ y) & 1) ? 0 : 1) << 15); + } + } + } +} + static int fb_create(struct drm_resource *res, int fd, const char *cmd) { int ret; @@ -1389,105 +1490,8 @@ static int fb_create(struct drm_resource *res, int fd, const char *cmd) if (strlen(kd.file) > 0) fb_splash(fb, kd.file); - if (kd.fill) { - int x, y; - - if (kd.format == DRM_FORMAT_XRGB8888 || - kd.format == DRM_FORMAT_ARGB8888 || - kd.format == DRM_FORMAT_XBGR8888 || - kd.format == DRM_FORMAT_ABGR8888) { - uint32_t *pix; - - for (y = 0; y < fb->yres; y++) { - for (x = 0; x < fb->xres; x++) { - pix = fb->fb + x * 4 + y * fb->pitch; - *pix = ((x & 0xff) << 8) | - (0xff - (y & 0xff)) | - (((0xff - x) & 0xff) << 16) | - ((((x ^ y) & 1) ? 0x00 : 0xff) << 24); - } - } - } else if (kd.format == DRM_FORMAT_RGBX8888 || - kd.format == DRM_FORMAT_RGBA8888 || - kd.format == DRM_FORMAT_BGRX8888 || - kd.format == DRM_FORMAT_BGRA8888 || - kd.format == DRM_FORMAT_RGBX8888_A8 || - kd.format == DRM_FORMAT_BGRX8888_A8) { - uint32_t *pix; - uint8_t *alpha; - - for (y = 0; y < fb->yres; y++) { - for (x = 0; x < fb->xres; x++) { - pix = fb->fb + x * 4 + y * fb->pitch; - *pix = ((x & 0xff) << 16) | - ((0xff - (y & 0xff)) << 8) | - (((0xff - x) & 0xff) << 24) | - (((x ^ y) & 1) ? 0x00 : 0xff); - if (kd.format == DRM_FORMAT_RGBX8888 || - kd.format == DRM_FORMAT_RGBA8888 || - kd.format == DRM_FORMAT_BGRX8888 || - kd.format == DRM_FORMAT_BGRA8888) - continue; - alpha = fb->fb + fb->yres * fb->pitch + - x + y * ((fb->pitch + 3) / 4); - *alpha = ((x ^ y) & 1) ? 0x00 : 0xff; - } - } - } else if (kd.format == DRM_FORMAT_BGR888 || - kd.format == DRM_FORMAT_RGB888 || - kd.format == DRM_FORMAT_BGR888_A8 || - kd.format == DRM_FORMAT_RGB888_A8) { - uint8_t *pix, *alpha; - - for (y = 0; y < fb->yres; y++) { - for (x = 0; x < fb->xres; x++) { - pix = fb->fb + x * 3 + y * fb->pitch; - pix[0] = (0xff - x) & 0xff; - pix[1] = x & 0xff; - pix[2] = 0xff - (y & 0xff); - if (kd.format == DRM_FORMAT_BGR888 || - kd.format == DRM_FORMAT_RGB888) - continue; - alpha = fb->fb + fb->yres * fb->pitch + - x + y * ((fb->pitch + 2) / 3); - *alpha = ((x ^ y) & 1) ? 0x00 : 0xff; - } - } - } else if (kd.format == DRM_FORMAT_RGB565 || - kd.format == DRM_FORMAT_BGR565 || - kd.format == DRM_FORMAT_RGB565_A8 || - kd.format == DRM_FORMAT_BGR565_A8) { - uint16_t *pix; - uint8_t *alpha; - - for (y = 0; y < fb->yres; y++) { - for (x = 0; x < fb->xres; x++) { - pix = fb->fb + x * 2 + y * fb->pitch; - *pix = ((x & 0x3f) << 5) | - (0x1f - (y & 0x1f)) | - (((0x1f - x) & 0x1f) << 11); - if (kd.format == DRM_FORMAT_RGB565 || - kd.format == DRM_FORMAT_BGR565) - continue; - alpha = fb->fb + fb->yres * fb->pitch + - x + y * ((fb->pitch + 1) / 2); - *alpha = ((x ^ y) & 1) ? 0x00 : 0xff; - } - } - } else if (kd.format == DRM_FORMAT_ARGB1555) { - uint16_t *pix; - - for (y = 0; y < fb->yres; y++) { - for (x = 0; x < fb->xres; x++) { - pix = fb->fb + x * 2 + y * fb->pitch; - *pix = ((x & 0x1f) << 5) | - (0x1f - (y & 0x1f)) | - (((0x1f - x) & 0x1f) << 10) | - ((((x ^ y) & 1) ? 0 : 1) << 15); - } - } - } - } + if (kd.fill) + fb_fill(fb); globals.kms_fbs[globals.num_kms_fbs] = fb; globals.num_kms_fbs++; |