Make the orientation of a texture accessible from and known by GrSurface.

R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6801044

git-svn-id: http://skia.googlecode.com/svn/branches/gpu_dev@6148 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 324fdc1..35867c2 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -83,7 +83,7 @@
         fEffects[s] = NULL;
         fTextureMatrices[s] = GrMatrix::InvalidMatrix();
         // this is arbitrary, just initialize to something
-        fTextureOrientation[s] = GrGLTexture::kBottomUp_Orientation;
+        fTextureOrigin[s] = GrSurface::kBottomLeft_Origin;
     }
 
     this->genProgram(effects);
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 8adcd62..5fad7cc 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -248,10 +248,9 @@
     GrColor                     fCoverage;
     GrColor                     fColorFilterColor;
     int                         fRTHeight;
-    /// When it is sent to GL, the texture matrix will be flipped if the texture orientation
-    /// (below) requires.
+    /// When it is sent to GL, the texture matrix will be flipped if the texture origin requires.
     GrMatrix                    fTextureMatrices[GrDrawState::kNumStages];
-    GrGLTexture::Orientation    fTextureOrientation[GrDrawState::kNumStages];
+    GrSurface::Origin           fTextureOrigin[GrDrawState::kNumStages];
 
     GrGLEffect*                 fEffects[GrDrawState::kNumStages];
 
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 3e72757..9bbc842 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -49,7 +49,9 @@
                 texture,
                 MakeDesc(kNone_GrTextureFlags,
                          viewport.fWidth, viewport.fHeight,
-                         desc.fConfig, desc.fSampleCnt)) {
+                         desc.fConfig, desc.fSampleCnt),
+                texture->origin()) {
+    GrAssert(kBottomLeft_Origin == texture->origin());
     GrAssert(NULL != texID);
     GrAssert(NULL != texture);
     // FBO 0 can't also be a texture, right?
@@ -70,7 +72,8 @@
                 NULL,
                 MakeDesc(kNone_GrTextureFlags,
                          viewport.fWidth, viewport.fHeight,
-                         desc.fConfig, desc.fSampleCnt)) {
+                         desc.fConfig, desc.fSampleCnt),
+                kBottomLeft_Origin) {
     this->init(desc, viewport, NULL);
 }
 
diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index 64b0d21..11a877f 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -51,7 +51,7 @@
     const GrGLIRect& getViewport() const { return fViewport; }
 
     // The following two functions return the same ID when a
-    // texture-rendertarget is multisampled, and different IDs when
+    // texture/render target is multisampled, and different IDs when
     // it is.
     // FBO ID used to render into
     GrGLuint renderFBOID() const { return fRTFBOID; }
@@ -93,7 +93,7 @@
     // else own them.
     bool        fOwnIDs;
 
-    // when we switch to this rendertarget we want to set the viewport to
+    // when we switch to this render target we want to set the viewport to
     // only render to to content area (as opposed to the whole allocation) and
     // we want the rendering to be at top left (GL has origin in bottom left)
     GrGLIRect fViewport;
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 0aa4884..c1821b2 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -26,10 +26,9 @@
                                      (GPUGL->glInterface(),
                                       textureDesc.fTextureID,
                                       textureDesc.fOwnsID));
