Revert "Add more support for transformed clip rects and paths"

this introduced a dead lock in GradientCache's ctor.

This reverts commit dfe082f63e94cde9aee271c94d13de5e7217e036.

Bug: 7096001
Change-Id: I57b8bbab11fb7cb502fa58e3bbf5d19864db874f
diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk
index c3a07a1..1947c32 100644
--- a/libs/hwui/Android.mk
+++ b/libs/hwui/Android.mk
@@ -28,7 +28,6 @@
 		SkiaColorFilter.cpp \
 		SkiaShader.cpp \
 		Snapshot.cpp \
-		Stencil.cpp \
 		TextureCache.cpp \
 		TextDropShadowCache.cpp
 	
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index b9a6336..f4f56d6 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -38,7 +38,6 @@
 #include "TextDropShadowCache.h"
 #include "FboCache.h"
 #include "ResourceCache.h"
-#include "Stencil.h"
 #include "Dither.h"
 
 namespace android {
@@ -253,14 +252,10 @@
     TextDropShadowCache dropShadowCache;
     FboCache fboCache;
     ResourceCache resourceCache;
+    Dither dither;
 
     GammaFontRenderer* fontRenderer;
 
-    Dither dither;
-#if STENCIL_BUFFER_SIZE
-    Stencil stencil;
-#endif
-
     // Debug methods
     PFNGLINSERTEVENTMARKEREXTPROC eventMark;
     PFNGLPUSHGROUPMARKEREXTPROC startMark;
diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp
index b50ed10..2e4e349 100644
--- a/libs/hwui/GradientCache.cpp
+++ b/libs/hwui/GradientCache.cpp
@@ -57,7 +57,7 @@
         INIT_LOGD("  Using default gradient cache size of %.2fMB", DEFAULT_GRADIENT_CACHE_SIZE);
     }
 
-    mMaxTextureSize = Caches::getInstance().maxTextureSize;
+    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
 
     mCache.setOnEntryRemovedListener(this);
 }
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 2f43be8..8da9f66 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -139,6 +139,10 @@
 // Setup
 ///////////////////////////////////////////////////////////////////////////////
 
+uint32_t OpenGLRenderer::getStencilSize() {
+    return STENCIL_BUFFER_SIZE;
+}
+
 bool OpenGLRenderer::isDeferred() {
     return false;
 }
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 4c7cf0a..2369f47 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -208,6 +208,12 @@
     SkPaint* filterPaint(SkPaint* paint);
 
     /**
+     * Returns the desired size for the stencil buffer. If the returned value
+     * is 0, then no stencil buffer is required.
+     */
+    ANDROID_API static uint32_t getStencilSize();
+
+    /**
      * Sets the alpha on the current snapshot. This alpha value will be modulated
      * with other alpha values when drawing primitives.
      */
diff --git a/libs/hwui/Snapshot.cpp b/libs/hwui/Snapshot.cpp
index 4484676..5d5961a 100644
--- a/libs/hwui/Snapshot.cpp
+++ b/libs/hwui/Snapshot.cpp
@@ -57,7 +57,7 @@
         clipRect = &mClipRectRoot;
 #if STENCIL_BUFFER_SIZE
         if (s->clipRegion) {
-            mClipRegionRoot.op(*s->clipRegion, SkRegion::kUnion_Op);
+            mClipRegionRoot.merge(*s->clipRegion);
             clipRegion = &mClipRegionRoot;
         }
 #endif
@@ -84,7 +84,8 @@
 #if STENCIL_BUFFER_SIZE
     if (!clipRegion) {
         clipRegion = &mClipRegionRoot;
-        clipRegion->setRect(clipRect->left, clipRect->top, clipRect->right, clipRect->bottom);
+        android::Rect tmp(clipRect->left, clipRect->top, clipRect->right, clipRect->bottom);
+        clipRegion->set(tmp);
     }
 #endif
 }
