Fix clearing of dirty textures.

When clear operations fall back to the slow path (i.e. neither fastClear
nor blitReactor is used), we were copying a rectangle the size of the
destination image. It should only sample within the 1x1 source pixel
instead.

Bug chromium:852641, chromium:851707

Change-Id: I9f247483f6167f92be8308b8470c021f5641b657
Reviewed-on: https://swiftshader-review.googlesource.com/19448
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Renderer/Surface.cpp b/src/Renderer/Surface.cpp
index 83412a3..5fc506d 100644
--- a/src/Renderer/Surface.cpp
+++ b/src/Renderer/Surface.cpp
@@ -44,6 +44,8 @@
 
 	void Surface::Buffer::write(int x, int y, int z, const Color<float> &color)
 	{
+		ASSERT(x < width && y < height && z < depth);
+
 		byte *element = (byte*)buffer + (x + border) * bytes + (y + border) * pitchB + z * samples * sliceB;
 
 		for(int i = 0; i < samples; i++)
@@ -55,6 +57,8 @@
 
 	void Surface::Buffer::write(int x, int y, const Color<float> &color)
 	{
+		ASSERT(x < width && y < height);
+
 		byte *element = (byte*)buffer + (x + border) * bytes + (y + border) * pitchB;
 
 		for(int i = 0; i < samples; i++)
@@ -396,6 +400,8 @@
 
 	Color<float> Surface::Buffer::read(int x, int y, int z) const
 	{
+		ASSERT(x < width && y < height && z < depth);
+
 		void *element = (unsigned char*)buffer + (x + border) * bytes + (y + border) * pitchB + z * samples * sliceB;
 
 		return read(element);
@@ -403,6 +409,8 @@
 
 	Color<float> Surface::Buffer::read(int x, int y) const
 	{
+		ASSERT(x < width && y < height);
+
 		void *element = (unsigned char*)buffer + (x + border) * bytes + (y + border) * pitchB;
 
 		return read(element);