release-request-05263112-375a-4b1f-a657-a14bb2a5c5a3-for-git_oc-mr1-release-4185249 snap-temp-L63000000082739046

Change-Id: Ib82365a211e44d2eafae4299e975021efc405186
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..2af9d94 100644
--- a/gralloc960/alloc_ion.cpp
+++ b/gralloc960/alloc_ion.cpp
@@ -248,6 +248,13 @@
 		return -1;
 	}
 
+        // we do not need ion_hnd once we have shared_fd
+        if (0 != ion_free(m->ion_client, ion_hnd))
+        {
+            AWAR("ion_free( %d ) failed", m->ion_client);
+        }
+        ion_hnd = -1;
+
 	if (!(usage & GRALLOC_USAGE_PROTECTED))
 	{
 		cpu_ptr = (unsigned char*)mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, shared_fd, 0 );
@@ -255,7 +262,6 @@
 		if ( MAP_FAILED == cpu_ptr )
 		{
 			AERR( "ion_map( %d ) failed", m->ion_client );
-			if ( 0 != ion_free( m->ion_client, ion_hnd ) ) AERR( "ion_free( %d ) failed", m->ion_client );
 			close( shared_fd );
 			return -1;
 		}
@@ -280,7 +286,6 @@
 	if ( NULL != hnd )
 	{
 		hnd->share_fd = shared_fd;
-		hnd->ion_hnd = ion_hnd;
 		hnd->min_pgsz = min_pgsz;
 		*pHandle = hnd;
 		return 0;
@@ -298,8 +303,6 @@
 		if ( 0 != ret ) AERR( "munmap failed for base:%p size: %zd", cpu_ptr, size );
 	}
 
-	ret = ion_free( m->ion_client, ion_hnd );
-	if ( 0 != ret ) AERR( "ion_free( %d ) failed", m->ion_client );
 	return -1;
 }
 
@@ -307,7 +310,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;
@@ -322,6 +325,7 @@
 
 void alloc_backend_alloc_free(private_handle_t const* hnd, private_module_t* m)
 {
+	(void) m;
 	if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)
 	{
 		return;
@@ -334,7 +338,6 @@
 			if ( 0 != munmap( (void*)hnd->base, hnd->size ) ) AERR( "Failed to munmap handle %p", hnd );
 		}
 		close( hnd->share_fd );
-		if ( 0 != ion_free( m->ion_client, hnd->ion_hnd ) ) AERR( "Failed to ion_free( ion_client: %d ion_hnd: %d )", m->ion_client, hnd->ion_hnd );
 		memset( (void*)hnd, 0, sizeof( *hnd ) );
 	}
 }
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_module.cpp b/gralloc960/gralloc_module.cpp
index 232ecc1..df2d82e 100644
--- a/gralloc960/gralloc_module.cpp
+++ b/gralloc960/gralloc_module.cpp
@@ -66,22 +66,14 @@
 	// if this handle was created in this process, then we keep it as is.
 	private_handle_t* hnd = (private_handle_t*)handle;
 
-	if (hnd->pid == getpid())
-	{
-		// If the handle is created and registered in the same process this is valid,
-		// but it could also be that application is registering twice which is illegal.
-		AWAR("Registering handle %p coming from the same process: %d.", hnd, hnd->pid);
-	}
-
 	int retval = -EINVAL;
 
 	pthread_mutex_lock(&s_map_lock);
 
-	hnd->pid = getpid();
-
 	if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) 
 	{
-		AERR( "Can't register buffer %p as it is a framebuffer", handle );
+		AINF("Register framebuffer 0x%p is no-op", handle);
+		retval = 0;
 	}
 	else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION)
 	{
@@ -114,7 +106,7 @@
 	{
 		AERR( "Can't unregister buffer %p as it is a framebuffer", handle );
 	}
-	else if (hnd->pid == getpid()) // never unmap buffers that were not created in this process
+	else
 	{
 		pthread_mutex_lock(&s_map_lock);
 
@@ -142,10 +134,6 @@
 
 		pthread_mutex_unlock(&s_map_lock);
 	}
-	else
-	{
-		AERR( "Trying to unregister buffer %p from process %d that was not created in current process: %d", hnd, hnd->pid, getpid());
-	}
 
 	return 0;
 }
diff --git a/gralloc960/gralloc_priv.h b/gralloc960/gralloc_priv.h
index a945354..55feb67 100644
--- a/gralloc960/gralloc_priv.h
+++ b/gralloc960/gralloc_priv.h
@@ -162,7 +162,7 @@
 	int     share_fd;
 	int     share_attr_fd;
 
