Surface: Do not copy back if front and back buffer are identical

It is unnecessary to copy from and to the same surface. Skipping
the copy back is a huge performance improvement when using shared
buffer mode and locking a rectangle of the surface.

Bug: 38398135
Test: Use stylus demo and remove full-surface locking hack.
Change-Id: Ie8d03468507489247ba4a4be5f0cde5960e69c16
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index ff0a5d4..94d8578 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -1518,6 +1518,9 @@
         const Region& reg,
         int *dstFenceFd)
 {
+    if (dst->getId() == src->getId())
+        return OK;
+
     // src and dst with, height and format must be identical. no verification
     // is done here.
     status_t err;