From d38f137e9b813f8193675ebd3dfbfe8bc42639e9 Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Wed, 12 Oct 2011 19:53:16 +0000 Subject: Move gpu/include/* to include/gpu and gpu/src/* to src/gpu Review URL: http://codereview.appspot.com/5250070/ git-svn-id: http://skia.googlecode.com/svn/trunk@2471 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrGLIRect.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/gpu/GrGLIRect.h (limited to 'src/gpu/GrGLIRect.h') diff --git a/src/gpu/GrGLIRect.h b/src/gpu/GrGLIRect.h new file mode 100644 index 0000000000..e94fa21a5a --- /dev/null +++ b/src/gpu/GrGLIRect.h @@ -0,0 +1,74 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + + +#ifndef GrGLIRect_DEFINED +#define GrGLIRect_DEFINED + +#include "GrGLInterface.h" + +/** + * Helper struct for dealing with the fact that Ganesh and GL use different + * window coordinate systems (top-down vs bottom-up) + */ +struct GrGLIRect { + GrGLint fLeft; + GrGLint fBottom; + GrGLsizei fWidth; + GrGLsizei fHeight; + + void pushToGLViewport(const GrGLInterface* gl) const { + GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight)); + } + + void pushToGLScissor(const GrGLInterface* gl) const { + GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight)); + } + + void setFromGLViewport(const GrGLInterface* gl) { + GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint)); + GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) 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 -- cgit v1.2.3