Added GrContext::AutoClipStack to encapsulate setting\resetting of clip stack
http://codereview.appspot.com/6343097/
git-svn-id: http://skia.googlecode.com/svn/trunk@4558 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 8f7378f..a199beb 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -338,12 +338,6 @@
*/
void setClip(const GrClip& clip);
- /**
- * Convenience method for setting the clip to a rect.
- * @param rect the rect to set as the new clip.
- */
- void setClip(const GrIRect& rect);
-
///////////////////////////////////////////////////////////////////////////
// Draws
@@ -701,6 +695,26 @@
GrMatrix fMatrix;
};
+ class AutoClip : GrNoncopyable {
+ public:
+ AutoClip(GrContext* context, const GrRect& newClipRect)
+ : fContext(context)
+ , fNewClip(newClipRect) {
+ fOldClip = fContext->getClip();
+ fContext->setClip(fNewClip);
+ }
+
+ ~AutoClip() {
+ if (NULL != fContext) {
+ fContext->setClip(fOldClip);
+ }
+ }
+ private:
+ GrContext* fContext;
+ GrClip fOldClip;
+ GrClip fNewClip;
+ };
+
///////////////////////////////////////////////////////////////////////////
// Functions intended for internal use only.
GrGpu* getGpu() { return fGpu; }