Add an origin flag for backend (external) textures. Some textures in WebKit have...
authorsenorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 28 Jan 2013 16:42:38 +0000 (16:42 +0000)
committersenorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 28 Jan 2013 16:42:38 +0000 (16:42 +0000)
Review URL: https://codereview.appspot.com/7200048

git-svn-id: http://skia.googlecode.com/svn/trunk@7414 2bbb7eff-a529-9590-31e7-b0007b416f81

13 files changed:
include/gpu/GrRenderTarget.h
include/gpu/GrSurface.h
include/gpu/GrTexture.h
include/gpu/GrTypes.h
src/effects/SkDisplacementMapEffect.cpp
src/effects/SkLightingImageFilter.cpp
src/effects/SkMatrixConvolutionImageFilter.cpp
src/gpu/effects/GrTextureDomainEffect.cpp
src/gpu/gl/GrGLEffectMatrix.cpp
src/gpu/gl/GrGLRenderTarget.cpp
src/gpu/gl/GrGLTexture.cpp
src/gpu/gl/GrGLTexture.h
src/gpu/gl/GrGpuGL.cpp

index 4e77466b9afc6aa6d0acaff1a3f658005ea18d42..19a37a5d8b766e5717a3ef59a2693e257fc38bb9 100644 (file)
@@ -142,7 +142,7 @@ protected:
                    bool isWrapped,
                    GrTexture* texture,
                    const GrTextureDesc& desc,
