Use only external surface dimensions.

They should always be identical to the internal ones.

Bug 21424351

Change-Id: Iafa18c14cc4d2e16f20238dac0208a8159cbaa6a
Reviewed-on: https://swiftshader-review.googlesource.com/3460
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Main/FrameBuffer.cpp b/src/Main/FrameBuffer.cpp
index a2f9d52..59543ac 100644
--- a/src/Main/FrameBuffer.cpp
+++ b/src/Main/FrameBuffer.cpp
@@ -124,8 +124,8 @@
 			cursor = cursorImage->lockExternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
 			cursorImage->unlockExternal();
 
-			cursorWidth = cursorImage->getExternalWidth();
-			cursorHeight = cursorImage->getExternalHeight();
+			cursorWidth = cursorImage->getWidth();
+			cursorHeight = cursorImage->getHeight();
 		}
 		else
 		{
diff --git a/src/OpenGL/libGL/Device.cpp b/src/OpenGL/libGL/Device.cpp
index 5a90363..7dc9376 100644
--- a/src/OpenGL/libGL/Device.cpp
+++ b/src/OpenGL/libGL/Device.cpp
@@ -185,8 +185,8 @@
 

 		int x0 = 0;

 		int y0 = 0;

-		int width = renderTarget->getExternalWidth();

-		int height = renderTarget->getExternalHeight();

+		int width = renderTarget->getWidth();

+		int height = renderTarget->getHeight();

 

 		if(scissorEnable)   // Clamp against scissor rectangle

 		{

@@ -211,8 +211,8 @@
 

 		int x0 = 0;

 		int y0 = 0;

-		int width = depthStencil->getExternalWidth();

-		int height = depthStencil->getExternalHeight();

+		int width = depthStencil->getWidth();

+		int height = depthStencil->getHeight();

 

 		if(scissorEnable)   // Clamp against scissor rectangle

 		{

@@ -234,8 +234,8 @@
 

 		int x0 = 0;

 		int y0 = 0;

-		int width = depthStencil->getExternalWidth();

-		int height = depthStencil->getExternalHeight();

+		int width = depthStencil->getWidth();

+		int height = depthStencil->getHeight();

 

 		if(scissorEnable)   // Clamp against scissor rectangle

 		{

@@ -496,10 +496,10 @@
 			return false;

 		}

 		

-		int sWidth = source->getExternalWidth();

-		int sHeight = source->getExternalHeight();

-		int dWidth = dest->getExternalWidth();

-		int dHeight = dest->getExternalHeight();

+		int sWidth = source->getWidth();

+		int sHeight = source->getHeight();

+		int dWidth = dest->getWidth();

+		int dHeight = dest->getHeight();

 

 		SliceRect sRect;

 		SliceRect dRect;

@@ -547,8 +547,8 @@
 				sw::byte *sourceBuffer = (sw::byte*)source->lockInternal(0, 0, sRect.slice, LOCK_READONLY, PUBLIC);

 				sw::byte *destBuffer = (sw::byte*)dest->lockInternal(0, 0, dRect.slice, LOCK_DISCARD, PUBLIC);

 

-				unsigned int width = source->getInternalWidth();

-				unsigned int height = source->getInternalHeight();

+				unsigned int width = source->getWidth();

+				unsigned int height = source->getHeight();

 				unsigned int pitch = source->getInternalPitchB();

 

 				for(unsigned int y = 0; y < height; y++)

@@ -568,8 +568,8 @@
 				sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, PUBLIC);

 				sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, PUBLIC);

 

-				unsigned int width = source->getInternalWidth();

-				unsigned int height = source->getInternalHeight();

+				unsigned int width = source->getWidth();

+				unsigned int height = source->getHeight();

 				unsigned int pitch = source->getStencilPitchB();

 

 				for(unsigned int y = 0; y < height; y++)

@@ -710,17 +710,17 @@
 			if(renderTarget)

 			{

 				scissor.x0 = max(scissor.x0, 0);

-				scissor.x1 = min(scissor.x1, renderTarget->getExternalWidth());

+				scissor.x1 = min(scissor.x1, renderTarget->getWidth());

 				scissor.y0 = max(scissor.y0, 0);

-				scissor.y1 = min(scissor.y1, renderTarget->getExternalHeight());

+				scissor.y1 = min(scissor.y1, renderTarget->getHeight());

 			}

 

 			if(depthStencil)

 			{

 				scissor.x0 = max(scissor.x0, 0);

-				scissor.x1 = min(scissor.x1, depthStencil->getExternalWidth());

+				scissor.x1 = min(scissor.x1, depthStencil->getWidth());

 				scissor.y0 = max(scissor.y0, 0);

-				scissor.y1 = min(scissor.y1, depthStencil->getExternalHeight());

+				scissor.y1 = min(scissor.y1, depthStencil->getHeight());

 			}

 

 			setScissor(scissor);

diff --git a/src/OpenGL/libGLES_CM/Device.cpp b/src/OpenGL/libGLES_CM/Device.cpp
index a37fb89..508668f 100644
--- a/src/OpenGL/libGLES_CM/Device.cpp
+++ b/src/OpenGL/libGLES_CM/Device.cpp
@@ -144,8 +144,8 @@
 

 		int x0 = 0;

 		int y0 = 0;

-		int width = renderTarget->getExternalWidth();

-		int height = renderTarget->getExternalHeight();

+		int width = renderTarget->getWidth();

+		int height = renderTarget->getHeight();

 

 		if(scissorEnable)   // Clamp against scissor rectangle

 		{

@@ -170,8 +170,8 @@
 

 		int x0 = 0;

 		int y0 = 0;

-		int width = depthStencil->getExternalWidth();

-		int height = depthStencil->getExternalHeight();

+		int width = depthStencil->getWidth();

+		int height = depthStencil->getHeight();

 

 		if(scissorEnable)   // Clamp against scissor rectangle

 		{

@@ -193,8 +193,8 @@
 

 		int x0 = 0;

 		int y0 = 0;

-		int width = depthStencil->getExternalWidth();

-		int height = depthStencil->getExternalHeight();

+		int width = depthStencil->getWidth();

+		int height = depthStencil->getHeight();

 

 		if(scissorEnable)   // Clamp against scissor rectangle

 		{

@@ -414,10 +414,10 @@
 			return false;

 		}

 		

-		int sWidth = source->getExternalWidth();

-		int sHeight = source->getExternalHeight();

-		int dWidth = dest->getExternalWidth();

-		int dHeight = dest->getExternalHeight();

+		int sWidth = source->getWidth();

+		int sHeight = source->getHeight();

+		int dWidth = dest->getWidth();

+		int dHeight = dest->getHeight();

 

 		SliceRect sRect;

 		SliceRect dRect;

@@ -465,8 +465,8 @@
 				sw::byte *sourceBuffer = (sw::byte*)source->lockInternal(0, 0, sRect.slice, LOCK_READONLY, PUBLIC);

 				sw::byte *destBuffer = (sw::byte*)dest->lockInternal(0, 0, dRect.slice, LOCK_DISCARD, PUBLIC);

 

-				unsigned int width = source->getInternalWidth();

-				unsigned int height = source->getInternalHeight();

+				unsigned int width = source->getWidth();

+				unsigned int height = source->getHeight();

 				unsigned int pitch = source->getInternalPitchB();

 

 				for(unsigned int y = 0; y < height; y++)

@@ -486,8 +486,8 @@
 				sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, PUBLIC);

 				sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, PUBLIC);

 

-				unsigned int width = source->getInternalWidth();

-				unsigned int height = source->getInternalHeight();

+				unsigned int width = source->getWidth();

+				unsigned int height = source->getHeight();

 				unsigned int pitch = source->getStencilPitchB();

 

 				for(unsigned int y = 0; y < height; y++)

@@ -583,17 +583,17 @@
 			if(renderTarget)

 			{

 				scissor.x0 = max(scissor.x0, 0);

-				scissor.x1 = min(scissor.x1, renderTarget->getExternalWidth());

+				scissor.x1 = min(scissor.x1, renderTarget->getWidth());

 				scissor.y0 = max(scissor.y0, 0);

-				scissor.y1 = min(scissor.y1, renderTarget->getExternalHeight());

+				scissor.y1 = min(scissor.y1, renderTarget->getHeight());

 			}

 

 			if(depthStencil)

 			{

 				scissor.x0 = max(scissor.x0, 0);

-				scissor.x1 = min(scissor.x1, depthStencil->getExternalWidth());

+				scissor.x1 = min(scissor.x1, depthStencil->getWidth());

 				scissor.y0 = max(scissor.y0, 0);

-				scissor.y1 = min(scissor.y1, depthStencil->getExternalHeight());

+				scissor.y1 = min(scissor.y1, depthStencil->getHeight());

 			}

 

 			setScissor(scissor);

diff --git a/src/OpenGL/libGLESv2/Device.cpp b/src/OpenGL/libGLESv2/Device.cpp
index 36ac149..79b8c26 100644
--- a/src/OpenGL/libGLESv2/Device.cpp
+++ b/src/OpenGL/libGLESv2/Device.cpp
@@ -161,8 +161,8 @@
 	{

 		x0 = 0;

 		y0 = 0;

-		width = sourceSurface->getExternalWidth();

-		height = sourceSurface->getExternalHeight();

+		width = sourceSurface->getWidth();

+		height = sourceSurface->getHeight();

 

 		if(scissorEnable)   // Clamp against scissor rectangle

 		{

@@ -511,10 +511,10 @@
 			return false;

 		}

 		

-		int sWidth = source->getExternalWidth();

-		int sHeight = source->getExternalHeight();

-		int dWidth = dest->getExternalWidth();

-		int dHeight = dest->getExternalHeight();

+		int sWidth = source->getWidth();

+		int sHeight = source->getHeight();

+		int dWidth = dest->getWidth();

+		int dHeight = dest->getHeight();

 

 		bool flipX = false;

 		bool flipY = false;

@@ -606,7 +606,7 @@
 				sw::byte *sourceBuffer = (sw::byte*)source->lockInternal(0, 0, sourceRect->slice, LOCK_READONLY, PUBLIC);

 				sw::byte *destBuffer = (sw::byte*)dest->lockInternal(0, 0, destRect->slice, LOCK_DISCARD, PUBLIC);

 

-				copyBuffer(sourceBuffer, destBuffer, source->getInternalWidth(), source->getInternalHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), egl::Image::bytes(source->getInternalFormat()), flipX, flipY);

+				copyBuffer(sourceBuffer, destBuffer, source->getWidth(), source->getHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), egl::Image::bytes(source->getInternalFormat()), flipX, flipY);

 

 				source->unlockInternal();

 				dest->unlockInternal();

