Change setScissor() to take in Vulkan coordinate convention.

* Cache dimensions in GLSurface and GLFramebuffer so that we don't have
to query properties through gl.
* Change argument to const Rect&

Bug: 114439058
Change-Id: Ia5ba9405af92819152e26e13508e0b57bc73f233
Test: SurfaceFlinger_Test, go/wm-smoke
diff --git a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
index 0f0ff62..5c929a3 100644
--- a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
@@ -444,12 +444,17 @@
         if (success && glSurface.getAsync()) {
             eglSwapInterval(mEGLDisplay, 0);
         }
+        if (success) {
+            mSurfaceHeight = glSurface.getHeight();
+        }
     }
+
     return success;
 }
 
 void GLES20RenderEngine::resetCurrentSurface() {
     eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+    mSurfaceHeight = 0;
 }
 
 base::unique_fd GLES20RenderEngine::flush() {
@@ -563,8 +568,12 @@
     drawMesh(mesh);
 }
 
-void GLES20RenderEngine::setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top) {
-    glScissor(left, bottom, right, top);
+void GLES20RenderEngine::setScissor(const Rect& region) {
+    // Invert y-coordinate to map to GL-space.
+    int32_t canvasHeight = mRenderToFbo ? mFboHeight : mSurfaceHeight;
+    int32_t glBottom = canvasHeight - region.bottom;
+
+    glScissor(region.left, glBottom, region.getWidth(), region.getHeight());
     glEnable(GL_SCISSOR_TEST);
 }
 
@@ -612,6 +621,7 @@
                            GL_TEXTURE_2D, textureName, 0);
 
     mRenderToFbo = true;
+    mFboHeight = glFramebuffer->getBufferHeight();
 
     uint32_t glStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
 
@@ -623,13 +633,14 @@
 
 void GLES20RenderEngine::unbindFrameBuffer(Framebuffer* /* framebuffer */) {
     mRenderToFbo = false;
+    mFboHeight = 0;
 
     // back to main framebuffer
     glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
     // Workaround for b/77935566 to force the EGL driver to release the
     // screenshot buffer
-    setScissor(0, 0, 0, 0);
+    setScissor(Rect::EMPTY_RECT);
     clearWithColor(0.0, 0.0, 0.0, 0.0);
     disableScissor();
 }