<div dir="ltr">From e30486e0288e7be526fc358a5318b344522e407b Mon Sep 17 00:00:00 2001<br>From: mchalain <<a href="mailto:marc.chalain@gmail.com">marc.chalain@gmail.com</a>><br>Date: Fri, 7 Jun 2013 17:12:31 +0200<br>
Subject: [PATCH] [fbdev_backend]: support of DIRECTCOLOR Frame buffer<br><br>---<br> src/compositor-fbdev.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---<br> 1 file changed, 46 insertions(+), 3 deletions(-)<br><br>
diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c<br>index 9c3d17e..d6d911a 100644<br>--- a/src/compositor-fbdev.c<br>+++ b/src/compositor-fbdev.c<br>@@ -203,9 +203,42 @@ finish_frame_handler(void *data)<br> return 1;<br>
}<br> <br>+static int<br>+build_cmap(struct fb_var_screeninfo *vinfo,<br>+ struct fb_cmap *cmap)<br>+{<br>+ uint16_t *colors;<br>+ int i;<br>+ int rcols = 1 << vinfo->red.length;<br>
+ int gcols = 1 << vinfo->green.length;<br>+ int bcols = 1 << vinfo->blue.length;<br>+<br>+ /* Make our palette the length of the deepest color */<br>+ int cols = (rcols > gcols ? rcols : gcols);<br>
+ cols = (cols > bcols ? cols : bcols);<br>+<br>+ colors = malloc(sizeof(uint16_t) * cols);<br>+ if (!colors) return -1;<br>+<br>+ for (i = 0; i < rcols; i++)<br>+ colors[i] = (UINT16_MAX / (rcols - 1)) * i;<br>
+<br>+ cmap->start = 0;<br>+ cmap->len = cols;<br>+ cmap->red = colors;<br>+ cmap->blue = colors;<br>+ cmap->green = colors;<br>+ if (vinfo->transp.length)<br>+ cmap->transp = colors;<br>
+ else<br>+ cmap->transp = NULL;<br>+ return 0;<br>+}<br>+<br> static pixman_format_code_t<br> calculate_pixman_format(struct fb_var_screeninfo *vinfo,<br>- struct fb_fix_screeninfo *finfo)<br>
+ struct fb_fix_screeninfo *finfo,<br>+ struct fb_cmap *cmap)<br> {<br> /* Calculate the pixman format supported by the frame buffer from the<br> * buffer's metadata. Return 0 if no known pixman format is supported<br>
@@ -241,7 +274,10 @@ calculate_pixman_format(struct fb_var_screeninfo *vinfo,<br> if (finfo->type != FB_TYPE_PACKED_PIXELS)<br> return 0;<br> <br>- /* We only handle true-colour frame buffers at the moment. */<br>
+ if (finfo->visual == FB_VISUAL_DIRECTCOLOR)<br>+ build_cmap(vinfo, cmap);<br>+ else<br>+ /* We only handle true-colour frame buffers at the moment. */<br> if (finfo->visual != FB_VISUAL_TRUECOLOR || vinfo->grayscale != 0)<br>
return 0;<br> <br>@@ -304,6 +340,9 @@ fbdev_query_screen_info(struct fbdev_output *output, int fd,<br> {<br> struct fb_var_screeninfo varinfo;<br> struct fb_fix_screeninfo fixinfo;<br>+ struct fb_cmap cmap;<br>
+<br>+ memset(&cmap, 0, sizeof(cmap));<br> <br> /* Probe the device for screen information. */<br> if (ioctl(fd, FBIOGET_FSCREENINFO, &fixinfo) < 0 ||<br>@@ -322,9 +361,13 @@ fbdev_query_screen_info(struct fbdev_output *output, int fd,<br>
info->line_length = fixinfo.line_length;<br> strncpy(info->id, <a href="http://fixinfo.id">fixinfo.id</a>, sizeof(info->id) / sizeof(*info->id));<br> <br>- info->pixel_format = calculate_pixman_format(&varinfo, &fixinfo);<br>
+ info->pixel_format = calculate_pixman_format(&varinfo, &fixinfo, &cmap);<br> info->refresh_rate = calculate_refresh_rate(&varinfo);<br> <br>+ if (cmap.red != NULL) {<br>+ ioctl(fd, FBIOPUTCMAP, &cmap);<br>
+ free(cmap.red);<br>+ }<br> if (info->pixel_format == 0) {<br> weston_log("Frame buffer uses an unsupported format.\n");<br> return -1;<br>-- <br>1.7.9.5<br><br><br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2013/6/7 Pekka Paalanen <span dir="ltr"><<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Fri, 7 Jun 2013 16:03:18 +0200<br>
Marc Chalain <<a href="mailto:marc.chalain@gmail.com">marc.chalain@gmail.com</a>> wrote:<br>
<br>
> > You should execute the ioctl in fbdev_set_screen_info.<br>
> fbdev_set_screen_info is used only when the fb device is reenabled. The<br>
> colors map has to be initialized at the beginning in all cases.<br>
> If we use this function we will call it in all cases and it's not required.<br>
><br>
><br>
> >I don't see the codepath which results in cmap.transp being not set in the<br>
> test for it.<br>
> Yes... I forgot => new patch<br>
><br>
><br>
> >You don't initialize cmap.red so the test for it gives an undefined result.<br>
> Yes... error => new patch<br>
><br>
><br>
> >Don't define macros in the middle of code with a literal that's only used<br>
> once.<br>
> In fact that comes from the cmap.transp which are not always initialized.<br>
> In some cases transparency is useless. But I will repair => new patch<br>
><br>
> New patch<br>
<br>
</div>Also, please use git-format-patch, and send the patches inline, not as<br>
attachments. Furthermore, using git-send-email would guarantee, that the<br>
patches do not get mangled by your email client.<br>
<br>
<br>
Thanks,<br>
pq<br>
</blockquote></div><br></div>