@@ -617,7 +617,7 @@
 				sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, PUBLIC);

 				sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, PUBLIC);

 

-				copyBuffer(sourceBuffer, destBuffer, source->getInternalWidth(), source->getInternalHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), egl::Image::bytes(source->getInternalFormat()), flipX, flipY);

+				copyBuffer(sourceBuffer, destBuffer, source->getWidth(), source->getHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), egl::Image::bytes(source->getInternalFormat()), flipX, flipY);

 

 				source->unlockStencil();

 				dest->unlockStencil();

@@ -673,12 +673,12 @@
 			return false;

 		}

 

-		int sWidth  = source->getExternalWidth();

-		int sHeight = source->getExternalHeight();

-		int sDepth  = source->getExternalDepth();

-		int dWidth  = dest->getExternalWidth();

-		int dHeight = dest->getExternalHeight();

-		int dDepth  = dest->getExternalDepth();

+		int sWidth  = source->getWidth();

+		int sHeight = source->getHeight();

+		int sDepth  = source->getDepth();

+		int dWidth  = dest->getWidth();

+		int dHeight = dest->getHeight();

+		int dDepth  = dest->getDepth();

 

 		bool scaling = (sWidth != dWidth) || (sHeight != dHeight) || (sDepth != dDepth);

 		bool equalFormats = source->getInternalFormat() == dest->getInternalFormat();

