aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu/src/GrGLIRect.h
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-18 16:09:55 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-18 16:09:55 +0000
commit8895a7a0e222de4530e506e43eaa5e6030e8c5ed (patch)
tree1493fb4cf14a7cfaccf86a16302495d7c27d61f5 /gpu/src/GrGLIRect.h
parentce2b1afb582f0a2274f476c949cff8b0e1c72b36 (diff)
Reduce glGets for stencil bits.
Clean up GL vs Gr rect conventions for viewport and scissor. Review URL: http://codereview.appspot.com/4185056/ git-svn-id: http://skia.googlecode.com/svn/trunk@813 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src/GrGLIRect.h')
-rw-r--r--gpu/src/GrGLIRect.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/gpu/src/GrGLIRect.h b/gpu/src/GrGLIRect.h
new file mode 100644
index 0000000000..b8638c0af9
--- /dev/null
+++ b/gpu/src/GrGLIRect.h
@@ -0,0 +1,64 @@
+#include "GrGLConfig.h"
+
+#ifndef GrGLIRect_DEFINED
+#define GrGLIRect_DEFINED
+
+/**
+ * Helper struct for dealing with the fact that Ganesh and GL use different
+ * window coordinate systems (top-down vs bottom-up)
+ */
+struct GrGLIRect {
+ GLint fLeft;
+ GLint fBottom;
+ GLsizei fWidth;
+ GLsizei fHeight;
+
+ void pushToGLViewport() const {
+ GR_GL(Viewport(fLeft, fBottom, fWidth, fHeight));
+ }
+
+ void pushToGLScissor() const {
+ GR_GL(Scissor(fLeft, fBottom, fWidth, fHeight));
+ }
+
+ void setFromGLViewport() {
+ GR_STATIC_ASSERT(sizeof(*this) == 4*sizeof(GLint));
+ GR_GL_GetIntegerv(GL_VIEWPORT, (GLint*) this);
+ }
+
+ // sometimes we have a GrIRect from the client that we
+ // want to simultaneously make relative to GL's viewport
+ // and convert from top-down to bottom-up.
+ void setRelativeTo(const GrGLIRect& glRect,
+ int leftOffset,
+ int topOffset,
+ int width,
+ int height) {
+ fLeft = glRect.fLeft + leftOffset;
+ fWidth = width;
+ fBottom = glRect.fBottom + (glRect.fHeight - topOffset - height);
+ fHeight = height;
+
+ GrAssert(fLeft >= 0);
+ GrAssert(fWidth >= 0);
+ GrAssert(fBottom >= 0);
+ GrAssert(fHeight >= 0);
+ }
+
+ bool contains(const GrGLIRect& glRect) const {
+ return fLeft <= glRect.fLeft &&
+ fBottom <= glRect.fBottom &&
+ fLeft + fWidth >= glRect.fLeft + glRect.fWidth &&
+ fBottom + fHeight >= glRect.fBottom + glRect.fHeight;
+ }
+
+ void invalidate() {fLeft = fWidth = fBottom = fHeight = -1;}
+
+ bool operator ==(const GrGLIRect& glRect) const {
+ return 0 == memcmp(this, &glRect, sizeof(GrGLIRect));
+ }
+
+ bool operator !=(const GrGLIRect& glRect) const {return !(*this == glRect);}
+};
+
+#endif \ No newline at end of file