Skip to contentSkip to conversation

fbdev: add fillrect and copyarea ioctls

PATCH In review Ali Gholami Rudi 6 participants 13 messages Jul 13, 2009 – Jul 14, 2009 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

cover fbdev: add fillrect and copyarea ioctls

Hi,

Is there any reason for not adding these ioctls to fbdev? I searched the net and couldn't any. Anyway, these patches simply implement those ioctls.

Ali Gholami Rudi (2):
fbdev: add FBIOFILLRECT ioctl
fbdev: add FBIOCOPYAREA ioctl

 drivers/video/fbmem.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fb.h    |    2 +
 2 files changed, 52 insertions(+), 0 deletions(-)
#1 lore raw

PATCH 1/2 fbdev: add FBIOFILLRECT ioctl

---
 drivers/video/fbmem.c |   25 +++++++++++++++++++++++++
 include/linux/fb.h    |    1 +
 2 files changed, 26 insertions(+), 0 deletions(-)
drivers/video/fbmem.c +25 -0
index a85c818..a90cd0f 100644
@@ -1016,6 +1016,25 @@ fb_blank(struct fb_info *info, int blank)
  	return ret;
 }
 
+static int fb_fillrect_user(struct fb_info *info,
+			    struct fb_fillrect *fill)
+{
+	int ret = 0;
+	if (fill->rop != ROP_COPY && fill->rop != ROP_XOR)
+		return -EINVAL;
+	if (!lock_fb_info(info))
+		return -ENODEV;
+	if (fill->dx + fill->width > info->var.xres ||
+	    fill->dy + fill->height > info->var.yres) {
+		ret = -EINVAL;
+		goto out;
+	}
+	info->fbops->fb_fillrect(info, fill);
+out:
+	unlock_fb_info(info);
+	return ret;
+}
+
 static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 			unsigned long arg)
 {
@@ -1026,6 +1045,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 	struct fb_cmap cmap_from;
 	struct fb_cmap_user cmap;
 	struct fb_event event;
+	struct fb_fillrect fill;
 	void __user *argp = (void __user *)arg;
 	long ret = 0;
 
@@ -1133,6 +1153,11 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 		release_console_sem();
 		unlock_fb_info(info);
 		break;
+	case FBIOFILLRECT:
+		if (copy_from_user(&fill, argp, sizeof(fill)))
+			return -EFAULT;
+		ret = fb_fillrect_user(info, &fill);
+		break;
 	default:
 		if (!lock_fb_info(info))
 			return -ENODEV;
include/linux/fb.h +1 -0
index f847df9..40cc99a 100644
@@ -37,6 +37,7 @@ struct dentry;
 #define FBIOGET_HWCINFO         0x4616
 #define FBIOPUT_MODEINFO        0x4617
 #define FBIOGET_DISPINFO        0x4618
+#define FBIOFILLRECT		0x4619
 
 
 #define FB_TYPE_PACKED_PIXELS		0	/* Packed Pixels	*/
#2 lore raw

PATCH 2/2 fbdev: add FBIOCOPYAREA ioctl

In reply to Ali Gholami Rudi
---
 drivers/video/fbmem.c |   25 +++++++++++++++++++++++++
 include/linux/fb.h    |    1 +
 2 files changed, 26 insertions(+), 0 deletions(-)
drivers/video/fbmem.c +25 -0
index a90cd0f..518119a 100644
@@ -1035,6 +1035,25 @@ out:
 	return ret;
 }
 
