Refactor FrameBuffer blit/flip source.

Pass a surface to the blit/flip functions, instead of a raw pointer.
This puts the FrameBuffer in control of locking and unlocking.

Change-Id: I55335b3beef8d7083aae7687bd25392964261bde
Reviewed-on: https://swiftshader-review.googlesource.com/4482
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Main/FrameBuffer.cpp b/src/Main/FrameBuffer.cpp
index ccf9083..82dff46 100644
--- a/src/Main/FrameBuffer.cpp
+++ b/src/Main/FrameBuffer.cpp
@@ -103,7 +103,7 @@
 		cursor.positionY = y;
 	}
 
-	void FrameBuffer::copy(void *source, Format sourceFormat, size_t sourceStride)
+	void FrameBuffer::copy(sw::Surface *source)
 	{
 		if(!source)
 		{
@@ -115,23 +115,23 @@
 			return;
 		}
 
+		int sourceStride = source->getInternalPitchB();
+
 		updateState = {};
 		updateState.width = width;
 		updateState.height = height;
 		updateState.destFormat = format;
 		updateState.destStride = stride;
-		updateState.sourceFormat = sourceFormat;
-		updateState.sourceStride = topLeftOrigin ? (int)sourceStride : -(int)sourceStride;
+		updateState.sourceFormat = source->getInternalFormat();
+		updateState.sourceStride = topLeftOrigin ? sourceStride : -sourceStride;
 		updateState.cursorWidth = cursor.width;
 		updateState.cursorHeight = cursor.height;
 
-		if(topLeftOrigin)
+		renderbuffer = source->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
+
+		if(!topLeftOrigin)
 		{
-			renderbuffer = source;
-		}
-		else
-		{
-			renderbuffer = (byte*)source + (height - 1) * sourceStride;
+			renderbuffer = (byte*)renderbuffer + (height - 1) * sourceStride;
 		}
 
 		cursor.x = cursor.positionX - cursor.hotspotX;
@@ -147,6 +147,7 @@
 			copyLocked();
 		}
 
+		source->unlockInternal();
 		unlock();
 
 		profiler.nextFrame();   // Assumes every copy() is a full frame