michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: michael@0: #ifndef GrGLIRect_DEFINED michael@0: #define GrGLIRect_DEFINED michael@0: michael@0: #include "gl/GrGLInterface.h" michael@0: #include "GrGLUtil.h" michael@0: michael@0: /** michael@0: * Helper struct for dealing with the fact that Ganesh and GL use different michael@0: * window coordinate systems (top-down vs bottom-up) michael@0: */ michael@0: struct GrGLIRect { michael@0: GrGLint fLeft; michael@0: GrGLint fBottom; michael@0: GrGLsizei fWidth; michael@0: GrGLsizei fHeight; michael@0: michael@0: void pushToGLViewport(const GrGLInterface* gl) const { michael@0: GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight)); michael@0: } michael@0: michael@0: void pushToGLScissor(const GrGLInterface* gl) const { michael@0: GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight)); michael@0: } michael@0: michael@0: void setFromGLViewport(const GrGLInterface* gl) { michael@0: GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint)); michael@0: GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) this); michael@0: } michael@0: michael@0: // sometimes we have a SkIRect from the client that we michael@0: // want to simultaneously make relative to GL's viewport michael@0: // and (optionally) convert from top-down to bottom-up. michael@0: void setRelativeTo(const GrGLIRect& glRect, michael@0: int leftOffset, michael@0: int topOffset, michael@0: int width, michael@0: int height, michael@0: GrSurfaceOrigin origin) { michael@0: fLeft = glRect.fLeft + leftOffset; michael@0: fWidth = width; michael@0: if (kBottomLeft_GrSurfaceOrigin == origin) { michael@0: fBottom = glRect.fBottom + (glRect.fHeight - topOffset - height); michael@0: } else { michael@0: fBottom = glRect.fBottom + topOffset; michael@0: } michael@0: fHeight = height; michael@0: michael@0: SkASSERT(fLeft >= 0); michael@0: SkASSERT(fWidth >= 0); michael@0: SkASSERT(fBottom >= 0); michael@0: SkASSERT(fHeight >= 0); michael@0: } michael@0: michael@0: bool contains(const GrGLIRect& glRect) const { michael@0: return fLeft <= glRect.fLeft && michael@0: fBottom <= glRect.fBottom && michael@0: fLeft + fWidth >= glRect.fLeft + glRect.fWidth && michael@0: fBottom + fHeight >= glRect.fBottom + glRect.fHeight; michael@0: } michael@0: michael@0: void invalidate() {fLeft = fWidth = fBottom = fHeight = -1;} michael@0: michael@0: bool operator ==(const GrGLIRect& glRect) const { michael@0: return 0 == memcmp(this, &glRect, sizeof(GrGLIRect)); michael@0: } michael@0: michael@0: bool operator !=(const GrGLIRect& glRect) const {return !(*this == glRect);} michael@0: }; michael@0: michael@0: #endif