Snap for 4787638 from ea8d8c6e519ac7765c9c587394494033980837ad to oreo-mr1-cts-release

Change-Id: I83468a2931d1e9ce58c7b5a376a3e1eda75ce6c9
diff --git a/external/vulkancts/modules/vulkan/api/vktApiBufferTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiBufferTests.cpp
index 024e826..256ec1e 100644
--- a/external/vulkancts/modules/vulkan/api/vktApiBufferTests.cpp
+++ b/external/vulkancts/modules/vulkan/api/vktApiBufferTests.cpp
@@ -565,11 +565,20 @@
 	const deUint32						heapTypeIndex					= static_cast<deUint32>(deCtz32(memReqs.memoryRequirements.memoryTypeBits));
 	const VkMemoryType					memoryType						= memoryProperties.memoryTypes[heapTypeIndex];
 	const VkMemoryHeap					memoryHeap						= memoryProperties.memoryHeaps[memoryType.heapIndex];
-	const VkDeviceSize					maxBufferSize					= deAlign64(memoryHeap.size >> 1u, memReqs.memoryRequirements.alignment);
 	const deUint32						shrinkBits						= 4u;	// number of bits to shift when reducing the size with each iteration
 
+	// Buffer size - Choose half of the reported heap size for the maximum buffer size, we
+	// should attempt to test as large a portion as possible.
+	//
+	// However on a system where device memory is shared with the system, the maximum size
+	// should be tested against the platform memory limits as a significant portion of the heap
+	// may already be in use by the operating system and other running processes.
+	const VkDeviceSize maxBufferSize = getMaxBufferSize(memoryHeap.size,
+													   memReqs.memoryRequirements.alignment,
+													   getPlatformMemoryLimits(m_context));
+
 	Move<VkDeviceMemory>				memory;
