Snap for 10342859 from e787b4a1c63e79f172c63ddf0f5a4895fb7c8eab to udc-d1-release

Change-Id: I42a2834c0cbebb33115e75582a3c43689dd0ba12
diff --git a/gralloc4/src/allocator/mali_gralloc_ion.cpp b/gralloc4/src/allocator/mali_gralloc_ion.cpp
index 5f7fc26..da9aba5 100644
--- a/gralloc4/src/allocator/mali_gralloc_ion.cpp
+++ b/gralloc4/src/allocator/mali_gralloc_ion.cpp
@@ -363,6 +363,7 @@
                               uint32_t numDescriptors, buffer_handle_t *pHandle,
                               bool *shared_backend, int ion_fd)
 {
+	ATRACE_CALL();
 	GRALLOC_UNUSED(shared_backend);
 
 	unsigned int priv_heap_flag = 0;
@@ -426,6 +427,7 @@
 	}
 
 #if defined(GRALLOC_INIT_AFBC) && (GRALLOC_INIT_AFBC == 1)
+	ATRACE_NAME("AFBC init block");
 	unsigned char *cpu_ptr = NULL;
 	for (i = 0; i < numDescriptors; i++)
 	{
@@ -437,34 +439,42 @@
 		if ((bufDescriptor->alloc_format & MALI_GRALLOC_INTFMT_AFBCENABLE_MASK)
 			&& !(usage & GRALLOC_USAGE_PROTECTED))
 		{
-			/* TODO: only map for AFBC buffers */
-			cpu_ptr =
-			    (unsigned char *)mmap(NULL, bufDescriptor->alloc_sizes[0], PROT_READ | PROT_WRITE, MAP_SHARED, hnd->fds[0], 0);
-
-			if (MAP_FAILED == cpu_ptr)
 			{
-				MALI_GRALLOC_LOGE("mmap failed for fd ( %d )", hnd->fds[0]);
-				mali_gralloc_ion_free_internal(pHandle, numDescriptors);
-				return -1;
+				ATRACE_NAME("mmap");
+				/* TODO: only map for AFBC buffers */
+				cpu_ptr =
+				    (unsigned char *)mmap(NULL, bufDescriptor->alloc_sizes[0], PROT_READ | PROT_WRITE, MAP_SHARED, hnd->fds[0], 0);
+
+				if (MAP_FAILED == cpu_ptr)
+				{
+					MALI_GRALLOC_LOGE("mmap failed for fd ( %d )", hnd->fds[0]);
+					mali_gralloc_ion_free_internal(pHandle, numDescriptors);
+					return -1;
+				}
+
+				mali_gralloc_ion_sync_start(hnd, true, true);
 			}
 
-			mali_gralloc_ion_sync_start(hnd, true, true);
-
-			/* For separated plane YUV, there is a header to initialise per plane. */
-			const plane_info_t *plane_info = bufDescriptor->plane_info;
-			const bool is_multi_plane = hnd->is_multi_plane();
-			for (int i = 0; i < MAX_PLANES && (i == 0 || plane_info[i].byte_stride != 0); i++)
 			{
-				init_afbc(cpu_ptr + plane_info[i].offset,
-				          bufDescriptor->alloc_format,
-				          is_multi_plane,
-				          plane_info[i].alloc_width,
-				          plane_info[i].alloc_height);
+				ATRACE_NAME("data init");
+				/* For separated plane YUV, there is a header to initialise per plane. */
+				const plane_info_t *plane_info = bufDescriptor->plane_info;
+				const bool is_multi_plane = hnd->is_multi_plane();
+				for (int i = 0; i < MAX_PLANES && (i == 0 || plane_info[i].byte_stride != 0); i++)
+				{
+					init_afbc(cpu_ptr + plane_info[i].offset,
+					          bufDescriptor->alloc_format,
+					          is_multi_plane,
+					          plane_info[i].alloc_width,
+					          plane_info[i].alloc_height);
+				}
 			}
 
-			mali_gralloc_ion_sync_end(hnd, true, true);
-
-			munmap(cpu_ptr, bufDescriptor->alloc_sizes[0]);
+			{
+				ATRACE_NAME("munmap");
+				mali_gralloc_ion_sync_end(hnd, true, true);
+				munmap(cpu_ptr, bufDescriptor->alloc_sizes[0]);
+			}
 		}
 	}
 #endif
diff --git a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
index 19c2a21..4a0618b 100644
--- a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
+++ b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
@@ -247,6 +247,7 @@
                const bool is_multi_plane,
                const int w, const int h)
 {
+	ATRACE_CALL();
 	const bool is_tiled = ((alloc_format & MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS)
 	                         == MALI_GRALLOC_INTFMT_AFBC_TILED_HEADERS);
 	const uint32_t n_headers = (w * h) / AFBC_PIXELS_PER_BLOCK;
@@ -984,6 +985,7 @@
 
 int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescriptor)
 {
+	ATRACE_CALL();
 	alloc_type_t alloc_type{};
 
 	int alloc_width = bufDescriptor->width;
@@ -1127,7 +1129,16 @@
                                  uint32_t numDescriptors, buffer_handle_t *pHandle, bool *shared_backend,
                                  int fd)
 {
-	ATRACE_CALL();
+	std::string atrace_log = __FUNCTION__;
+	if (ATRACE_ENABLED()) {
+		buffer_descriptor_t * const bufDescriptor = (buffer_descriptor_t *)(descriptors[0]);
+		std::stringstream ss;
+		ss << __FUNCTION__ << "(f=0x" << std::hex << bufDescriptor->hal_format << ", u=0x" <<
+			bufDescriptor->producer_usage << ", w=" << std::dec << bufDescriptor->width << ", h=" << bufDescriptor->height << ")";
+		atrace_log = ss.str();
+	}
+	ATRACE_NAME(atrace_log.c_str());
+
 	bool shared = false;
 	uint64_t backing_store_id = 0x0;
 	int err;