+static int fb_copyarea_user(struct fb_info *info,
+			    struct fb_copyarea *copy)
+{
+	int ret = 0;
+	if (!lock_fb_info(info))
+		return -ENODEV;
+	if (copy->dx + copy->width > info->var.xres ||
+	    copy->sx + copy->width > info->var.xres ||
+	    copy->dy + copy->height > info->var.yres ||
+	    copy->sy + copy->height > info->var.yres) {
+		ret = -EINVAL;
+		goto out;
+	}
+	info->fbops->fb_copyarea(info, copy);
+out:
+	unlock_fb_info(info);
+	return ret;
+}
+
 static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 			unsigned long arg)
 {
@@ -1046,6 +1065,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 	struct fb_cmap_user cmap;
 	struct fb_event event;
 	struct fb_fillrect fill;
+	struct fb_copyarea copy;
 	void __user *argp = (void __user *)arg;
 	long ret = 0;
 
@@ -1158,6 +1178,11 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 			return -EFAULT;
 		ret = fb_fillrect_user(info, &fill);
 		break;
+	case FBIOCOPYAREA:
+		if (copy_from_user(&copy, argp, sizeof(copy)))
+			return -EFAULT;
+		ret = fb_copyarea_user(info, &copy);
+		break;
 	default:
 		if (!lock_fb_info(info))
 			return -ENODEV;
include/linux/fb.h +1 -0
index 40cc99a..f1cf8df 100644
@@ -38,6 +38,7 @@ struct dentry;
 #define FBIOPUT_MODEINFO        0x4617
 #define FBIOGET_DISPINFO        0x4618
 #define FBIOFILLRECT		0x4619
+#define FBIOCOPYAREA		0x461A
 
 
 #define FB_TYPE_PACKED_PIXELS		0	/* Packed Pixels	*/
#3 lore raw
In reply to Ali Gholami Rudi
Quoted 6 lines · On Mon, 13 Jul 2009 19:47:09 +0430 Ali Gholami Rudi <[email protected]> wrote:

Hi,

Is there any reason for not adding these ioctls to fbdev? I searched the net and couldn't any. Anyway, these patches simply implement those ioctls.

can we turn this around, is there a reason to add them? or in other words, how / where would these be used ?

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#4 lore raw
Quoted 9 lines · Arjan van de Ven
Quoted 4 lines · On Mon, 13 Jul 2009 19:47:09 +0430 Ali Gholami Rudi <[email protected]> wrote:

Is there any reason for not adding these ioctls to fbdev? I searched the net and couldn't any. Anyway, these patches simply implement those ioctls.

can we turn this around, is there a reason to add them? or in other words, how / where would these be used ?

User-space programs that use framebuffer directly can use them. I was writing a simple framebuffer virtual terminal (using libfreetype for fonts; like fbterm); scrolling and painting boxes would be faster if there was someway of using hardware accelerated operations. I think other similar programs can benefit, too.

Ali

#5 lore raw
Quoted 8 lines · Ali Gholami Rudi
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · On Mon, 13 Jul 2009 19:47:09 +0430 Ali Gholami Rudi <[email protected]> wrote:

Is there any reason for not adding these ioctls to fbdev?  I searched the net and couldn't any.  Anyway, these patches simply implement those ioctls.

Quoted 8 lines
Quoted 2 lines

can we turn this around, is there a reason to add them? or in other words, how / where would these be used ?

User-space programs that use framebuffer directly can use them.  I was writing a simple framebuffer virtual terminal (using libfreetype for fonts; like fbterm); scrolling and painting boxes would be faster if there was someway of using hardware accelerated operations.  I think other similar programs can benefit, too.

The general opinion is we should keep acceleration in userspace if at all possible.

Not all hw can implement these usefully in the kernel, directfb already does some
things for this.

Dave.

#6 lore raw
Quoted 5 lines · Dave Airlie
Quoted 4 lines · Ali Gholami Rudi
Quoted 2 lines · Arjan van de Ven

can we turn this around, is there a reason to add them? or in other words, how / where would these be used ?

Quoted 8 lines
Quoted 5 lines

User-space programs that use framebuffer directly can use them.  I was writing a simple framebuffer virtual terminal (using libfreetype for fonts; like fbterm); scrolling and painting boxes would be faster if there was someway of using hardware accelerated operations.  I think other similar programs can benefit, too.

The general opinion is we should keep acceleration in userspace if at all possible.

I see. The line between user- and kernel-space for graphic applications is very blurred to me :-)

Quoted 1 line

Not all hw can implement these usefully in the kernel, directfb

AFAICT, many major ones like intelfb, radeonfb and nv implement them and those that can't, use a software implementation. You mean they are unreliable or that there is little performance improvement because of the way those operations are implemented in the kernel?

Quoted 2 lines

already does some
things for this.

Sometime ago I did try running directfb on a radeon r300 and it failed. I didn't try hard to see what's wrong but I got the impression that userspace apps are not good at using the hardware directly.

Ali

#7 lore raw
Quoted 18 lines · Ali Gholami Rudi
Quoted 5 lines · Dave Airlie
Quoted 4 lines · Ali Gholami Rudi
Quoted 2 lines · Arjan van de Ven

can we turn this around, is there a reason to add them? or in other words, how / where would these be used ?

Quoted 8 lines
Quoted 5 lines

User-space programs that use framebuffer directly can use them.  I was writing a simple framebuffer virtual terminal (using libfreetype for fonts; like fbterm); scrolling and painting boxes would be faster if there was someway of using hardware accelerated operations.  I think other similar programs can benefit, too.

The general opinion is we should keep acceleration in userspace if at all possible.

I see.  The line between user- and kernel-space for graphic applications is very blurred to me :-)

Quoted 6 lines
Quoted 1 line

Not all hw can implement these usefully in the kernel, directfb

AFAICT, many major ones like intelfb, radeonfb and nv implement them and those that can't, use a software implementation.  You mean they are unreliable or that there is little performance improvement because of the way those operations are implemented in the kernel?

Generally newer consumer HW can't implement a simple blit without using the 3D engine which requires a large amount of state to be sent to the device. Keeping the state encoding and stuff out of the kernel and in userspace is generally seen as the right thing to do.

Quoted 6 lines
Quoted 2 lines

already does some
things for this.

Sometime ago I did try running directfb on a radeon r300 and it failed. I didn't try hard to see what's wrong but I got the impression that userspace apps are not good at using the hardware directly.