-                   Origin origin)
+                   GrSurfaceOrigin origin)
         : INHERITED(gpu, isWrapped, desc, origin)
         , fStencilBuffer(NULL)
         , fTexture(texture) {
index 4ef0acb82e166938cb3067d7e65e2e5c7bee4b7b..8ccbc9833bc7b6300e027d762dbf3539bb374fa5 100644 (file)
@@ -33,19 +33,8 @@ public:
      */
     int height() const { return fDesc.fHeight; }
 
-    /**
-     * Some surfaces will be stored such that the upper and left edges of the content meet at the
-     * the origin (in texture coord space) and for other surfaces the lower and left edges meet at
-     * the origin. Render-targets are always consistent with the convention of the underlying
-     * backend API to make it easier to mix native backend rendering with Skia rendering. Wrapped
-     * backend surfaces always use the backend's convention as well.
-     */
-    enum Origin {
-        kTopLeft_Origin,
-        kBottomLeft_Origin,
-    };
-    Origin origin() const {
-        GrAssert(kTopLeft_Origin == fOrigin || kBottomLeft_Origin == fOrigin);
+    GrSurfaceOrigin origin() const {
+        GrAssert(kTopLeft_SurfaceOrigin == fOrigin || kBottomLeft_SurfaceOrigin == fOrigin);
         return fOrigin;
     }
 
@@ -115,7 +104,7 @@ public:
                              uint32_t pixelOpsFlags = 0) = 0;
 
 protected:
-    GrSurface(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc, Origin origin)
+    GrSurface(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc, GrSurfaceOrigin origin)
     : INHERITED(gpu, isWrapped)
     , fDesc(desc)
     , fOrigin(origin) {
@@ -124,7 +113,7 @@ protected:
     GrTextureDesc fDesc;
 
 private:
-    Origin fOrigin;
+    GrSurfaceOrigin fOrigin;
 
     typedef GrResource INHERITED;
 };
index 657e6e507802d4257d784538d4760e4045f273ab..94d578894b975b32b6c2c9948cf0b1a1f37cd22a 100644 (file)
@@ -140,7 +140,7 @@ protected:
                                    // base class cons sets to NULL
                                    // subclass cons can create and set
 
-    GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc, Origin origin)
+    GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc, GrSurfaceOrigin origin)
     : INHERITED(gpu, isWrapped, desc, origin)
     , fRenderTarget(NULL) {
 
index d7241b499ca30cf8a06cab65d3d3816bea6cb1c9..055750dd118bd1ac44f30cabf43d395607ff6e0f 100644 (file)
@@ -425,6 +425,17 @@ enum {
     kGrColorTableSize = 256 * 4 //sizeof(GrColor)
 };
 
+/**
+ * Some textures will be stored such that the upper and left edges of the content meet at the
+ * the origin (in texture coord space) and for other textures the lower and left edges meet at
+ * the origin. Render-targets are always consistent with the convention of the underlying
+ * backend API to make it easier to mix native backend rendering with Skia rendering.
+ */
+
+enum GrSurfaceOrigin {
+    kBottomLeft_GrSurfaceOrigin,
+    kTopLeft_GrSurfaceOrigin,
+};
 
 /**
  * Describes a texture to be created.
@@ -596,6 +607,7 @@ GR_MAKE_BITFIELD_OPS(GrBackendTextureFlags)
 struct GrBackendTextureDesc {
     GrBackendTextureDesc() { memset(this, 0, sizeof(*this)); }
     GrBackendTextureFlags           fFlags;
+    GrSurfaceOrigin                 fOrigin;
     int                             fWidth;         //<! width in pixels
     int                             fHeight;        //<! height in pixels
     GrPixelConfig                   fConfig;        //<! color format
index 0fef7c60c48fac091aa3c6eee16ff938f23c24bc..aeb47dc5c374fa23628647fe28236804b857f502 100644 (file)
@@ -516,7 +516,7 @@ void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, const Gr
                                colorTex);
 
     uman.set2f(fScaleUni, SkScalarToFloat(displacementMap.scale()),
-                colorTex->origin() == GrSurface::kTopLeft_Origin ?
+                colorTex->origin() == kTopLeft_GrSurfaceOrigin ?
                 SkScalarToFloat(displacementMap.scale()) :
                 SkScalarToFloat(-displacementMap.scale()));
 }
index dd892f91d913fba74307298907ada13c50a08561..498c8e0d17abdf15a937ab61edc3d8ab03d6d530 100644 (file)
@@ -1218,7 +1218,7 @@ GrGLEffect::EffectKey GrGLLightingEffect::GenKey(const GrEffectStage& s,
 void GrGLLightingEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
     const GrLightingEffect& effect = GetEffectFromStage<GrLightingEffect>(stage);
     GrTexture* texture = effect.texture(0);
-    float ySign = texture->origin() == GrSurface::kTopLeft_Origin ? -1.0f : 1.0f;
+    float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
     uman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->height());
     uman.set1f(fSurfaceScaleUni, effect.surfaceScale());
     fLight->setData(uman, effect.light());
index 0c2a24e04dd853b7a2d03eb6812e36aec8654fd4..5a97ec4faec4475ab71df0fed649933a5bbcf95c 100644 (file)
@@ -473,7 +473,7 @@ void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman,
     GrAssert(effect.kernelSize() == fKernelSize);
     GrAssert(effect.tileMode() == fTileMode);
     float imageIncrement[2];
-    float ySign = texture.origin() == GrSurface::kTopLeft_Origin ? 1.0f : -1.0f;
+    float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
     imageIncrement[0] = 1.0f / texture.width();
     imageIncrement[1] = ySign / texture.height();
     uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
index bfd62c2528628b8e0ef3e46e870fc5e8d446f944..833c19803b0ec888fcce9b2ac181f116c42590de 100644 (file)
@@ -90,7 +90,7 @@ void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, const GrEf
         SkScalarToFloat(domain.bottom())
     };
     // vertical flip if necessary
-    if (GrSurface::kBottomLeft_Origin == effect.texture(0)->origin()) {
+    if (kBottomLeft_GrSurfaceOrigin == effect.texture(0)->origin()) {
         values[1] = 1.0f - values[1];
         values[3] = 1.0f - values[3];
         // The top and bottom were just flipped, so correct the ordering
index 6dcb6e609650f9a8c9dcebd2cf587fd83028ccde..5fdde2c394628d4778bfc70c0c680fc72ad64bb5 100644 (file)
@@ -19,7 +19,7 @@ GrGLEffect::EffectKey GrGLEffectMatrix::GenKey(const SkMatrix& effectMatrix,
                                      SkMatrix::kPerspective_Mask;
     int combinedTypes = type0 | type1;
 
-    bool reverseY = (NULL != texture) && GrSurface::kBottomLeft_Origin == texture->origin();
+    bool reverseY = (NULL != texture) && kBottomLeft_GrSurfaceOrigin == texture->origin();
 
     if (SkMatrix::kPerspective_Mask & combinedTypes) {
         return kGeneral_Key;
@@ -173,11 +173,11 @@ void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager,
         case kVoid_GrSLType:
             GrAssert(matrix.isIdentity());
             GrAssert(coordChangeMatrix.isIdentity());
-            GrAssert(NULL == texture || GrSurface::kTopLeft_Origin == texture->origin());
+            GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->origin());
             return;
         case kVec2f_GrSLType: {
             GrAssert(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChangeMatrix.getType()));
-            GrAssert(NULL == texture || GrSurface::kTopLeft_Origin == texture->origin());
+            GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->origin());
             SkScalar tx = matrix[SkMatrix::kMTransX] + coordChangeMatrix[SkMatrix::kMTransX];
             SkScalar ty = matrix[SkMatrix::kMTransY] + coordChangeMatrix[SkMatrix::kMTransY];
             if (fPrevMatrix.get(SkMatrix::kMTransX) != tx ||
@@ -191,7 +191,7 @@ void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager,
         case kMat33f_GrSLType: {
             SkMatrix combined;
             combined.setConcat(matrix, coordChangeMatrix);
-            if (NULL != texture && GrSurface::kBottomLeft_Origin == texture->origin()) {
+            if (NULL != texture && kBottomLeft_GrSurfaceOrigin == texture->origin()) {
                 // combined.postScale(1,-1);
                 // combined.postTranslate(0,1);
                 combined.set(SkMatrix::kMSkewY,
index c68283e64847f379228a79f54eeeb100b3a4e33e..47128e7064b26f442615578e210498953050ced6 100644 (file)
@@ -51,7 +51,7 @@ GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
                          viewport.fWidth, viewport.fHeight,
                          desc.fConfig, desc.fSampleCnt),
                 texture->origin()) {
-    GrAssert(kBottomLeft_Origin == texture->origin());
+    GrAssert(kBottomLeft_GrSurfaceOrigin == texture->origin());
     GrAssert(NULL != texID);
     GrAssert(NULL != texture);
     // FBO 0 can't also be a texture, right?
@@ -74,7 +74,7 @@ GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
                 MakeDesc(kNone_GrTextureFlags,
                          viewport.fWidth, viewport.fHeight,
                          desc.fConfig, desc.fSampleCnt),
-                kBottomLeft_Origin) {
+                kBottomLeft_GrSurfaceOrigin) {
     this->init(desc, viewport, NULL);
 }
 
index 5c588e7f0d9d173b5f27ef9ef93d96fe73c39fe3..3ec555a924d41a840de776c2b81a0145c3ebda45 100644 (file)
@@ -28,7 +28,7 @@ void GrGLTexture::init(GrGpuGL* gpu,
                                       textureDesc.fIsWrapped));
 
     if (NULL != rtDesc) {
-        GrAssert(kBottomLeft_Origin == textureDesc.fOrigin);
+        GrAssert(kBottomLeft_GrSurfaceOrigin == textureDesc.fSurfaceOrigin);
         GrGLIRect vp;
         vp.fLeft   = 0;
         vp.fWidth  = textureDesc.fWidth;
index 527bab0e84aa43b3e0932bb73c625a85740149ae..231482134bc3927013f20205da85e93e5f5b13d1 100644 (file)
@@ -59,7 +59,7 @@ public:
     struct Desc : public GrTextureDesc {
         GrGLuint        fTextureID;
         bool            fIsWrapped;
-        Origin          fOrigin;
+        GrSurfaceOrigin fOrigin;
     };
 
     // creates a texture that is also an RT
index 670f6acfa41d005c91309b1e245f7515ec920d38..a1a5bee5f262087001b8b3a9bfc4535c0bbb9aca 100644 (file)
@@ -485,6 +485,12 @@ GrTexture* GrGpuGL::onWrapBackendTexture(const GrBackendTextureDesc& desc) {
         return NULL;
     }
 
+    // FIXME:  add support for TopLeft RT's by flipping all draws.
+    if (desc.fFlags & kRenderTarget_GrBackendTextureFlag &&
+        kBottomLeft_GrSurfaceOrigin != desc.fOrigin) {
+        return NULL;
+    }
+
     int maxSize = this->getCaps().maxTextureSize();
     if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
         return NULL;
@@ -499,7 +505,7 @@ GrTexture* GrGpuGL::onWrapBackendTexture(const GrBackendTextureDesc& desc) {
     glTexDesc.fSampleCnt = desc.fSampleCnt;
     glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle);
     glTexDesc.fIsWrapped = true;
-    glTexDesc.fOrigin = GrSurface::kBottomLeft_Origin;
+    glTexDesc.fOrigin = desc.fOrigin;
 
     GrGLTexture* texture = NULL;
     if (desc.fFlags & kRenderTarget_GrBackendTextureFlag) {
@@ -675,7 +681,7 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
     bool swFlipY = false;
     bool glFlipY = false;
     if (NULL != data) {
-        if (GrSurface::kBottomLeft_Origin == desc.fOrigin) {
+        if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
             if (this->glCaps().unpackFlipYSupport()) {
                 glFlipY = true;
             } else {
@@ -957,7 +963,7 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
     // 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.fOrigin = renderTarget ? GrSurface::kBottomLeft_Origin : GrSurface::kTopLeft_Origin;
+    glTexDesc.fOrigin = renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
 
     glRTDesc.fSampleCnt = desc.fSampleCnt;
     if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() &&