Hide alloc size vs content size below API
Remove old gl shaders class
Move texture matrix to sampler class

git-svn-id: http://skia.googlecode.com/svn/trunk@808 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp
index 8d00af9..ba13372 100644
--- a/gpu/src/GrGpuGL.cpp
+++ b/gpu/src/GrGpuGL.cpp
@@ -49,6 +49,58 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
+void GrGpuGL::AdjustTextureMatrix(const GrGLTexture* texture, 
+                                  GrSamplerState::SampleMode mode, 
+                                  GrMatrix* matrix) {
+    GrAssert(NULL != texture);
+    GrAssert(NULL != matrix);
+    if (GR_Scalar1 != texture->contentScaleX() ||
+        GR_Scalar1 != texture->contentScaleY()) {
+        if (GrSamplerState::kRadial_SampleMode == mode) {
+            GrMatrix scale;
+            scale.setScale(texture->contentScaleX(), texture->contentScaleX());
+            matrix->postConcat(scale);
+        } else if (GrSamplerState::kNormal_SampleMode == mode) {
+            GrMatrix scale;
+            scale.setScale(texture->contentScaleX(), texture->contentScaleY());
+            matrix->postConcat(scale);
+        } else {
+            GrPrintf("We haven't handled NPOT adjustment for other sample modes!");
+        }
+    }
+    GrGLTexture::Orientation orientation = texture->orientation();
+    if (GrGLTexture::kBottomUp_Orientation == orientation) {
+        GrMatrix invY;
+        invY.setAll(GR_Scalar1, 0,           0,
+                    0,          -GR_Scalar1, GR_Scalar1,
+                    0,          0,           GrMatrix::I()[8]);
+        matrix->postConcat(invY);
+    } else {
+        GrAssert(GrGLTexture::kTopDown_Orientation == orientation);
+    }
+}
+
+bool GrGpuGL::TextureMatrixIsIdentity(const GrGLTexture* texture, 
+                                      const GrSamplerState& sampler) {
+    GrAssert(NULL != texture);
+    if (!sampler.getMatrix().isIdentity()) {
+        return false;
+    }
+    if (GR_Scalar1 != texture->contentScaleX() ||
+        GR_Scalar1 != texture->contentScaleY()) {
+        return false;
+    }
+    GrGLTexture::Orientation orientation = texture->orientation();
+    if (GrGLTexture::kBottomUp_Orientation == orientation) {
+        return false;
+    } else {
+        GrAssert(GrGLTexture::kTopDown_Orientation == orientation);
+    }
+    return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
 static bool gPrintStartupSpew;
 
 
@@ -102,8 +154,7 @@
 
     resetContextHelper();
 
-    fHWDrawState.fRenderTarget = NULL;
-    fRenderTargetChanged = true;
+    resetDirtyFlags();
 
     GLint maxTextureUnits;
     // check FS and fixed-function texture unit limits
@@ -265,6 +316,7 @@
         fNPOTTextureTileSupport = false;
     }
 #endif
+
     ////////////////////////////////////////////////////////////////////////////
     // Experiments to determine limitations that can't be queried. TODO: Make
     // these a preprocess that generate some compile time constants.
@@ -395,14 +447,15 @@
     fHWDrawState.fDstBlend = (BlendCoeff)-1;
     fHWDrawState.fColor = GrColor_ILLEGAL;
 
-    fHWDrawState.fViewMatrix.setScale(GR_ScalarMax, GR_ScalarMax); // illegal
+    fHWDrawState.fViewMatrix = GrMatrix::InvalidMatrix();
 
     for (int s = 0; s < kNumStages; ++s) {
         fHWDrawState.fTextures[s] = NULL;
         fHWDrawState.fSamplerStates[s].setRadial2Params(-GR_ScalarMax,
                                                         -GR_ScalarMax,
                                                         true);
-        fHWDrawState.fTextureMatrices[s].setScale(GR_ScalarMax, GR_ScalarMax);
+        
+        fHWDrawState.fSamplerStates[s].setMatrix(GrMatrix::InvalidMatrix());
     }
 
     GR_GL(Scissor(0,0,0,0));
