Adds ability to draw rects using a unit square vertex buffer. Useful when matrix/uniform changes are less expensive than sending new verts.
Adds optional matrix parameters to GrContext drawRect and drawRectToRect so that non-axis-aligned matrices can be drawn using these functions.
codereview Issue 4105049
git-svn-id: http://skia.googlecode.com/svn/trunk@749 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h
index 862559e..e7f37f1 100644
--- a/gpu/include/GrDrawTarget.h
+++ b/gpu/include/GrDrawTarget.h
@@ -238,7 +238,7 @@
* requirements. The texture matrix is applied both when the texture
* coordinates are explicit and when vertex positions are used as texture
* coordinates. In the latter case the texture matrix is applied to the
- * pre-modelview position values.
+ * pre-view-matrix position values.
*
* @param stage the stage for which to set a matrix.
* @param m the matrix used to transform the texture coordinates.
@@ -246,6 +246,25 @@
void setTextureMatrix(int stage, const GrMatrix& m);
/**
+ * Multiplies the current texture matrix for a stage by a matrix
+ *
+ * After this call T' = T*m where T is the old tex matrix,
+ * m is the parameter to this function, and T' is the new tex matrix.
+ * (We consider positions to be column vectors so tex cood vector t is
+ * transformed by matrix X as t' = X*t.)
+ *
+ * @param m the matrix used to modify the texture matrix matrix.
+ */
+ void concatTextureMatrix(int stage, const GrMatrix& m);
+
+ /**
+ * Retrieves the current texture matrix for a stage
+ * @param stage index of stage
+ * @return the stage's current texture matrix.
+ */
+ const GrMatrix& getTextureMatrix(int stage) const;
+
+ /**
* Sets the matrix applied to veretx positions.
*
* In the post-view-matrix space the rectangle [0,w]x[0,h]
@@ -264,11 +283,28 @@
* (We consider positions to be column vectors so position vector p is
* transformed by matrix X as p' = X*p.)
*
- * @param m the matrix used to modify the modelview matrix.
+ * @param m the matrix used to modify the view matrix.
*/
void concatViewMatrix(const GrMatrix& m);
/**
+ * Retrieves the current view matrix
+ * @return the current view matrix.
+ */
+ const GrMatrix& getViewMatrix() const;
+
+ /**
+ * Retrieves the inverse of the current view matrix.
+ *
+ * If the current view matrix is invertible, return true, and if matrix
+ * is non-null, copy the inverse into it. If the current view matrix is
+ * non-invertible, return false and ignore the matrix parameter.
+ *
+ * @param matrix if not null, will receive a copy of the current inverse.
+ */
+ bool getViewInverse(GrMatrix* matrix) const;
+
+ /**
* Sets color for next draw to a premultiplied-alpha color.
*
* @param the color to set.
@@ -332,23 +368,6 @@
void setBlendFunc(BlendCoeff srcCoef, BlendCoeff dstCoef);
/**
- * Retrieves the current view matrix
- * return the current view matrix.
- */
- const GrMatrix& getViewMatrix() const;
-
- /**
- * Retrieves the inverse of the current view matrix.
- *
- * If the current view matrix is invertible, return true, and if matrix
- * is non-null, copy the inverse into it. If the current view matrix is
- * non-invertible, return false and ignore the matrix parameter.
- *
- * @param matrix if not null, will receive a copy of the current inverse.
- */
- bool getViewInverse(GrMatrix* matrix) const;
-
- /**
* Used to save and restore the GrGpu's drawing state
*/
struct SavedDrawState {
@@ -612,6 +631,39 @@
};
///////////////////////////////////////////////////////////////////////////
+
+ class AutoViewMatrixRestore : ::GrNoncopyable {
+ public:
+ AutoViewMatrixRestore() {
+ fDrawTarget = NULL;
+ }
+
+ AutoViewMatrixRestore(GrDrawTarget* target)
+ : fDrawTarget(target), fMatrix(fDrawTarget->getViewMatrix()) {
+ GrAssert(NULL != target);
+ }
+
+ void set(GrDrawTarget* target) {
+ GrAssert(NULL != target);
+ if (NULL != fDrawTarget) {
+ fDrawTarget->setViewMatrix(fMatrix);
+ }
+ fDrawTarget = target;
+ fMatrix = target->getViewMatrix();
+ }
+
+ ~AutoViewMatrixRestore() {
+ if (NULL != fDrawTarget) {
+ fDrawTarget->setViewMatrix(fMatrix);
+ }
+ }
+
+ private:
+ GrDrawTarget* fDrawTarget;
+ GrMatrix fMatrix;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
class AutoReleaseGeometry : ::GrNoncopyable {
public: