gralloc960: make fbdev fd a shallow copy am: 5f82a37fdb am: f0446da0ad am: 83d5d60df8
am: 29083b86e5

Change-Id: I9878fe0b6858b9cff241eca309ad341f5c768fd4
diff --git a/gralloc960/alloc_device.cpp b/gralloc960/alloc_device.cpp
index 8614ae5..9a3ff8c 100644
--- a/gralloc960/alloc_device.cpp
+++ b/gralloc960/alloc_device.cpp
@@ -117,7 +117,7 @@
 
 	// The entire framebuffer memory is already mapped, now create a buffer object for parts of this memory
 	private_handle_t* hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_FRAMEBUFFER, usage, size,
-			(void*)framebufferVaddr, 0, dup(m->framebuffer->fd),
+			(void*)framebufferVaddr, 0, m->framebuffer->shallow_fbdev_fd,
 			(framebufferVaddr - (uintptr_t)m->framebuffer->base));
 
 	/*
@@ -1234,7 +1234,6 @@
 		const size_t bufferSize = m->finfo.line_length * m->info.yres;
 		int index = ((uintptr_t)hnd->base - (uintptr_t)m->framebuffer->base) / bufferSize;
 		m->bufferMask &= ~(1 << index);
-		close(hnd->fd);
 	}
 
 	gralloc_buffer_attr_free( (private_handle_t *) hnd );
diff --git a/gralloc960/alloc_ion.cpp b/gralloc960/alloc_ion.cpp
index 2f9efc0..954c538 100644
--- a/gralloc960/alloc_ion.cpp
+++ b/gralloc960/alloc_ion.cpp
@@ -307,7 +307,7 @@
 {
 	struct fb_dmabuf_export fb_dma_buf;
 	int res;
-	res = ioctl( m->framebuffer->fd, FBIOGET_DMABUF, &fb_dma_buf );
+	res = ioctl( m->framebuffer->shallow_fbdev_fd, FBIOGET_DMABUF, &fb_dma_buf );
 	if(res == 0)
 	{
 		hnd->share_fd = fb_dma_buf.fd;
diff --git a/gralloc960/framebuffer_device.cpp b/gralloc960/framebuffer_device.cpp
index 873b5f4..fa60eb5 100644
--- a/gralloc960/framebuffer_device.cpp
+++ b/gralloc960/framebuffer_device.cpp
@@ -92,24 +92,25 @@
 		m->info.activate = FB_ACTIVATE_VBL;
 		m->info.yoffset = offset / m->finfo.line_length;
 
+                int fbdev_fd = m->framebuffer->shallow_fbdev_fd;
 #ifdef STANDARD_LINUX_SCREEN
-		if (ioctl(m->framebuffer->fd, FBIOPAN_DISPLAY, &m->info) == -1) 
+		if (ioctl(fbdev_fd, FBIOPAN_DISPLAY, &m->info) == -1) 
 		{
-			AERR( "FBIOPAN_DISPLAY failed for fd: %d", m->framebuffer->fd );
+			AERR( "FBIOPAN_DISPLAY failed for fd: %d", fbdev_fd );
 			m->base.unlock(&m->base, buffer); 
 			return -errno;
 		}
 #else /*Standard Android way*/
-		if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) 
+		if (ioctl(fbdev_fd, FBIOPUT_VSCREENINFO, &m->info) == -1) 
 		{
-			AERR( "FBIOPUT_VSCREENINFO failed for fd: %d", m->framebuffer->fd );
+			AERR( "FBIOPUT_VSCREENINFO failed for fd: %d", fbdev_fd );
 			m->base.unlock(&m->base, buffer); 
 			return -errno;
 		}
 #endif
 		if ( 0 != gralloc_wait_for_vsync(dev) )
 		{
-			AERR( "Gralloc wait for vsync failed for fd: %d", m->framebuffer->fd );
+			AERR( "Gralloc wait for vsync failed for fd: %d", fbdev_fd );
 			m->base.unlock(&m->base, buffer); 
 			return -errno;
 		}
@@ -365,7 +366,7 @@
 
 	// Create a "fake" buffer object for the entire frame buffer memory, and store it in the module
 	module->framebuffer = new private_handle_t(private_handle_t::PRIV_FLAGS_FRAMEBUFFER, GRALLOC_USAGE_HW_FB, fbSize, vaddr,
-	                                           0, dup(fd), 0);
+	                                           0, fd, 0);
 
 	module->numBuffers = info.yres_virtual / info.yres;
 	module->bufferMask = 0;
diff --git a/gralloc960/gralloc_priv.h b/gralloc960/gralloc_priv.h
index a945354..51089dd 100644
--- a/gralloc960/gralloc_priv.h
+++ b/gralloc960/gralloc_priv.h
@@ -194,7 +194,7 @@
 	mali_gralloc_yuv_info yuv_info;
 
 	// Following members is for framebuffer only
-	int   fd;
+	int   shallow_fbdev_fd; // shallow copy, not dup'ed
 	union {
 		off_t    offset;
 		uint64_t padding4;
@@ -235,7 +235,7 @@
 		pid(getpid()),
 		attr_base(MAP_FAILED),
 		yuv_info(MALI_YUV_NO_INFO),
-		fd(fb_file),
+		shallow_fbdev_fd(fb_file),
 		offset(fb_offset)
 	{
 		version = sizeof(native_handle);
diff --git a/gralloc960/gralloc_vsync_default.cpp b/gralloc960/gralloc_vsync_default.cpp
index 40f6699..3ce7f0e 100644
--- a/gralloc960/gralloc_vsync_default.cpp
+++ b/gralloc960/gralloc_vsync_default.cpp
@@ -49,7 +49,7 @@
 	{
 		int crtc = 0;
 		gralloc_mali_vsync_report(MALI_VSYNC_EVENT_BEGIN_WAIT);
-		if(ioctl(m->framebuffer->fd, FBIO_WAITFORVSYNC, &crtc) < 0) 
+		if(ioctl(m->framebuffer->shallow_fbdev_fd, FBIO_WAITFORVSYNC, &crtc) < 0) 
 		{
 			gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT);
 			return -errno;