-	ion_user_handle_t ion_hnd;
+	ion_user_handle_t ion_hnd_UNUSED;
 
 	// ints
 	int        magic;
@@ -183,7 +183,7 @@
 	};
 	int        lockState;
 	int        writeOwner;
-	int        pid;
+	int        pid_UNUSED;
 
 	// locally mapped shared attribute area
 	union {
@@ -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;
@@ -209,7 +209,8 @@
 #ifdef __cplusplus
 	/*
 	 * We track the number of integers in the structure. There are 16 unconditional
-	 * integers (magic - pid, yuv_info, fd and offset). Note that the fd element is
+	 * integers (magic - pid, yuv_info, shallow_fbdev_fd and offset).
+	 * Note that the shallow_fbdev_fd element is
 	 * considered an int not an fd because it is not intended to be used outside the
 	 * surface flinger process. The GRALLOC_ARM_NUM_INTS variable is used to track the
 	 * number of integers that are conditionally included. Similar considerations apply
@@ -221,7 +222,7 @@
 	private_handle_t(int _flags, int _usage, int _size, void *_base, int lock_state, int fb_file, off_t fb_offset):
 		share_fd(-1),
 		share_attr_fd(-1),
-		ion_hnd(-1),
+		ion_hnd_UNUSED(-1),
 		magic(sMagic),
 		flags(_flags),
 		usage(_usage),
@@ -232,10 +233,10 @@
 		base(_base),
 		lockState(lock_state),
 		writeOwner(0),
-		pid(getpid()),
+		pid_UNUSED(-1),
 		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;
diff --git a/hikey960/device-hikey960.mk b/hikey960/device-hikey960.mk
index 6098480..2645e2d 100644
--- a/hikey960/device-hikey960.mk
+++ b/hikey960/device-hikey960.mk
@@ -22,7 +22,9 @@
 			device/linaro/hikey/init.hikey960.power.rc:root/init.hikey960.power.rc \
 			device/linaro/hikey/init.common.usb.rc:root/init.hikey960.usb.rc \
 			device/linaro/hikey/ueventd.common.rc:root/ueventd.hikey960.rc \
-			device/linaro/hikey/common.kl:system/usr/keylayout/hikey960.kl
+			device/linaro/hikey/common.kl:system/usr/keylayout/hikey960.kl \
+			frameworks/native/data/etc/android.hardware.vulkan.level-0.xml:system/etc/permissions/android.hardware.vulkan.level.xml \
+			frameworks/native/data/etc/android.hardware.vulkan.version-1_0_3.xml:system/etc/permissions/android.hardware.vulkan.version.xml
 
 # Build HiKey960 HDMI audio HAL. Experimental only may not work. FIXME
 PRODUCT_PACKAGES += audio.primary.hikey960
diff --git a/self-extractors_hikey960/arm/staging/device-partial.mk b/self-extractors_hikey960/arm/staging/device-partial.mk
index 8e667d7..8af8e9c 100644
--- a/self-extractors_hikey960/arm/staging/device-partial.mk
+++ b/self-extractors_hikey960/arm/staging/device-partial.mk
@@ -15,4 +15,6 @@
 # Linaro blob(s) necessary for Hikey hardware
 PRODUCT_COPY_FILES := \
     vendor/linaro/hikey960/arm/proprietary/lib64/libGLES_mali.so:system/lib64/egl/libGLES_mali.so:linaro \
-    vendor/linaro/hikey960/arm/proprietary/libGLES_mali.so:system/lib/egl/libGLES_mali.so:linaro
+    vendor/linaro/hikey960/arm/proprietary/libGLES_mali.so:system/lib/egl/libGLES_mali.so:linaro \
+    vendor/linaro/hikey960/arm/proprietary/lib64/libGLES_mali.so:system/vendor/lib64/hw/vulkan.hikey960.so:linaro \
+    vendor/linaro/hikey960/arm/proprietary/libGLES_mali.so:system/vendor/lib/hw/vulkan.hikey960.so:linaro
diff --git a/vendor_owner_info.txt b/vendor_owner_info.txt
index da8d27f..85519d6 100644
--- a/vendor_owner_info.txt
+++ b/vendor_owner_info.txt
@@ -1,2 +1,4 @@
 system/vendor/lib64/egl/libGLES_mali.so:linaro
 system/vendor/lib/egl/libGLES_mali.so:linaro
+system/vendor/lib/hw/vulkan.hikey960.so:linaro
+system/vendor/lib64/hw/vulkan.hikey960.so:linaro