directfb has hw accel for different cards, really porting the code out of the kernel for the cards you are interested in would probably benefit more.

Dave.

#8 lore raw
In reply to Ali Gholami Rudi
Quoted 8 lines · Ali Gholami Rudi
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · On Mon, 13 Jul 2009 19:47:09 +0430 Ali Gholami Rudi <[email protected]> wrote:

Is there any reason for not adding these ioctls to fbdev? I searched the net and couldn't any. Anyway, these patches simply implement those ioctls.

Quoted 9 lines
Quoted 2 lines

can we turn this around, is there a reason to add them? or in other words, how / where would these be used ?

User-space programs that use framebuffer directly can use them. I was writing a simple framebuffer virtual terminal (using libfreetype for fonts; like fbterm); scrolling and painting boxes would be faster if there was someway of using hardware accelerated operations. I think other similar programs can benefit, too.

hope to see them added too (plus the WAITFORVSYNC ioctl).

The argument seems to be that we're waiting for DRM which will bring full 3D acceleration to userspace, but imho, besides games you can have a fully functional gui with the quality of winXP using just 2D acceleration. (also xvideo is interesting)

DirectFB just duplicates some of the kernel code, but it is always one step behind and not as well tested. Since this patch exposes existing functionality without adding any new untested code, i don't see a reason why it shouldn't be added.

There are serious use cases of a system that uses just kernel+uclibc+ a full gui just on the framebuffer in a less-than 10MB tarball.

Stelios

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge

#9 lore raw
In reply to Ali Gholami Rudi
Quoted 5 lines · Ali Gholami Rudi

Hi,

Is there any reason for not adding these ioctls to fbdev? I searched the net and couldn't any. Anyway, these patches simply implement those ioctls.

Have you also added the needed 32 vs. 64 bit handlers for these ioctls?

thanks,

greg k-h

#10 lore raw
Quoted 9 lines · Greg KH
Quoted 5 lines · Ali Gholami Rudi

Hi,

Is there any reason for not adding these ioctls to fbdev? I searched the net and couldn't any. Anyway, these patches simply implement those ioctls.

Have you also added the needed 32 vs. 64 bit handlers for these ioctls?

They are not there, but could be trivially added with

drivers/video/fbmem.c +2 -0
index f8a09bf..ce107c4 100644
@@ -1285,6 +1285,8 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
 	case FBIOPAN_DISPLAY:
 	case FBIOGET_CON2FBMAP:
 	case FBIOPUT_CON2FBMAP:
+	case FBIOCOPYAREA:
+	case FBIOFILLRECT:
 		arg = (unsigned long) compat_ptr(arg);
 	case FBIOBLANK:
 		ret = do_fb_ioctl(info, cmd, arg);

Unfortunately, it would not be as easy to add an FBIOIMAGE, which sounds equally useful.

	Arnd <><
#11 lore raw
Quoted 16 lines · Arnd Bergmann
Quoted 7 lines · Greg KH
Quoted 3 lines · Ali Gholami Rudi

Is there any reason for not adding these ioctls to fbdev? I searched the net and couldn't any. Anyway, these patches simply implement those ioctls.

Have you also added the needed 32 vs. 64 bit handlers for these ioctls?

They are not there, but could be trivially added with

drivers/video/fbmem.c +0 -0
index f8a09bf..ce107c4 100644

drivers/video/fbmem.c static long fb_compat_ioctl(struct file *file, unsigned int cmd, · line 1292

Quoted 8 lines
drivers/video/fbmem.c +2 -0
@@ -1285,6 +1285,8 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
 	case FBIOPAN_DISPLAY:
 	case FBIOGET_CON2FBMAP:
 	case FBIOPUT_CON2FBMAP:
+	case FBIOCOPYAREA:
+	case FBIOFILLRECT:
 		arg = (unsigned long) compat_ptr(arg);
 	case FBIOBLANK:
 		ret = do_fb_ioctl(info, cmd, arg);

Thanks, I'll update the patches.

Ali

#12 lore raw
In reply to Greg KH
Quoted 6 lines · Greg KH
Quoted 3 lines · Ali Gholami Rudi

Is there any reason for not adding these ioctls to fbdev? I searched the net and couldn't any. Anyway, these patches simply implement those ioctls.

Have you also added the needed 32 vs. 64 bit handlers for these ioctls?

I guess Arnd's patch will do.

By the way, it should check for overflows, too? I mean should I change this:

Review

Quoted 4 lines
(quoted diff) +4 -0
+       if (copy->dx + copy->width > info->var.xres ||
+           copy->sx + copy->width > info->var.xres ||
+           copy->dy + copy->height > info->var.yres ||
+           copy->sy + copy->height > info->var.yres) {
#define ISSUMLESSTHAN(a, b, s)	(((a) <= (s)) && ((b) <= (s)) && \
				 ((a) + (b) <= (s)))

if (!ISSUMLESSTHAN(copy->dx, copy->width, info->var.xres) || ...

Ali