Fix GLPrograms test.
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 29 Mar 2013 20:30:50 +0000 (20:30 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 29 Mar 2013 20:30:50 +0000 (20:30 +0000)
Review URL: https://codereview.chromium.org/13327008

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

src/core/SkXfermode.cpp
src/gpu/gl/GrGLProgramDesc.h
tests/GLProgramsTest.cpp

index 705faf8..6f22aa4 100644 (file)
@@ -984,13 +984,20 @@ public:
                               const TextureSamplerArray& samplers) SK_OVERRIDE {
             const char* dstColorName = builder->dstColor();
             GrAssert(NULL != dstColorName);
-            builder->fsCodeAppendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.a);\n",
-                                   outputColor, dstColorName, inputColor);
-            builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb,"
-                                                   " (1.0 - %s.a) * %s.rgb + %s.rgb);\n",
-                                   outputColor,
-                                   inputColor, dstColorName, inputColor,
-                                   dstColorName, inputColor, dstColorName);
+            if (NULL == inputColor) {
+                // the input color is solid white
+                builder->fsCodeAppendf("\t\t%s.a = 1.0;\n", outputColor);
+                builder->fsCodeAppendf("\t\t%s.rgb = vec3(1.0, 1.0, 1.0) - %s.aaa + %s.rgb;\n",
+                                       outputColor, dstColorName, dstColorName);
+            } else {
+                builder->fsCodeAppendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.a);\n",
+                                       outputColor, dstColorName, inputColor);
+                builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb,"
+                                                       " (1.0 - %s.a) * %s.rgb + %s.rgb);\n",
+                                       outputColor,
+                                       inputColor, dstColorName, inputColor,
+                                       dstColorName, inputColor, dstColorName);
+            }
         }
 
         static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { return 0; }
index b1660d8..df5729f 100644 (file)
@@ -38,6 +38,7 @@ public:
     // For unit testing.
     void setRandom(SkMWCRandom*,
                    const GrGpuGL* gpu,
+                   const GrTexture* dummyDstTexture,
                    const GrEffectStage stages[GrDrawState::kNumStages]);
 
     /**
index 13cf85c..512f89e 100644 (file)
@@ -23,6 +23,7 @@
 
 void GrGLProgramDesc::setRandom(SkMWCRandom* random,
                                 const GrGpuGL* gpu,
+                                const GrTexture* dstTexture,
                                 const GrEffectStage stages[GrDrawState::kNumStages]) {
     fAttribBindings = 0;
     fEmitsPointSize = random->nextBool();
@@ -52,6 +53,7 @@ void GrGLProgramDesc::setRandom(SkMWCRandom* random,
         fAttribBindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
     }
 
+    bool dstRead = false;
     for (int s = 0; s < GrDrawState::kNumStages; ++s) {
         if (NULL != stages[s].getEffect()) {
             const GrBackendEffectFactory& factory = (*stages[s].getEffect())->getFactory();
@@ -59,9 +61,16 @@ void GrGLProgramDesc::setRandom(SkMWCRandom* random,
                                         GrDrawState::kLocalCoords_AttribBindingsBit);
             GrDrawEffect drawEffect(stages[s], explicitLocalCoords);
             fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
+            if ((*stages[s].getEffect())->willReadDst()) {
+                dstRead = true;
+            }
         }
     }
 
+    if (dstRead) {
+        this->fDstRead = GrGLShaderBuilder::KeyForDstRead(dstTexture, gpu->glCaps());
+    }
+
     int attributeIndex = 0;
     fPositionAttributeIndex = attributeIndex;
     ++attributeIndex;
@@ -111,10 +120,10 @@ bool GrGpuGL::programUnitTest(int maxStages) {
 
         int currAttribIndex = GrDrawState::kAttribIndexCount;
         int attribIndices[2];
+        GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
         for (int s = 0; s < maxStages; ++s) {
             // enable the stage?
             if (random.nextBool()) {
-                GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
                 SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::CreateStage(
                                                                                 &random,
                                                                                 this->getContext(),
@@ -135,7 +144,8 @@ bool GrGpuGL::programUnitTest(int maxStages) {
                 stages[s].setEffect(effect.get(), attribIndices[0], attribIndices[1]);
             }
         }
-        pdesc.setRandom(&random, this, stages);
+        const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dummyTextures[1];
+        pdesc.setRandom(&random, this, dstTexture, stages);
 
         const GrEffectStage* stagePtrs[GrDrawState::kNumStages];
         for (int s = 0; s < GrDrawState::kNumStages; ++s) {