@@ -817,17 +817,17 @@
 			if(renderTarget)

 			{

 				scissor.x0 = max(scissor.x0, 0);

-				scissor.x1 = min(scissor.x1, renderTarget->getExternalWidth());

+				scissor.x1 = min(scissor.x1, renderTarget->getWidth());

 				scissor.y0 = max(scissor.y0, 0);

-				scissor.y1 = min(scissor.y1, renderTarget->getExternalHeight());

+				scissor.y1 = min(scissor.y1, renderTarget->getHeight());

 			}

 

 			if(depthStencil)

 			{

 				scissor.x0 = max(scissor.x0, 0);

-				scissor.x1 = min(scissor.x1, depthStencil->getExternalWidth());

+				scissor.x1 = min(scissor.x1, depthStencil->getWidth());

 				scissor.y0 = max(scissor.y0, 0);

-				scissor.y1 = min(scissor.y1, depthStencil->getExternalHeight());

+				scissor.y1 = min(scissor.y1, depthStencil->getHeight());

 			}

 

 			setScissor(scissor);

diff --git a/src/Renderer/Blitter.cpp b/src/Renderer/Blitter.cpp
index f3b9ab6..07f9e3b 100644
--- a/src/Renderer/Blitter.cpp
+++ b/src/Renderer/Blitter.cpp
@@ -95,18 +95,18 @@
 		source->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
 		dest->lockInternal(0, 0, 0, sw::LOCK_WRITEONLY, sw::PUBLIC);
 
