1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLIRect.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* 1.5 + * Copyright 2011 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 + 1.12 + 1.13 +#ifndef GrGLIRect_DEFINED 1.14 +#define GrGLIRect_DEFINED 1.15 + 1.16 +#include "gl/GrGLInterface.h" 1.17 +#include "GrGLUtil.h" 1.18 + 1.19 +/** 1.20 + * Helper struct for dealing with the fact that Ganesh and GL use different 1.21 + * window coordinate systems (top-down vs bottom-up) 1.22 + */ 1.23 +struct GrGLIRect { 1.24 + GrGLint fLeft; 1.25 + GrGLint fBottom; 1.26 + GrGLsizei fWidth; 1.27 + GrGLsizei fHeight; 1.28 + 1.29 + void pushToGLViewport(const GrGLInterface* gl) const { 1.30 + GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight)); 1.31 + } 1.32 + 1.33 + void pushToGLScissor(const GrGLInterface* gl) const { 1.34 + GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight)); 1.35 + } 1.36 + 1.37 + void setFromGLViewport(const GrGLInterface* gl) { 1.38 + GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint)); 1.39 + GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) this); 1.40 + } 1.41 + 1.42 + // sometimes we have a SkIRect from the client that we 1.43 + // want to simultaneously make relative to GL's viewport 1.44 + // and (optionally) convert from top-down to bottom-up. 1.45 + void setRelativeTo(const GrGLIRect& glRect, 1.46 + int leftOffset, 1.47 + int topOffset, 1.48 + int width, 1.49 + int height, 1.50 + GrSurfaceOrigin origin) { 1.51 + fLeft = glRect.fLeft + leftOffset; 1.52 + fWidth = width; 1.53 + if (kBottomLeft_GrSurfaceOrigin == origin) { 1.54 + fBottom = glRect.fBottom + (glRect.fHeight - topOffset - height); 1.55 + } else { 1.56 + fBottom = glRect.fBottom + topOffset; 1.57 + } 1.58 + fHeight = height; 1.59 + 1.60 + SkASSERT(fLeft >= 0); 1.61 + SkASSERT(fWidth >= 0); 1.62 + SkASSERT(fBottom >= 0); 1.63 + SkASSERT(fHeight >= 0); 1.64 + } 1.65 + 1.66 + bool contains(const GrGLIRect& glRect) const { 1.67 + return fLeft <= glRect.fLeft && 1.68 + fBottom <= glRect.fBottom && 1.69 + fLeft + fWidth >= glRect.fLeft + glRect.fWidth && 1.70 + fBottom + fHeight >= glRect.fBottom + glRect.fHeight; 1.71 + } 1.72 + 1.73 + void invalidate() {fLeft = fWidth = fBottom = fHeight = -1;} 1.74 + 1.75 + bool operator ==(const GrGLIRect& glRect) const { 1.76 + return 0 == memcmp(this, &glRect, sizeof(GrGLIRect)); 1.77 + } 1.78 + 1.79 + bool operator !=(const GrGLIRect& glRect) const {return !(*this == glRect);} 1.80 +}; 1.81 + 1.82 +#endif