@@ -1017,7 +1070,7 @@
                      GrColorUnpackB(color)/255.f,
                      GrColorUnpackA(color)/255.f));
     GR_GL(Clear(GL_COLOR_BUFFER_BIT));
-    fWriteMaskChanged = true;
+    fDirtyFlags.fWriteMaskChanged = true;
 }
 
 void GrGpuGL::eraseStencil(uint32_t value, uint32_t mask) {
@@ -1032,7 +1085,7 @@
     GR_GL(StencilMask(mask));
     GR_GL(ClearStencil(value));
     GR_GL(Clear(GL_STENCIL_BUFFER_BIT));
-    fWriteMaskChanged = true;
+    fDirtyFlags.fWriteMaskChanged = true;
 }
 
 void GrGpuGL::eraseStencilClip() {
@@ -1107,7 +1160,7 @@
     #endif
         fHWDrawState.fRenderTarget = fCurrDrawState.fRenderTarget;
         const GrIRect& vp = rt->viewport();
-        fRenderTargetChanged = true;
+        fDirtyFlags.fRenderTargetChanged = true;
         if (fHWBounds.fViewportRect != vp) {
             GR_GL(Viewport(vp.fLeft,
                            vp.fBottom,
@@ -1181,10 +1234,10 @@
         fHWDrawState.fRenderTarget = NULL;
 
         GLint left = 0;
-        GLint right = texture->contentWidth();
+        GLint right = texture->width();
         // we will have rendered to the top of the FBO.
         GLint top = texture->allocHeight();
-        GLint bottom = texture->allocHeight() - texture->contentHeight();
+        GLint bottom = texture->allocHeight() - texture->height();
         if (kApple_MSFBO == fMSFBOType) {
             GR_GL(Enable(GL_SCISSOR_TEST));
             GR_GL(Scissor(left, bottom, right-left, top-bottom));
@@ -1208,7 +1261,7 @@
     bool stencilClip = fClipState.fClipInStencil &&
                        (kClip_StateBit & fCurrDrawState.fFlagBits);
     bool stencilChange =
-        fWriteMaskChanged                                         ||
+        fDirtyFlags.fWriteMaskChanged                             ||
         fHWStencilClip != stencilClip                             ||
         fHWDrawState.fStencilPass != fCurrDrawState.fStencilPass  ||
         (kNone_StencilPass != fCurrDrawState.fStencilPass &&
@@ -1399,7 +1452,6 @@
         }
         fHWDrawState.fStencilPass = fCurrDrawState.fStencilPass;
         fHWDrawState.fReverseFill = fCurrDrawState.fReverseFill;
-        fWriteMaskChanged = false;
         fHWStencilClip = stencilClip;
     }
 }
@@ -1468,6 +1520,10 @@
                                         newTexParams.fWrapT));
                 }
                 nextTexture->setTexParams(newTexParams);
+
+                // The texture matrix has to compensate for texture width/height
+                // and NPOT-embedded-in-POT
+                fDirtyFlags.fTextureChangedMask |= (1 << s);
             } else {
                 GrAssert(!"Rendering with texture vert flag set but no texture");
                 return false;
@@ -1489,7 +1545,7 @@
 #if GR_SUPPORT_GLDESKTOP
     // ES doesn't support toggling GL_MULTISAMPLE and doesn't have
     // smooth lines.
-    if (fRenderTargetChanged ||
+    if (fDirtyFlags.fRenderTargetChanged ||
         (fCurrDrawState.fFlagBits & kAntialias_StateBit) !=
         (fHWDrawState.fFlagBits & kAntialias_StateBit)) {
         GLint msaa = 0;
@@ -1712,6 +1768,10 @@
     }
 }
 
+void GrGpuGL::resetDirtyFlags() {
+    Gr_bzero(&fDirtyFlags, sizeof(fDirtyFlags));
+}
+
 void GrGpuGL::setBuffers(bool indexed,
                          int* extraVertexOffset,
                          int* extraIndexOffset) {