-		float w = static_cast<float>(source->getExternalWidth())  / static_cast<float>(dest->getExternalWidth());
-		float h = static_cast<float>(source->getExternalHeight()) / static_cast<float>(dest->getExternalHeight());
-		float d = static_cast<float>(source->getExternalDepth())  / static_cast<float>(dest->getExternalDepth());
+		float w = static_cast<float>(source->getWidth())  / static_cast<float>(dest->getWidth());
+		float h = static_cast<float>(source->getHeight()) / static_cast<float>(dest->getHeight());
+		float d = static_cast<float>(source->getDepth())  / static_cast<float>(dest->getDepth());
 
 		float z = 0.5f * d;
-		for(int k = 0; k < dest->getExternalDepth(); ++k)
+		for(int k = 0; k < dest->getDepth(); ++k)
 		{
 			float y = 0.5f * h;
-			for(int j = 0; j < dest->getExternalHeight(); ++j)
+			for(int j = 0; j < dest->getHeight(); ++j)
 			{
 				float x = 0.5f * w;
-				for(int i = 0; i < dest->getExternalWidth(); ++i)
+				for(int i = 0; i < dest->getWidth(); ++i)
 				{
 					dest->writeInternal(i, j, k, source->sampleInternal(x, y, z));
 					x += w;
@@ -271,7 +271,7 @@
 						unscale = vector(1.0f, 1.0f, 1.0f, 1.0f);
 						break;
 					default:
-						return false;
+						return nullptr;
 					}
 
 					float4 scale;
@@ -296,7 +296,7 @@
 						scale = vector(1.0f, 1.0f, 1.0f, 1.0f);
 						break;
 					default:
-						return false;
+						return nullptr;
 					}
 
 					if(unscale != scale)
@@ -309,9 +309,9 @@
 						color = Min(color, Float4(1.0f, 1.0f, 1.0f, 1.0f));
 
 						color = Max(color, Float4(Surface::isUnsignedComponent(state.destFormat, 0) ? 0.0f : -1.0f,
-							                        Surface::isUnsignedComponent(state.destFormat, 1) ? 0.0f : -1.0f,
-													Surface::isUnsignedComponent(state.destFormat, 2) ? 0.0f : -1.0f,
-													Surface::isUnsignedComponent(state.destFormat, 3) ? 0.0f : -1.0f));
+						                          Surface::isUnsignedComponent(state.destFormat, 1) ? 0.0f : -1.0f,
+						                          Surface::isUnsignedComponent(state.destFormat, 2) ? 0.0f : -1.0f,
+						                          Surface::isUnsignedComponent(state.destFormat, 3) ? 0.0f : -1.0f));
 					}
 
 					Pointer<Byte> d = destLine + i * Surface::bytes(state.destFormat);