-    fOrientation        = textureDesc.fOrientation;
-
+    
     if (NULL != rtDesc) {
-        // we render to the top left
+        GrAssert(kBottomLeft_Origin == textureDesc.fOrigin);
         GrGLIRect vp;
         vp.fLeft   = 0;
         vp.fWidth  = textureDesc.fWidth;
@@ -43,14 +42,14 @@
 
 GrGLTexture::GrGLTexture(GrGpuGL* gpu,
                          const Desc& textureDesc)
-    : INHERITED(gpu, textureDesc) {
+    : INHERITED(gpu, textureDesc, textureDesc.fOrigin) {
     this->init(gpu, textureDesc, NULL);
 }
 
 GrGLTexture::GrGLTexture(GrGpuGL* gpu,
                          const Desc& textureDesc,
                          const GrGLRenderTarget::Desc& rtDesc)
-    : INHERITED(gpu, textureDesc) {
+    : INHERITED(gpu, textureDesc, textureDesc.fOrigin) {
     this->init(gpu, textureDesc, &rtDesc);
 }
 
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index a2e4af2..4666bfb 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -48,11 +48,6 @@
 class GrGLTexture : public GrTexture {
 
 public:
-    enum Orientation {
-        kBottomUp_Orientation,
-        kTopDown_Orientation,
-    };
-
     struct TexParams {
         GrGLenum fFilter;
         GrGLenum fWrapS;
@@ -64,7 +59,7 @@
     struct Desc : public GrTextureDesc {
         GrGLuint        fTextureID;
         bool            fOwnsID;
-        Orientation     fOrientation;
+        Origin          fOrigin;
     };
 
     // creates a texture that is also an RT
@@ -95,16 +90,6 @@
     }
     GrGLuint textureID() const { return fTexIDObj->id(); }
 
-    // Ganesh assumes texture coordinates have their origin
-    // in the top-left corner of the image. OpenGL, however,
-    // has the origin in the lower-left corner. For content that
-    // is loaded by Ganesh we just push the content "upside down"
-    // (by GL's understanding of the world) in glTex*Image and the
-    // addressing just works out. However, content generated by GL
-    // (FBO or externally imported texture) will be updside down
-    // and it is up to the GrGpuGL derivative to handle y-mirroing.
-    Orientation orientation() const { return fOrientation; }
-
 protected:
 
     // overrides of GrTexture
@@ -115,7 +100,6 @@
     TexParams                       fTexParams;
     GrGpu::ResetTimestamp           fTexParamsTimestamp;
     GrGLTexID*                      fTexIDObj;
-    Orientation                     fOrientation;
 
     void init(GrGpuGL* gpu,
               const Desc& textureDesc,
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 04d0f8e..28963f1 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -490,7 +490,7 @@
     glTexDesc.fSampleCnt = desc.fSampleCnt;
     glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle);
     glTexDesc.fOwnsID = false;
-    glTexDesc.fOrientation = GrGLTexture::kBottomUp_Orientation;
+    glTexDesc.fOrigin = GrSurface::kBottomLeft_Origin;
 
     GrGLTexture* texture = NULL;
     if (desc.fFlags & kRenderTarget_GrBackendTextureFlag) {
@@ -574,7 +574,7 @@
     desc.fConfig = glTex->config();
     desc.fSampleCnt = glTex->desc().fSampleCnt;
     desc.fTextureID = glTex->textureID();
-    desc.fOrientation = glTex->orientation();
+    desc.fOrigin = glTex->origin();
 
     this->uploadTexData(desc, false,
                         left, top, width, height,
@@ -665,7 +665,7 @@
     bool swFlipY = false;
     bool glFlipY = false;
     if (NULL != data) {
-        if (GrGLTexture::kBottomUp_Orientation == desc.fOrientation) {
+        if (GrSurface::kBottomLeft_Origin == desc.fOrigin) {
             if (this->glCaps().unpackFlipYSupport()) {
                 glFlipY = true;
             } else {
@@ -948,8 +948,7 @@
     // We keep GrRenderTargets in GL's normal orientation so that they
     // can be drawn to by the outside world without the client having
     // to render upside down.
-    glTexDesc.fOrientation = renderTarget ? GrGLTexture::kBottomUp_Orientation :
-                                            GrGLTexture::kTopDown_Orientation;
+    glTexDesc.fOrigin = renderTarget ? GrSurface::kBottomLeft_Origin : GrSurface::kTopLeft_Origin;
 
     glRTDesc.fSampleCnt = desc.fSampleCnt;
     if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() &&
diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h
index 4985d99..466c4a7 100644
--- a/src/gpu/gl/GrGpuGL.h
+++ b/src/gpu/gl/GrGpuGL.h
@@ -146,8 +146,7 @@
     const GrGLContextInfo& glContextInfo() const { return fGLContextInfo; }
 
     // adjusts texture matrix to account for orientation
-    static void AdjustTextureMatrix(const GrGLTexture* texture,
-                                    GrMatrix* matrix);
+    static void AdjustTextureMatrix(const GrTexture* texture, GrMatrix* matrix);
 
     // This helper determines if what optimizations can be applied to the matrix after any coord
     // adjustments are applied. The return is a bitfield of GrGLProgram::StageDesc::OptFlags.
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index 3be5afc..ba36abe 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -161,19 +161,15 @@
 
 // helpers for texture matrices
 
-void GrGpuGL::AdjustTextureMatrix(const GrGLTexture* texture,
-                                  GrMatrix* matrix) {
+void GrGpuGL::AdjustTextureMatrix(const GrTexture* texture, GrMatrix* matrix) {
     GrAssert(NULL != texture);
     GrAssert(NULL != matrix);
-    GrGLTexture::Orientation orientation = texture->orientation();
-    if (GrGLTexture::kBottomUp_Orientation == orientation) {
+    if (GrSurface::kBottomLeft_Origin == texture->origin()) {
         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);
     }
 }
 
@@ -183,7 +179,7 @@
     GrMatrix matrix;
     stage.getTotalMatrix(&matrix);
 
-    bool canBeIndentity = GrGLTexture::kTopDown_Orientation == texture->orientation();
+    bool canBeIndentity = GrSurface::kTopLeft_Origin == texture->origin();
 
     if (canBeIndentity && matrix.isIdentity()) {
         return GrGLProgram::StageDesc::kIdentityMatrix_OptFlagBit;
@@ -206,8 +202,7 @@
     const GrGLTexture* texture = static_cast<const GrGLTexture*>(effect->texture(0));
     if (NULL != texture) {
 
-        bool orientationChange = fCurrentProgram->fTextureOrientation[s] !=
-                                 texture->orientation();
+        bool originChange = fCurrentProgram->fTextureOrigin[s] != texture->origin();
 
         UniformHandle matrixUni = fCurrentProgram->fUniforms.fStages[s].fTextureMatrixUni;
 
@@ -216,7 +211,7 @@
         drawState.getStage(s).getTotalMatrix(&samplerMatrix);
 
         if (kInvalidUniformHandle != matrixUni &&
-            (orientationChange || !hwMatrix.cheapEqualTo(samplerMatrix))) {
+            (originChange || !hwMatrix.cheapEqualTo(samplerMatrix))) {
 
             GrMatrix m = samplerMatrix;
             AdjustTextureMatrix(texture, &m);
@@ -239,7 +234,7 @@
             fCurrentProgram->fTextureMatrices[s] = samplerMatrix;
         }
 
-        fCurrentProgram->fTextureOrientation[s] = texture->orientation();
+        fCurrentProgram->fTextureOrigin[s] = texture->origin();
     }
 }