@@ -92,11 +93,11 @@
 void Snapshot::copyClipRectFromRegion() {
 #if STENCIL_BUFFER_SIZE
     if (!clipRegion->isEmpty()) {
-        const SkIRect& bounds = clipRegion->getBounds();
-        clipRect->set(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
+        android::Rect bounds(clipRegion->bounds());
+        clipRect->set(bounds.left, bounds.top, bounds.right, bounds.bottom);
 
         if (clipRegion->isRect()) {
-            clipRegion->setEmpty();
+            clipRegion->clear();
             clipRegion = NULL;
         }
     } else {
@@ -106,11 +107,43 @@
 #endif
 }
 
-bool Snapshot::clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op) {
+bool Snapshot::clipRegionOr(float left, float top, float right, float bottom) {
 #if STENCIL_BUFFER_SIZE
-    SkIRect tmp;
-    tmp.set(left, top, right, bottom);
-    clipRegion->op(tmp, op);
+    android::Rect tmp(left, top, right, bottom);
+    clipRegion->orSelf(tmp);
+    copyClipRectFromRegion();
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool Snapshot::clipRegionXor(float left, float top, float right, float bottom) {
+#if STENCIL_BUFFER_SIZE
+    android::Rect tmp(left, top, right, bottom);
+    clipRegion->xorSelf(tmp);
+    copyClipRectFromRegion();
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool Snapshot::clipRegionAnd(float left, float top, float right, float bottom) {
+#if STENCIL_BUFFER_SIZE
+    android::Rect tmp(left, top, right, bottom);
+    clipRegion->andSelf(tmp);
+    copyClipRectFromRegion();
+    return true;
+#else
+    return false;
+#endif
+}
+
+bool Snapshot::clipRegionNand(float left, float top, float right, float bottom) {
+#if STENCIL_BUFFER_SIZE
+    android::Rect tmp(left, top, right, bottom);
+    clipRegion->subtractSelf(tmp);
     copyClipRectFromRegion();
     return true;
 #else
@@ -128,9 +161,14 @@
     bool clipped = false;
 
     switch (op) {
+        case SkRegion::kDifference_Op: {
+            ensureClipRegion();
+            clipped = clipRegionNand(r.left, r.top, r.right, r.bottom);
+            break;
+        }
         case SkRegion::kIntersect_Op: {
             if (CC_UNLIKELY(clipRegion)) {
-                clipped = clipRegionOp(r.left, r.top, r.right, r.bottom, SkRegion::kIntersect_Op);
+                clipped = clipRegionOr(r.left, r.top, r.right, r.bottom);
             } else {
                 clipped = clipRect->intersect(r);
                 if (!clipped) {
@@ -142,22 +180,26 @@
         }
         case SkRegion::kUnion_Op: {
             if (CC_UNLIKELY(clipRegion)) {
-                clipped = clipRegionOp(r.left, r.top, r.right, r.bottom, SkRegion::kUnion_Op);
+                clipped = clipRegionAnd(r.left, r.top, r.right, r.bottom);
             } else {
                 clipped = clipRect->unionWith(r);
             }
             break;
         }
+        case SkRegion::kXOR_Op: {
+            ensureClipRegion();
+            clipped = clipRegionXor(r.left, r.top, r.right, r.bottom);
+            break;
+        }
+        case SkRegion::kReverseDifference_Op: {
+            // TODO!!!!!!!
+            break;
+        }
         case SkRegion::kReplace_Op: {
             setClip(r.left, r.top, r.right, r.bottom);
             clipped = true;
             break;
         }
-        default: {
-            ensureClipRegion();
-            clipped = clipRegionOp(r.left, r.top, r.right, r.bottom, op);
-            break;
-        }
     }
 
     if (clipped) {
@@ -171,7 +213,7 @@
     clipRect->set(left, top, right, bottom);
 #if STENCIL_BUFFER_SIZE
     if (clipRegion) {
-        clipRegion->setEmpty();
+        clipRegion->clear();
         clipRegion = NULL;
     }
 #endif
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index a89b740..30b03fc 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -198,7 +198,7 @@
      *
      * This field is used only if STENCIL_BUFFER_SIZE is > 0.
      */
-    SkRegion* clipRegion;
+    Region* clipRegion;
 
     /**
      * The ancestor layer's dirty region.
@@ -223,14 +223,17 @@
     void ensureClipRegion();
     void copyClipRectFromRegion();
 
-    bool clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op);
+    bool clipRegionOr(float left, float top, float right, float bottom);
+    bool clipRegionXor(float left, float top, float right, float bottom);
+    bool clipRegionAnd(float left, float top, float right, float bottom);
+    bool clipRegionNand(float left, float top, float right, float bottom);
 
     mat4 mTransformRoot;
     Rect mClipRectRoot;
     Rect mLocalClip;
 
 #if STENCIL_BUFFER_SIZE
-    SkRegion mClipRegionRoot;
+    Region mClipRegionRoot;
 #endif
 
 }; // class Snapshot
diff --git a/libs/hwui/Stencil.cpp b/libs/hwui/Stencil.cpp
deleted file mode 100644
index 9d2c86f..0000000
--- a/libs/hwui/Stencil.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <GLES2/gl2.h>
-
-#include "Properties.h"
-#include "Stencil.h"
-
-namespace android {
-namespace uirenderer {
-
-Stencil::Stencil(): mState(kDisabled) {
-}
-
-uint32_t Stencil::getStencilSize() {
-    return STENCIL_BUFFER_SIZE;
-}
-
-void Stencil::clear() {
-    glClearStencil(0);
-    glClear(GL_STENCIL_BUFFER_BIT);
-}
-
-void Stencil::enableTest() {
-    if (mState != kTest) {
-        enable();
-        glStencilFunc(GL_LESS, 0x0, 0x1);
-        // We only want to test, let's keep everything
-        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-        mState = kTest;
-    }
-}
-
-void Stencil::enableWrite() {
-    if (mState != kWrite) {
-        enable();
-        glStencilFunc(GL_ALWAYS, 0x1, 0x1);
-        // The test always passes so the first two values are meaningless
-        glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
-        mState = kWrite;
-    }
-}
-
-void Stencil::enable() {
-    if (!mState == kDisabled) {
-        glEnable(GL_STENCIL_TEST);
-    }
-}
-
-void Stencil::disable() {
-    if (mState != kDisabled) {
-        glDisable(GL_STENCIL_TEST);
-        mState = kDisabled;
-    }
-}
-
-}; // namespace uirenderer
-}; // namespace android
diff --git a/libs/hwui/Stencil.h b/libs/hwui/Stencil.h
deleted file mode 100644
index 67ccc78..0000000
--- a/libs/hwui/Stencil.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_HWUI_STENCIL_H
-#define ANDROID_HWUI_STENCIL_H
-
-#ifndef LOG_TAG
-    #define LOG_TAG "OpenGLRenderer"
-#endif
-
-#include <cutils/compiler.h>
-
-namespace android {
-namespace uirenderer {
-
-///////////////////////////////////////////////////////////////////////////////
-// Stencil buffer management
-///////////////////////////////////////////////////////////////////////////////
-
-class ANDROID_API Stencil {
-public:
-    Stencil();
-
-    /**
-     * Returns the desired size for the stencil buffer. If the returned value
-     * is 0, then no stencil buffer is required.
-     */
-    ANDROID_API static uint32_t getStencilSize();
-
-    /**
-     * Clears the stencil buffer.
-     */
-    void clear();
-
-    /**
-     * Enables stencil test. When the stencil test is enabled the stencil
-     * buffer is not written into.
-     */
-    void enableTest();
-
-    /**
-     * Enables stencil write. When stencil write is enabled, the stencil
-     * test always succeeds and the value 0x1 is written in the stencil
-     * buffer for each fragment.
-     */
-    void enableWrite();
-
-    /**
-     * Disables stencil test and write.
-     */
-    void disable();
-
-    /**
-     * Indicates whether either test or write is enabled.
-     */
-    bool isEnabled() {
-        return mState != kDisabled;
-    }
-
-private:
-    void enable();
-
-    enum StencilState {
-        kDisabled,
-        kTest,
-        kWrite
-    };
-
-    StencilState mState;
-
-}; // class Stencil
-
-}; // namespace uirenderer
-}; // namespace android
-
-#endif // ANDROID_HWUI_STENCIL_H