@@ -368,7 +368,7 @@
 						*Pointer<Float>(d) = color.x;
 						break;
 					default:
-						return false;
+						return nullptr;
 					}
 
 					x += w;
@@ -439,8 +439,8 @@
 		data.y0d = dRect.y0;
 		data.y1d = dRect.y1;
 
-		data.sWidth = source->getInternalWidth();
-		data.sHeight = source->getInternalHeight();
+		data.sWidth = source->getWidth();
+		data.sHeight = source->getHeight();
 
 		blitFunction(&data);
 
diff --git a/src/Renderer/Sampler.cpp b/src/Renderer/Sampler.cpp
index 3d73ceb..9f26e4e 100644
--- a/src/Renderer/Sampler.cpp
+++ b/src/Renderer/Sampler.cpp
@@ -109,9 +109,9 @@
 				externalTextureFormat = surface->getExternalFormat();
 				internalTextureFormat = surface->getInternalFormat();
 
-				int width = surface->getInternalWidth();
-				int height = surface->getInternalHeight();
-				int depth = surface->getInternalDepth();
+				int width = surface->getWidth();
+				int height = surface->getHeight();
+				int depth = surface->getDepth();
 				int pitchP = surface->getInternalPitchP();
 				int sliceP = surface->getInternalSliceP();
 
diff --git a/src/Renderer/Surface.hpp b/src/Renderer/Surface.hpp
index b50c127..75c926a 100644
--- a/src/Renderer/Surface.hpp
+++ b/src/Renderer/Surface.hpp
@@ -165,11 +165,12 @@
 		

 		virtual ~Surface();

 

+		inline int getWidth() const;

+		inline int getHeight() const;

+		inline int getDepth() const;

+

 		void *lockExternal(int x, int y, int z, Lock lock, Accessor client);

 		void unlockExternal();

-		inline int getExternalWidth() const;

-		inline int getExternalHeight() const;

-		inline int getExternalDepth() const;

 		inline Format getExternalFormat() const;

 		inline int getExternalPitchB() const;

 		inline int getExternalPitchP() const;

@@ -178,9 +179,6 @@
 

 		virtual void *lockInternal(int x, int y, int z, Lock lock, Accessor client);

 		virtual void unlockInternal();

-		inline int getInternalWidth() const;

-		inline int getInternalHeight() const;

-		inline int getInternalDepth() const;

 		inline Format getInternalFormat() const;

 		inline int getInternalPitchB() const;

 		inline int getInternalPitchP() const;

@@ -377,17 +375,17 @@
 

 namespace sw

 {

-	int Surface::getExternalWidth() const

+	int Surface::getWidth() const

 	{

 		return external.width;

 	}

 

-	int Surface::getExternalHeight() const

+	int Surface::getHeight() const

 	{

 		return external.height;

 	}

 

-	int Surface::getExternalDepth() const

+	int Surface::getDepth() const

 	{

 		return external.depth;

 	}

@@ -417,21 +415,6 @@
 		return external.sliceP;

 	}

 

-	int Surface::getInternalWidth() const

-	{

-		return internal.width;

-	}

-

-	int Surface::getInternalHeight() const

-	{

-		return internal.height;

-	}

-

-	int Surface::getInternalDepth() const

-	{

-		return internal.depth;

-	}

-

 	Format Surface::getInternalFormat() const

 	{

 		return internal.format;