| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef GrGLIRect_DEFINED | 10 #ifndef GrGLIRect_DEFINED |
| 11 #define GrGLIRect_DEFINED | 11 #define GrGLIRect_DEFINED |
| 12 | 12 |
| 13 #include "gl/GrGLInterface.h" | 13 #include "gl/GrGLInterface.h" |
| 14 #include "GrGLUtil.h" | 14 #include "GrGLUtil.h" |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Helper struct for dealing with the fact that Ganesh and GL use different | 17 * Helper struct for dealing with the fact that Ganesh and GL use different |
| 18 * window coordinate systems (top-down vs bottom-up) | 18 * window coordinate systems (top-down vs bottom-up) |
| 19 */ | 19 */ |
| 20 struct GrGLIRect { | 20 struct GrGLIRect { |
| 21 GrGLint fLeft; | 21 GrGLint fLeft; |
| 22 GrGLint fBottom; | 22 GrGLint fBottom; |
| 23 GrGLsizei fWidth; | 23 GrGLsizei fWidth; |
| 24 GrGLsizei fHeight; | 24 GrGLsizei fHeight; |
| 25 | 25 |
| 26 /** |
| 27 * cast-safe way to treat the rect as an array of (4) ints. |
| 28 */ |
| 29 const int* asInts() const { |
| 30 return &fLeft; |
| 31 |
| 32 GR_STATIC_ASSERT(0 == offsetof(GrGLIRect, fLeft)); |
| 33 GR_STATIC_ASSERT(4 == offsetof(GrGLIRect, fBottom)); |
| 34 GR_STATIC_ASSERT(8 == offsetof(GrGLIRect, fWidth)); |
| 35 GR_STATIC_ASSERT(12 == offsetof(GrGLIRect, fHeight)); |
| 36 GR_STATIC_ASSERT(16 == sizeof(GrGLIRect)); // For an array of GrGLIRect. |
| 37 } |
| 38 int* asInts() { return &fLeft; } |
| 39 |
| 26 void pushToGLViewport(const GrGLInterface* gl) const { | 40 void pushToGLViewport(const GrGLInterface* gl) const { |
| 27 GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight)); | 41 GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight)); |
| 28 } | 42 } |
| 29 | 43 |
| 30 void pushToGLScissor(const GrGLInterface* gl) const { | 44 void pushToGLScissor(const GrGLInterface* gl) const { |
| 31 GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight)); | 45 GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight)); |
| 32 } | 46 } |
| 33 | 47 |
| 34 void setFromGLViewport(const GrGLInterface* gl) { | 48 void setFromGLViewport(const GrGLInterface* gl) { |
| 35 GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint)); | 49 GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint)); |
| 36 GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) this); | 50 GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) this); |
| 37 } | 51 } |
| 38 | 52 |
| 39 // sometimes we have a SkIRect from the client that we | 53 // sometimes we have a SkIRect from the client that we |
| 40 // want to simultaneously make relative to GL's viewport | 54 // want to simultaneously make relative to GL's viewport |
| 41 // and (optionally) convert from top-down to bottom-up. | 55 // and (optionally) convert from top-down to bottom-up. |
| 56 void setRelativeTo(const GrGLIRect& glViewport, const SkIRect& devRect, GrSu
rfaceOrigin org) { |
| 57 this->setRelativeTo(glViewport, devRect.x(), devRect.y(), devRect.width(
), devRect.height(), |
| 58 org); |
| 59 } |
| 60 |
| 42 void setRelativeTo(const GrGLIRect& glRect, | 61 void setRelativeTo(const GrGLIRect& glRect, |
| 43 int leftOffset, | 62 int leftOffset, |
| 44 int topOffset, | 63 int topOffset, |
| 45 int width, | 64 int width, |
| 46 int height, | 65 int height, |
| 47 GrSurfaceOrigin origin) { | 66 GrSurfaceOrigin origin) { |
| 48 fLeft = glRect.fLeft + leftOffset; | 67 fLeft = glRect.fLeft + leftOffset; |
| 49 fWidth = width; | 68 fWidth = width; |
| 50 if (kBottomLeft_GrSurfaceOrigin == origin) { | 69 if (kBottomLeft_GrSurfaceOrigin == origin) { |
| 51 fBottom = glRect.fBottom + (glRect.fHeight - topOffset - height); | 70 fBottom = glRect.fBottom + (glRect.fHeight - topOffset - height); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 68 void invalidate() {fLeft = fWidth = fBottom = fHeight = -1;} | 87 void invalidate() {fLeft = fWidth = fBottom = fHeight = -1;} |
| 69 | 88 |
| 70 bool operator ==(const GrGLIRect& glRect) const { | 89 bool operator ==(const GrGLIRect& glRect) const { |
| 71 return 0 == memcmp(this, &glRect, sizeof(GrGLIRect)); | 90 return 0 == memcmp(this, &glRect, sizeof(GrGLIRect)); |
| 72 } | 91 } |
| 73 | 92 |
| 74 bool operator !=(const GrGLIRect& glRect) const {return !(*this == glRect);} | 93 bool operator !=(const GrGLIRect& glRect) const {return !(*this == glRect);} |
| 75 }; | 94 }; |
| 76 | 95 |
| 77 #endif | 96 #endif |
| OLD | NEW |