-	size = std::min(size, maxBufferSize);
+	size = deAlign64(std::min(size, maxBufferSize >> 1), memReqs.memoryRequirements.alignment);
 	while (*memory == DE_NULL)
 	{
 		// Create the buffer
diff --git a/external/vulkancts/modules/vulkan/ycbcr/vktYCbCrConversionTests.cpp b/external/vulkancts/modules/vulkan/ycbcr/vktYCbCrConversionTests.cpp
index 163f69e..442320a 100644
--- a/external/vulkancts/modules/vulkan/ycbcr/vktYCbCrConversionTests.cpp
+++ b/external/vulkancts/modules/vulkan/ycbcr/vktYCbCrConversionTests.cpp
@@ -1207,7 +1207,7 @@
 							const IVec2	chromaJRange	(subsampledY ? calculateNearestIJRange(coordFormat, chromaV) : IVec2(j, j));
 
 							for (int chromaJ = chromaJRange.x(); chromaJ <= chromaJRange.y(); chromaJ++)
-							for (int chromaI = chromaIRange.x(); chromaI <= chromaIRange.x(); chromaI++)
+							for (int chromaI = chromaIRange.x(); chromaI <= chromaIRange.y(); chromaI++)
 							{
 								const Interval	srcColor[]	=
 								{
@@ -1231,7 +1231,7 @@
 							const IVec2	chromaJRange	(subsampledY ? calculateLinearIJRange(coordFormat, chromaV) : IVec2(j, j));
 
 							for (int chromaJ = chromaJRange.x(); chromaJ <= chromaJRange.y(); chromaJ++)
-							for (int chromaI = chromaIRange.x(); chromaI <= chromaIRange.x(); chromaI++)
+							for (int chromaI = chromaIRange.x(); chromaI <= chromaIRange.y(); chromaI++)
 							{
 								const Interval	chromaA	(calculateAB(subTexelPrecisionBits, chromaU, chromaI));
 								const Interval	chromaB	(calculateAB(subTexelPrecisionBits, chromaV, chromaJ));
@@ -1396,7 +1396,7 @@
 							const IVec2	chromaJRange	(calculateNearestIJRange(coordFormat, chromaV));
 
 							for (int chromaJ = chromaJRange.x(); chromaJ <= chromaJRange.y(); chromaJ++)
-							for (int chromaI = chromaIRange.x(); chromaI <= chromaIRange.x(); chromaI++)
+							for (int chromaI = chromaIRange.x(); chromaI <= chromaIRange.y(); chromaI++)
 							{
 								const Interval	srcColor[]	=
 								{
@@ -1419,7 +1419,7 @@
 							const IVec2	chromaJRange	(calculateNearestIJRange(coordFormat, chromaV));
 
 							for (int chromaJ = chromaJRange.x(); chromaJ <= chromaJRange.y(); chromaJ++)
-							for (int chromaI = chromaIRange.x(); chromaI <= chromaIRange.x(); chromaI++)
+							for (int chromaI = chromaIRange.x(); chromaI <= chromaIRange.y(); chromaI++)
 							{
 								const Interval	chromaA		(calculateAB(subTexelPrecisionBits, chromaU, chromaI));
 								const Interval	chromaB		(calculateAB(subTexelPrecisionBits, chromaV, chromaJ));
diff --git a/framework/platform/android/tcuAndroidRenderActivity.cpp b/framework/platform/android/tcuAndroidRenderActivity.cpp
index ddbf40e..0c3bd19 100644
--- a/framework/platform/android/tcuAndroidRenderActivity.cpp
+++ b/framework/platform/android/tcuAndroidRenderActivity.cpp
@@ -78,6 +78,7 @@
 	, m_window			(DE_NULL)
 	, m_paused			(false)
 	, m_finish			(false)
+	, m_receivedFirstResize(false)
 {
 }
 
@@ -143,7 +144,29 @@
 			if (m_windowState != WINDOWSTATE_NOT_CREATED && m_windowState != WINDOWSTATE_DESTROYED)
 				throw InternalError("Got unexpected onNativeWindowCreated() event from system");
 
-			m_windowState	= WINDOWSTATE_NOT_INITIALIZED;
+			// The documented behavior for the callbacks is that the native activity
+			// will get a call to onNativeWindowCreated(), at which point it should have
+			// a surface to render to, and can then start immediately.
+			//
+			// The actual creation process has the framework making calls to both
+			// onNativeWindowCreated() and then onNativeWindowResized(). The test
+			// waits for that first resize before it considers the window ready for
+			// rendering.
+			//
+			// However subsequent events in the framework may cause the window to be
+			// recreated at a new position without a size change, which sends on
+			// onNativeWindowDestroyed(), and then on onNativeWindowCreated() without
+			// a follow-up onNativeWindowResized(). If this happens, the test will
+			// stop rendering as it is no longer in the ready state, and a watchdog
+			// thread will eventually kill the test, causing it to fail. We therefore
+			// set the window state back to READY and process the window creation here
+			// if we have already observed that first resize call.
+			if (!m_receivedFirstResize) {
+				m_windowState	= WINDOWSTATE_NOT_INITIALIZED;
+			} else {
+				m_windowState	= WINDOWSTATE_READY;
+				onWindowCreated(message.payload.window);
+			}
 			m_window		= message.payload.window;
 			break;
 
@@ -151,6 +174,10 @@
 			if (m_window != message.payload.window)
 				throw InternalError("Got onNativeWindowResized() event targeting different window");
 
+			// Record that we've the first resize event, in case the window is
+			// recreated later without a resize.
+			m_receivedFirstResize = true;
+
 			if (m_windowState == WINDOWSTATE_NOT_INITIALIZED)
 			{
 				// Got first resize event, window is ready for use.
diff --git a/framework/platform/android/tcuAndroidRenderActivity.hpp b/framework/platform/android/tcuAndroidRenderActivity.hpp
index e2e7331..9cad495 100644
--- a/framework/platform/android/tcuAndroidRenderActivity.hpp
+++ b/framework/platform/android/tcuAndroidRenderActivity.hpp
@@ -158,6 +158,7 @@
 	ANativeWindow*			m_window;
 	bool					m_paused;					//!< Is rendering paused?
 	bool					m_finish;					//!< Has thread received FINISH message?
+	bool					m_receivedFirstResize;				//!< Has the first onWindowResized been processed?
 };
 
 class RenderActivity : public NativeActivity