Add implementations for clipRect(), save() and restore().

The current implementation of clipRect() does not apply local transformations
before setting the new clip.

Change-Id: I5997871bb638dfcd1a8ef96354846af52427e445
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 1236336..8a541fc 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -19,8 +19,32 @@
 
 #include <SkXfermode.h>
 
+#include <utils/RefBase.h>
+
+#include "Rect.h"
+
 namespace android {
 
+class Snapshot: public LightRefBase<Snapshot> {
+public:
+	Snapshot() { }
+
+	Snapshot(const sp<Snapshot> s): clipRect(s->clipRect), flags(0), previous(s) { }
+
+	enum Flags {
+		kFlagClipSet = 0x1,
+	};
+
+	// Clipping rectangle at the time of this snapshot
+	Rect clipRect;
+
+	// Dirty flags
+	int flags;
+
+	// Previous snapshot in the frames stack
+	sp<Snapshot> previous;
+}; // struct Snapshot
+
 class OpenGLRenderer {
 public:
     OpenGLRenderer();
@@ -29,12 +53,32 @@
     void setViewport(int width, int height);
     void prepare();
 
+    int getSaveCount() const;
+    int save(int flags);
+    void restore();
+    void restoreToCount(int saveCount);
+
+    bool clipRect(float left, float top, float right, float bottom);
+
     void drawColor(int color, SkXfermode::Mode mode);
 
 private:
+    int saveSnapshot();
+    bool restoreSnapshot();
+
+    void setScissorFromClip();
+
+    // Dimensions of the drawing surface
+    int mWidth, mHeight;
+
     // Matrix used for ortho projection in shaders
     float mOrthoMatrix[16];
-};
+
+    // Number of saved states
+    int mSaveCount;
+    // Current state
+    sp<Snapshot> mSnapshot;
+}; // class OpenGLRenderer
 
 }; // namespace android