create and thread batch tracker object
authorjoshualitt <joshualitt@chromium.org>
Thu, 4 Dec 2014 18:41:40 +0000 (10:41 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 4 Dec 2014 18:41:40 +0000 (10:41 -0800)
I remove the factory on the next CL

BUG=skia:

Committed: https://skia.googlesource.com/skia/+/c3a6eb23483e5d28073b509a5f637f41660de294

Review URL: https://codereview.chromium.org/772513002

17 files changed:
include/gpu/GrBackendProcessorFactory.h
include/gpu/GrTBackendProcessorFactory.h
src/gpu/GrAAConvexPathRenderer.cpp
src/gpu/GrDefaultGeoProcFactory.cpp
src/gpu/GrGeometryProcessor.h
src/gpu/GrOptDrawState.cpp
src/gpu/GrOptDrawState.h
src/gpu/GrOvalRenderer.cpp
src/gpu/effects/GrBezierEffect.cpp
src/gpu/effects/GrCustomCoordsTextureEffect.cpp
src/gpu/effects/GrDashingEffect.cpp
src/gpu/effects/GrDistanceFieldTextureEffect.cpp
src/gpu/gl/GrGLGeometryProcessor.h
src/gpu/gl/GrGLProcessor.h
src/gpu/gl/GrGLProgram.cpp
src/gpu/gl/GrGLProgramDesc.cpp
src/gpu/gl/builders/GrGLProgramBuilder.cpp

index acbc12c192610eca193d476abf69a8d5069152b4..dc0bbbe53f66e224bd61cc729f615d69c7fa1270 100644 (file)
@@ -68,14 +68,6 @@ private:
  */
 class GrBackendProcessorFactory : SkNoncopyable {
 public:
-    /** 
-     * Generates an processor's key. The key is based on the aspects of the GrProcessor object's
-     * configuration that affect GLSL code generation. Two GrProcessor instances that would cause
-     * this->createGLInstance()->emitCode() to produce different code must produce different keys.
-     */
-    virtual void getGLProcessorKey(const GrProcessor&, const GrGLCaps&,
-                                   GrProcessorKeyBuilder*) const = 0;
-
     /**
      * Produces a human-reable name for the v.
      */
@@ -127,6 +119,15 @@ class GrGLXferProcessor;
 
 class GrBackendFragmentProcessorFactory : public GrBackendProcessorFactory {
 public:
+    /**
+     * Generates an processor's key. The key is based on the aspects of the GrProcessor object's
+     * configuration that affect GLSL code generation. Two GrProcessor instances that would cause
+     * this->createGLInstance()->emitCode() to produce different code must produce different keys.
+     */
+    virtual void getGLProcessorKey(const GrFragmentProcessor&,
+                                   const GrGLCaps&,
+                                   GrProcessorKeyBuilder*) const = 0;
+
     /**
      * Creates a GrGLProcessor instance that is used both to generate code for the GrProcessor in a
      * GLSL program and to manage updating uniforms for the program when it is used.
@@ -143,13 +144,26 @@ public:
     virtual GrGLXferProcessor* createGLInstance(const GrXferProcessor&) const = 0;
 };
 
+class GrBatchTracker;
+
 class GrBackendGeometryProcessorFactory : public GrBackendProcessorFactory {
 public:
+    /**
+     * Generates an processor's key. The key is based on the aspects of the GrProcessor object's
+     * configuration that affect GLSL code generation. Two GrProcessor instances that would cause
+     * this->createGLInstance()->emitCode() to produce different code must produce different keys.
+     */
+    virtual void getGLProcessorKey(const GrGeometryProcessor&,
+                                   const GrBatchTracker&,
+                                   const GrGLCaps&,
+                                   GrProcessorKeyBuilder*) const = 0;
+
     /**
      * Creates a GrGLProcessor instance that is used both to generate code for the GrProcessor in a
      * GLSL program and to manage updating uniforms for the program when it is used.
      */
-    virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor&) const = 0;
+    virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor&,
+                                                    const GrBatchTracker&) const = 0;
 };
 
 #endif
index a86fe38d92ea40367c9f78009e44579bc4a358ed..98b5d6cb7e89239a18576a1fe6544507a304d82d 100644 (file)
@@ -41,14 +41,6 @@ public:
      *  described in this class's comment. */
     virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); }
 
-
-    /** Implemented using GLProcessor::GenKey as described in this class's comment. */
-    virtual void getGLProcessorKey(const GrProcessor& processor,
-                                   const GrGLCaps& caps,
-                                   GrProcessorKeyBuilder* b) const SK_OVERRIDE {
-        GLProcessor::GenKey(processor, caps, b);
-    }
-
     /** Returns a new instance of the appropriate *GL* implementation class
         for the given GrProcessor; caller is responsible for deleting
         the object. */
@@ -77,24 +69,80 @@ protected:
  * typesafe and does not require any casting.
  */
 template <class ProcessorClass>
-class GrTBackendGeometryProcessorFactory
-        : public GrTBackendProcessorFactory<ProcessorClass,
-                                            GrBackendGeometryProcessorFactory,
-                                            GrGeometryProcessor,
-                                            GrGLGeometryProcessor> {
+class GrTBackendGeometryProcessorFactory : public GrBackendGeometryProcessorFactory {
+public:
+    typedef typename ProcessorClass::GLProcessor GLProcessor;
+
+    /** Returns a human-readable name for the processor. Implemented using GLProcessor::Name as
+     *  described in this class's comment. */
+    virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); }
+
+    /** Implemented using GLProcessor::GenKey as described in this class's comment. */
+    virtual void getGLProcessorKey(const GrGeometryProcessor& processor,
+                                   const GrBatchTracker& bt,
+                                   const GrGLCaps& caps,
+                                   GrProcessorKeyBuilder* b) const SK_OVERRIDE {
+        GLProcessor::GenKey(processor, bt, caps, b);
+    }
+
+
+    /** Returns a new instance of the appropriate *GL* implementation class
+        for the given GrProcessor; caller is responsible for deleting
+        the object. */
+    virtual GrGLGeometryProcessor* createGLInstance(const GrGeometryProcessor& gp,
+                                                    const GrBatchTracker& bt) const SK_OVERRIDE {
+        return SkNEW_ARGS(GLProcessor, (*this, gp, bt));
+    }
+
+    /** This class is a singleton. This function returns the single instance. */
+    static const GrBackendGeometryProcessorFactory& getInstance() {
+        static SkAlignedSTStorage<1, GrTBackendGeometryProcessorFactory> gInstanceMem;
+        static const GrTBackendGeometryProcessorFactory* gInstance;
+        if (!gInstance) {
+            gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
+                                        GrTBackendGeometryProcessorFactory);
+        }
+        return *gInstance;
+    }
 protected:
     GrTBackendGeometryProcessorFactory() {}
 };
 
 template <class ProcessorClass>
-class GrTBackendFragmentProcessorFactory
-        : public GrTBackendProcessorFactory<ProcessorClass,
-                                           GrBackendFragmentProcessorFactory,
-                                           GrFragmentProcessor,
-                                           GrGLFragmentProcessor> {
+class GrTBackendFragmentProcessorFactory : public GrBackendFragmentProcessorFactory {
+public:
+    typedef typename ProcessorClass::GLProcessor GLProcessor;
+
+    /** Returns a human-readable name for the processor. Implemented using GLProcessor::Name as
+     *  described in this class's comment. */
+    virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); }
+
+    /** Implemented using GLProcessor::GenKey as described in this class's comment. */
+    virtual void getGLProcessorKey(const GrFragmentProcessor& processor,
+                                   const GrGLCaps& caps,
+                                   GrProcessorKeyBuilder* b) const SK_OVERRIDE {
+        GLProcessor::GenKey(processor, caps, b);
+    }
+
+    /** Returns a new instance of the appropriate *GL* implementation class
+        for the given GrProcessor; caller is responsible for deleting
+        the object. */
+    virtual GrGLFragmentProcessor* createGLInstance(const GrFragmentProcessor& gp) const SK_OVERRIDE {
+        return SkNEW_ARGS(GLProcessor, (*this, gp));
+    }
+
+    /** This class is a singleton. This function returns the single instance. */
+    static const GrBackendFragmentProcessorFactory& getInstance() {
+        static SkAlignedSTStorage<1, GrTBackendFragmentProcessorFactory> gInstanceMem;
+        static const GrTBackendFragmentProcessorFactory* gInstance;
+        if (!gInstance) {
+            gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
+                                        GrTBackendFragmentProcessorFactory);
+        }
+        return *gInstance;
+    }
 protected:
     GrTBackendFragmentProcessorFactory() {}
 };
 
-
 #endif
index b5ad44adc004eb21c7079b5c5955459d1b5ad855..3108b0472e96bfdd757a1301ff5eebe293445622 100644 (file)
@@ -527,7 +527,9 @@ public:
 
     class GLProcessor : public GrGLGeometryProcessor {
     public:
-        GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+        GLProcessor(const GrBackendProcessorFactory& factory,
+                    const GrGeometryProcessor&,
+                    const GrBatchTracker&)
             : INHERITED (factory) {}
 
         virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
@@ -571,9 +573,14 @@ public:
             fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
         }
 
-        static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*) {}
+        static inline void GenKey(const GrGeometryProcessor&,
+                                  const GrBatchTracker&,
+                                  const GrGLCaps&,
+                                  GrProcessorKeyBuilder*) {}
 
-        virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+        virtual void setData(const GrGLProgramDataManager&,
+                             const GrGeometryProcessor&,
+                             const GrBatchTracker&) SK_OVERRIDE {}
 
     private:
         typedef GrGLGeometryProcessor INHERITED;
index ab28a579e7ab7a2115f53b1079fbd5a651dd0cd7..ddaa809f067bbcd07fcd14fe7362f80a43583638 100644 (file)
@@ -75,7 +75,9 @@ public:
 
     class GLProcessor : public GrGLGeometryProcessor {
     public:
-        GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+        GLProcessor(const GrBackendProcessorFactory& factory,
+                    const GrGeometryProcessor&,
+                    const GrBatchTracker&)
             : INHERITED (factory) {}
 
         virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
@@ -109,12 +111,17 @@ public:
             fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
         }
 
-        static inline void GenKey(const GrProcessor& gp, const GrGLCaps&, GrProcessorKeyBuilder* b) {
+        static inline void GenKey(const GrGeometryProcessor& gp,
+                                  const GrBatchTracker&,
+                                  const GrGLCaps&,
+                                  GrProcessorKeyBuilder* b) {
             const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
             b->add32(def.fFlags);
         }
 
-        virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+        virtual void setData(const GrGLProgramDataManager&,
+                             const GrGeometryProcessor&,
+                             const GrBatchTracker&) SK_OVERRIDE {}
 
     private:
         typedef GrGLGeometryProcessor INHERITED;
index 17344d2bb4c251df6469aff20512bb4ba98fdf13..27383a4df49df6dd3e618f24f72fed5a5e745a1d 100644 (file)
 #include "GrProcessor.h"
 #include "GrShaderVar.h"
 
+/*
+ * A struct for tracking batching decisions.  While this lives on GrOptState, it is managed
+ * entirely by the derived classes of the GP.
+ */
+class GrBatchTracker {
+public:
+    template <typename T> const T& cast() const {
+        SkASSERT(sizeof(T) <= kMaxSize);
+        return *reinterpret_cast<const T*>(fData);
+    }
+
+    template <typename T> T* cast() {
+        SkASSERT(sizeof(T) <= kMaxSize);
+        return reinterpret_cast<T*>(fData);
+    }
+
+    static const size_t kMaxSize = 32;
+
+private:
+    uint8_t fData[kMaxSize];
+};
+
+class GrOptDrawState;
+
 /**
  * A GrGeometryProcessor is used to perform computation in the vertex shader and
  * add support for custom vertex attributes. A GrGemeotryProcessor is typically
@@ -73,6 +97,15 @@ public:
         return this->onIsEqual(that);
     }
 
+    struct InitBT {
+        bool fOutputColor;
+        bool fOutputCoverage;
+        GrColor fColor;
+        GrColor fCoverage;
+    };
+
+    virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {}
+
     // TODO this is a total hack until the gp can own whether or not it uses uniform
     // color / coverage
     bool hasVertexColor() const { return fHasVertexColor; }
index b7875968135b4703fb323e0d995d5acf33f33b07..d95bd3b7c42017a2526f4fd3e7fcb662bed8502e 100644 (file)
@@ -117,7 +117,17 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
     }
 
     this->setOutputStateInfo(drawState, blendOpt, caps);
-};
+
+    // let the GP init the batch tracker
+    if (drawState.hasGeometryProcessor()) {
+        GrGeometryProcessor::InitBT init;
+        init.fOutputColor = fDescInfo.fInputColorIsUsed;
+        init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed;
+        init.fColor = this->getColor();
+        init.fCoverage = this->getCoverage();
+        fGeometryProcessor->initBatchTracker(&fBatchTracker, init);
+    }
+}
 
 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
                                         GrDrawState::BlendOpt blendOpt,
index 25a3a49995525e36b138bf88e7be96e660ee1bc8..45501b49dd1c4fc4efe8ea9933d07875780cd3e4 100644 (file)
@@ -84,6 +84,7 @@ public:
 
     bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()); }
     const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryProcessor.get(); }
+    const GrBatchTracker& getBatchTracker() const { return fBatchTracker; }
 
     const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(); }
 
@@ -233,6 +234,7 @@ private:
     GrBlendCoeff                        fDstBlend;
     uint32_t                            fFlags;
     ProgramGeometryProcessor            fGeometryProcessor;
+    GrBatchTracker                      fBatchTracker;
     ProgramXferProcessor                fXferProcessor;
     FragmentStageArray                  fFragmentStages;
     GrGpu::DrawType                     fDrawType;
index a9dda840aa59d2b036413597d76c4f6e13c9a295..c6586120a9a902b02dfc4cbc0c0a69c618da690a 100644 (file)
@@ -91,7 +91,9 @@ public:
 
     class GLProcessor : public GrGLGeometryProcessor {
     public:
-        GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+        GLProcessor(const GrBackendProcessorFactory& factory,
+                    const GrGeometryProcessor&,
+                    const GrBatchTracker&)
         : INHERITED (factory) {}
 
         virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
@@ -122,13 +124,17 @@ public:
             fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
         }
 
-        static void GenKey(const GrProcessor& processor, const GrGLCaps&,
+        static void GenKey(const GrGeometryProcessor& processor,
+                           const GrBatchTracker&,
+                           const GrGLCaps&,
                            GrProcessorKeyBuilder* b) {
             const CircleEdgeEffect& circleEffect = processor.cast<CircleEdgeEffect>();
             b->add32(circleEffect.isStroked());
         }
 
-        virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+        virtual void setData(const GrGLProgramDataManager&,
+                             const GrGeometryProcessor&,
+                             const GrBatchTracker&) SK_OVERRIDE {}
 
     private:
         typedef GrGLGeometryProcessor INHERITED;
@@ -212,7 +218,9 @@ public:
 
     class GLProcessor : public GrGLGeometryProcessor {
     public:
-        GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+        GLProcessor(const GrBackendProcessorFactory& factory,
+                    const GrGeometryProcessor&,
+                    const GrBatchTracker&)
         : INHERITED (factory) {}
 
         virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
@@ -265,13 +273,17 @@ public:
             fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
         }
 
-        static void GenKey(const GrProcessor& processor, const GrGLCaps&,
+        static void GenKey(const GrGeometryProcessor& processor,
+                           const GrBatchTracker&,
+                           const GrGLCaps&,
                            GrProcessorKeyBuilder* b) {
             const EllipseEdgeEffect& ellipseEffect = processor.cast<EllipseEdgeEffect>();
             b->add32(ellipseEffect.isStroked());
         }
 
-        virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {
+        virtual void setData(const GrGLProgramDataManager&,
+                             const GrGeometryProcessor&,
+                             const GrBatchTracker&) SK_OVERRIDE {
         }
 
     private:
@@ -364,7 +376,9 @@ public:
 
     class GLProcessor : public GrGLGeometryProcessor {
     public:
-        GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&)
+        GLProcessor(const GrBackendProcessorFactory& factory,
+                    const GrGeometryProcessor&,
+                    const GrBatchTracker&)
         : INHERITED (factory) {}
 
         virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
@@ -431,14 +445,18 @@ public:
             fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
         }
 
-        static void GenKey(const GrProcessor& processor, const GrGLCaps&,
+        static void GenKey(const GrGeometryProcessor& processor,
+                           const GrBatchTracker&,
+                           const GrGLCaps&,
                            GrProcessorKeyBuilder* b) {
             const DIEllipseEdgeEffect& ellipseEffect = processor.cast<DIEllipseEdgeEffect>();
 
             b->add32(ellipseEffect.getMode());
         }
 
-        virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {
+        virtual void setData(const GrGLProgramDataManager&,
+                             const GrGeometryProcessor&,
+                             const GrBatchTracker&) SK_OVERRIDE {
         }
 
     private:
index 1b14d349dd9fc29688a0604650926466dc20def2..0bcfc75bef5cbbcb4ac40bf9c71321a832d70d91 100644 (file)
 
 class GrGLConicEffect : public GrGLGeometryProcessor {
 public:
-    GrGLConicEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+    GrGLConicEffect(const GrBackendProcessorFactory&,
+                    const GrGeometryProcessor&,
+                    const GrBatchTracker&);
 
     virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
 
-    static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+    static inline void GenKey(const GrGeometryProcessor&,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
+                              GrProcessorKeyBuilder*);
 
-    virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+    virtual void setData(const GrGLProgramDataManager&,
+                         const GrGeometryProcessor&,
+                         const GrBatchTracker&) SK_OVERRIDE {}
 
 private:
     GrPrimitiveEdgeType fEdgeType;
@@ -30,9 +37,10 @@ private:
 };
 
 GrGLConicEffect::GrGLConicEffect(const GrBackendProcessorFactory& factory,
-                                 const GrProcessor& effect)
+                                 const GrGeometryProcessor& processor,
+                                 const GrBatchTracker& bt)
     : INHERITED (factory) {
-    const GrConicEffect& ce = effect.cast<GrConicEffect>();
+    const GrConicEffect& ce = processor.cast<GrConicEffect>();
     fEdgeType = ce.getEdgeType();
 }
 
@@ -112,7 +120,9 @@ void GrGLConicEffect::emitCode(const EmitArgs& args) {
     fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
 }
 
-void GrGLConicEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor,
+                             const GrBatchTracker&,
+                             const GrGLCaps&,
                              GrProcessorKeyBuilder* b) {
     const GrConicEffect& ce = processor.cast<GrConicEffect>();
     uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
@@ -162,13 +172,20 @@ GrGeometryProcessor* GrConicEffect::TestCreate(SkRandom* random,
 
 class GrGLQuadEffect : public GrGLGeometryProcessor {
 public:
-    GrGLQuadEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+    GrGLQuadEffect(const GrBackendProcessorFactory&,
+                   const GrGeometryProcessor&,
+                   const GrBatchTracker&);
 
     virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
 
-    static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+    static inline void GenKey(const GrGeometryProcessor&,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
+                              GrProcessorKeyBuilder*);
 
-    virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+    virtual void setData(const GrGLProgramDataManager&,
+                         const GrGeometryProcessor&,
+                         const GrBatchTracker&) SK_OVERRIDE {}
 
 private:
     GrPrimitiveEdgeType fEdgeType;
@@ -177,9 +194,10 @@ private:
 };
 
 GrGLQuadEffect::GrGLQuadEffect(const GrBackendProcessorFactory& factory,
-                                 const GrProcessor& effect)
+                               const GrGeometryProcessor& processor,
+                               const GrBatchTracker& bt)
     : INHERITED (factory) {
-    const GrQuadEffect& ce = effect.cast<GrQuadEffect>();
+    const GrQuadEffect& ce = processor.cast<GrQuadEffect>();
     fEdgeType = ce.getEdgeType();
 }
 
@@ -245,7 +263,9 @@ void GrGLQuadEffect::emitCode(const EmitArgs& args) {
     fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
 }
 
-void GrGLQuadEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor,
+                            const GrBatchTracker&,
+                            const GrGLCaps&,
                             GrProcessorKeyBuilder* b) {
     const GrQuadEffect& ce = processor.cast<GrQuadEffect>();
     uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
@@ -295,13 +315,20 @@ GrGeometryProcessor* GrQuadEffect::TestCreate(SkRandom* random,
 
 class GrGLCubicEffect : public GrGLGeometryProcessor {
 public:
-    GrGLCubicEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+    GrGLCubicEffect(const GrBackendProcessorFactory&,
+                    const GrGeometryProcessor&,
+                    const GrBatchTracker&);
 
     virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
 
-    static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+    static inline void GenKey(const GrGeometryProcessor&,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
+                              GrProcessorKeyBuilder*);
 
-    virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {}
+    virtual void setData(const GrGLProgramDataManager&,
+                         const GrGeometryProcessor&,
+                         const GrBatchTracker&) SK_OVERRIDE {}
 
 private:
     GrPrimitiveEdgeType fEdgeType;
@@ -310,7 +337,8 @@ private:
 };
 
 GrGLCubicEffect::GrGLCubicEffect(const GrBackendProcessorFactory& factory,
-                                 const GrProcessor& processor)
+                                 const GrGeometryProcessor& processor,
+                                 const GrBatchTracker&)
     : INHERITED (factory) {
     const GrCubicEffect& ce = processor.cast<GrCubicEffect>();
     fEdgeType = ce.getEdgeType();
@@ -419,7 +447,9 @@ void GrGLCubicEffect::emitCode(const EmitArgs& args) {
     fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_str());
 }
 
-void GrGLCubicEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor,
+                             const GrBatchTracker&,
+                             const GrGLCaps&,
                              GrProcessorKeyBuilder* b) {
     const GrCubicEffect& ce = processor.cast<GrCubicEffect>();
     uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
index 45c30088898f708ab2c2244c0648bdef9b84d33d..637d442d133143aace8fcbe9bfa9100442d8a732 100644 (file)
@@ -17,7 +17,9 @@
 
 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor {
 public:
-    GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory, const GrProcessor&)
+    GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory,
+                                  const GrGeometryProcessor&,
+                                  const GrBatchTracker&)
         : INHERITED (factory) {}
 
     virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
@@ -49,9 +51,12 @@ public:
     }
 
     virtual void setData(const GrGLProgramDataManager&,
-                         const GrProcessor&) SK_OVERRIDE {}
+                         const GrGeometryProcessor&,
+                         const GrBatchTracker&) SK_OVERRIDE {}
 
-    static inline void GenKey(const GrProcessor& proc, const GrGLCaps&,
+    static inline void GenKey(const GrGeometryProcessor& proc,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
                               GrProcessorKeyBuilder* b) {
         const GrCustomCoordsTextureEffect& gp = proc.cast<GrCustomCoordsTextureEffect>();
 
index 95760e62e5ced5183bede3e97a8d1dfdb4affc7c..fec1551ef58196084934aafcb67701d1b36d9f57 100644 (file)
@@ -504,13 +504,20 @@ private:
 
 class GLDashingCircleEffect : public GrGLGeometryProcessor {
 public:
-    GLDashingCircleEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+    GLDashingCircleEffect(const GrBackendProcessorFactory&,
+                          const GrGeometryProcessor&,
+                          const GrBatchTracker&);
 
     virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
 
-    static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+    static inline void GenKey(const GrGeometryProcessor&,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
+                              GrProcessorKeyBuilder*);
 
-    virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE;
+    virtual void setData(const GrGLProgramDataManager&,
+                         const GrGeometryProcessor&,
+                         const GrBatchTracker&) SK_OVERRIDE;
 
 private:
     GrGLProgramDataManager::UniformHandle fParamUniform;
@@ -521,7 +528,8 @@ private:
 };
 
 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendProcessorFactory& factory,
-                                             const GrProcessor&)
+                                             const GrGeometryProcessor&,
+                                             const GrBatchTracker&)
     : INHERITED (factory) {
     fPrevRadius = SK_ScalarMin;
     fPrevCenterX = SK_ScalarMin;
@@ -570,8 +578,9 @@ void GLDashingCircleEffect::emitCode(const EmitArgs& args) {
     fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
 }
 
-void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman
-                                    , const GrProcessor& processor) {
+void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman,
+                                    const GrGeometryProcessor& processor,
+                                    const GrBatchTracker&) {
     const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
     SkScalar radius = dce.getRadius();
     SkScalar centerX = dce.getCenterX();
@@ -584,7 +593,9 @@ void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman
     }
 }
 
-void GLDashingCircleEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor,
+                                   const GrBatchTracker&,
+                                   const GrGLCaps&,
                                    GrProcessorKeyBuilder* b) {
     const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
     b->add32(dce.getEdgeType());
@@ -712,13 +723,20 @@ private:
 
 class GLDashingLineEffect : public GrGLGeometryProcessor {
 public:
-    GLDashingLineEffect(const GrBackendProcessorFactory&, const GrProcessor&);
+    GLDashingLineEffect(const GrBackendProcessorFactory&,
+                        const GrGeometryProcessor&,
+                        const GrBatchTracker&);
 
     virtual void emitCode(const EmitArgs&) SK_OVERRIDE;
 
-    static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*);
+    static inline void GenKey(const GrGeometryProcessor&,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
+                              GrProcessorKeyBuilder*);
 
-    virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE;
+    virtual void setData(const GrGLProgramDataManager&,
+                         const GrGeometryProcessor&,
+                         const GrBatchTracker&) SK_OVERRIDE;
 
 private:
     GrGLProgramDataManager::UniformHandle fRectUniform;
@@ -729,7 +747,8 @@ private:
 };
 
 GLDashingLineEffect::GLDashingLineEffect(const GrBackendProcessorFactory& factory,
-                                         const GrProcessor&)
+                                         const GrGeometryProcessor&,
+                                         const GrBatchTracker&)
     : INHERITED (factory) {
     fPrevRect.fLeft = SK_ScalarNaN;
     fPrevIntervalLength = SK_ScalarMax;
@@ -792,7 +811,8 @@ void GLDashingLineEffect::emitCode(const EmitArgs& args) {
 }
 
 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman,
-                                  const GrProcessor& processor) {
+                                  const GrGeometryProcessor& processor,
+                                  const GrBatchTracker&) {
     const DashingLineEffect& de = processor.cast<DashingLineEffect>();
     const SkRect& rect = de.getRect();
     SkScalar intervalLength = de.getIntervalLength();
@@ -805,7 +825,9 @@ void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman,
     }
 }
 
-void GLDashingLineEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
+void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor,
+                                 const GrBatchTracker&,
+                                 const GrGLCaps&,
                                  GrProcessorKeyBuilder* b) {
     const DashingLineEffect& de = processor.cast<DashingLineEffect>();
     b->add32(de.getEdgeType());
index 5e1bc9968ce1aecfa23b7f622b034bd0d8ed74a9..53f85907e42fe6bac2fa2b3e9db6279ddb147ede 100755 (executable)
@@ -23,7 +23,8 @@
 class GrGLDistanceFieldTextureEffect : public GrGLGeometryProcessor {
 public:
     GrGLDistanceFieldTextureEffect(const GrBackendProcessorFactory& factory,
-                                   const GrProcessor&)
+                                   const GrGeometryProcessor&,
+                                   const GrBatchTracker&)
         : INHERITED (factory)
         , fTextureSize(SkISize::Make(-1,-1))
 #ifdef SK_GAMMA_APPLY_TO_A8
@@ -124,10 +125,11 @@ public:
     }
 
     virtual void setData(const GrGLProgramDataManager& pdman,
-                         const GrProcessor& effect) SK_OVERRIDE {
+                         const GrGeometryProcessor& proc,
+                         const GrBatchTracker&) SK_OVERRIDE {
         SkASSERT(fTextureSizeUni.isValid());
 
-        GrTexture* texture = effect.texture(0);
+        GrTexture* texture = proc.texture(0);
         if (texture->width() != fTextureSize.width() ||
             texture->height() != fTextureSize.height()) {
             fTextureSize = SkISize::Make(texture->width(), texture->height());
@@ -137,7 +139,7 @@ public:
         }
 #ifdef SK_GAMMA_APPLY_TO_A8
         const GrDistanceFieldTextureEffect& dfTexEffect =
-                effect.cast<GrDistanceFieldTextureEffect>();
+                proc.cast<GrDistanceFieldTextureEffect>();
         float luminance = dfTexEffect.getLuminance();
         if (luminance != fLuminance) {
             pdman.set1f(fLuminanceUni, luminance);
@@ -146,7 +148,9 @@ public:
 #endif
     }
 
-    static inline void GenKey(const GrProcessor& processor, const GrGLCaps&,
+    static inline void GenKey(const GrGeometryProcessor& processor,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
                               GrProcessorKeyBuilder* b) {
         const GrDistanceFieldTextureEffect& dfTexEffect =
                 processor.cast<GrDistanceFieldTextureEffect>();
@@ -255,7 +259,8 @@ GrGeometryProcessor* GrDistanceFieldTextureEffect::TestCreate(SkRandom* random,
 class GrGLDistanceFieldNoGammaTextureEffect : public GrGLGeometryProcessor {
 public:
     GrGLDistanceFieldNoGammaTextureEffect(const GrBackendProcessorFactory& factory,
-                                          const GrProcessor& effect)
+                                          const GrGeometryProcessor&,
+                                          const GrBatchTracker&)
         : INHERITED(factory)
         , fTextureSize(SkISize::Make(-1, -1)) {}
 
@@ -338,10 +343,11 @@ public:
     }
 
     virtual void setData(const GrGLProgramDataManager& pdman,
-                         const GrProcessor& effect) SK_OVERRIDE {
+                         const GrGeometryProcessor& proc,
+                         const GrBatchTracker&) SK_OVERRIDE {
         SkASSERT(fTextureSizeUni.isValid());
 
-        GrTexture* texture = effect.texture(0);
+        GrTexture* texture = proc.texture(0);
         if (texture->width() != fTextureSize.width() || 
             texture->height() != fTextureSize.height()) {
             fTextureSize = SkISize::Make(texture->width(), texture->height());
@@ -351,10 +357,12 @@ public:
         }
     }
 
-    static inline void GenKey(const GrProcessor& effect, const GrGLCaps&,
+    static inline void GenKey(const GrGeometryProcessor& proc,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
                               GrProcessorKeyBuilder* b) {
         const GrDistanceFieldNoGammaTextureEffect& dfTexEffect =
-            effect.cast<GrDistanceFieldNoGammaTextureEffect>();
+            proc.cast<GrDistanceFieldNoGammaTextureEffect>();
 
         b->add32(dfTexEffect.getFlags());
     }
@@ -430,7 +438,8 @@ GrGeometryProcessor* GrDistanceFieldNoGammaTextureEffect::TestCreate(SkRandom* r
 class GrGLDistanceFieldLCDTextureEffect : public GrGLGeometryProcessor {
 public:
     GrGLDistanceFieldLCDTextureEffect(const GrBackendProcessorFactory& factory,
-                                      const GrProcessor&)
+                                      const GrGeometryProcessor&,
+                                      const GrBatchTracker&)
     : INHERITED (factory)
     , fTextureSize(SkISize::Make(-1,-1))
     , fTextColor(GrColor_ILLEGAL) {}
@@ -563,7 +572,8 @@ public:
     }
 
     virtual void setData(const GrGLProgramDataManager& pdman,
-                         const GrProcessor& processor) SK_OVERRIDE {
+                         const GrGeometryProcessor& processor,
+                         const GrBatchTracker&) SK_OVERRIDE {
         SkASSERT(fTextureSizeUni.isValid());
         SkASSERT(fTextColorUni.isValid());
 
@@ -594,7 +604,9 @@ public:
         }
     }
 
-    static inline void GenKey(const GrProcessor& processor, const GrGLCaps&,
+    static inline void GenKey(const GrGeometryProcessor& processor,
+                              const GrBatchTracker&,
+                              const GrGLCaps&,
                               GrProcessorKeyBuilder* b) {
         const GrDistanceFieldLCDTextureEffect& dfTexEffect =
                 processor.cast<GrDistanceFieldLCDTextureEffect>();
index c3bee952665449a111f43d9834de5388e9c97b6b..a172904ac68aa1a55240051143c1c785247cb590 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "GrGLProcessor.h"
 
+class GrBatchTracker;
 class GrGLGPBuilder;
 
 /**
@@ -25,16 +26,19 @@ public:
     struct EmitArgs {
         EmitArgs(GrGLGPBuilder* pb,
                  const GrGeometryProcessor& gp,
+                 const GrBatchTracker& bt,
                  const char* outputColor,
                  const char* outputCoverage,
                  const TextureSamplerArray& samplers)
             : fPB(pb)
             , fGP(gp)
+            , fBT(bt)
             , fOutputColor(outputColor)
             , fOutputCoverage(outputCoverage)
             , fSamplers(samplers) {}
         GrGLGPBuilder* fPB;
         const GrGeometryProcessor& fGP;
+        const GrBatchTracker& fBT;
         const char* fOutputColor;
         const char* fOutputCoverage;
         const TextureSamplerArray& fSamplers;
@@ -45,6 +49,15 @@ public:
      */
     virtual void emitCode(const EmitArgs&) = 0;
 
+    /** A GrGLGeometryProcessor instance can be reused with any GrGLGeometryProcessor that produces
+        the same stage key; this function reads data from a GrGLGeometryProcessor and uploads any
+        uniform variables required  by the shaders created in emitCode(). The GrGeometryProcessor
+        parameter is guaranteed to be of the same type that created this GrGLGeometryProcessor and
+        to have an identical processor key as the one that created this GrGLGeometryProcessor.  */
+    virtual void setData(const GrGLProgramDataManager&,
+                         const GrGeometryProcessor&,
+                         const GrBatchTracker&) = 0;
+
 private:
     typedef GrGLProcessor INHERITED;
 };
index ca4fa2459f97a1c1ca9b823120fae1d2bdcfeafa..6401e2b324abdacfc36fe11fdafd1e24017bb2e3 100644 (file)
@@ -22,7 +22,7 @@
     that their GrGLProcessors would emit the same GLSL code.
 
     The GrGLProcessor subclass must also have a constructor of the form:
-        EffectSubclass::EffectSubclass(const GrBackendProcessorFactory&, const GrProcessor&)
+        ProcessorSubclass::ProcessorSubclass(const GrBackendProcessorFactory&, const GrProcessor&)
 
     These objects are created by the factory object returned by the GrProcessor::getFactory().
 */
@@ -70,13 +70,6 @@ public:
 
     virtual ~GrGLProcessor() {}
 
-    /** A GrGLProcessor instance can be reused with any GrProcessor that produces the same stage
-        key; this function reads data from a GrProcessor and uploads any uniform variables required
-        by the shaders created in emitCode(). The GrProcessor parameter is guaranteed to be of the
-        same type that created this GrGLProcessor and to have an identical effect key as the one
-        that created this GrGLProcessor.  */
-    virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {}
-
     const char* name() const { return fFactory.name(); }
 
     static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder*) {}
@@ -100,7 +93,7 @@ public:
         stages.
 
         @param builder      Interface used to emit code in the shaders.
-        @param effect       The effect that generated this program stage.
+        @param processor    The processor that generated this program stage.
         @param key          The key that was computed by GenKey() from the generating GrProcessor.
         @param outputColor  A predefined vec4 in the FS in which the stage should place its output
                             color (or coverage).
@@ -108,19 +101,27 @@ public:
                             NULL in which case the implied input is solid white (all ones).
                             TODO: Better system for communicating optimization info (e.g. input
                             color is solid white, trans black, known to be opaque, etc.) that allows
-                            the effect to communicate back similar known info about its output.
+                            the processor to communicate back similar known info about its output.
         @param samplers     Contains one entry for each GrTextureAccess of the GrProcessor. These
                             can be passed to the builder to emit texture reads in the generated
                             code.
         TODO this should take a struct
         */
     virtual void emitCode(GrGLFPBuilder* builder,
-                          const GrFragmentProcessor& effect,
+                          const GrFragmentProcessor&,
                           const char* outputColor,
                           const char* inputColor,
                           const TransformedCoordsArray& coords,
                           const TextureSamplerArray& samplers) = 0;
 
+    /** A GrGLFragmentProcessor instance can be reused with any GrFragmentProcessor that produces
+        the same stage key; this function reads data from a GrFragmentProcessor and uploads any
+        uniform variables required by the shaders created in emitCode(). The GrFragmentProcessor
+        parameter is guaranteed to be of the same type that created this GrGLFragmentProcessor and
+        to have an identical processor key as the one that created this GrGLFragmentProcessor.  */
+    // TODO update this to pass in GrFragmentProcessor
+    virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {}
+
 private:
     typedef GrGLProcessor INHERITED;
 };
index 3b04edb8c8802f77342a97eccc31211040b26574..29c44ac56ccb9e92181b4b254c999857f325dadb 100644 (file)
@@ -158,7 +158,8 @@ void GrGLProgram::setData(const GrOptDrawState& optState) {
     if (fGeometryProcessor.get()) {
         SkASSERT(optState.hasGeometryProcessor());
         const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
-        fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp);
+        const GrBatchTracker& bt = optState.getBatchTracker();
+        fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp, bt);
         this->bindTextures(fGeometryProcessor, gp);
     }
     this->setFragmentData(optState);
index f8dbbc26f9096858a19966f0fcba2f422c176528..474f7026e48845fe1816518d5426ce35a06da388 100644 (file)
@@ -123,9 +123,6 @@ static bool get_meta_key(const GrProcessor& proc,
                          uint32_t transformKey,
                          uint32_t attribKey,
                          GrProcessorKeyBuilder* b) {
-    const GrBackendProcessorFactory& factory = proc.getFactory();
-    factory.getGLProcessorKey(proc, caps, b);
-
     size_t processorKeySize = b->size();
     uint32_t textureKey = gen_texture_key(proc, caps);
     uint32_t classID = proc.getFactory().classID();
@@ -170,6 +167,8 @@ bool GrGLProgramDescBuilder::Build(const GrOptDrawState& optState,
     if (optState.hasGeometryProcessor()) {
         const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
         GrProcessorKeyBuilder b(&desc->fKey);
+        const GrBackendGeometryProcessorFactory& factory = gp.getFactory();
+        factory.getGLProcessorKey(gp, optState.getBatchTracker(), gpu->glCaps(), &b);
         if (!get_meta_key(gp, gpu->glCaps(), 0, gen_attrib_key(gp), &b)) {
             desc->fKey.reset();
             return false;
@@ -178,7 +177,10 @@ bool GrGLProgramDescBuilder::Build(const GrOptDrawState& optState,
 
     for (int s = 0; s < optState.numFragmentStages(); ++s) {
         const GrPendingFragmentStage& fps = optState.getFragmentStage(s);
+        const GrFragmentProcessor& fp = *fps.getProcessor();
         GrProcessorKeyBuilder b(&desc->fKey);
+        const GrBackendFragmentProcessorFactory& factory = fp.getFactory();
+        factory.getGLProcessorKey(fp, gpu->glCaps(), &b);
         if (!get_meta_key(*fps.getProcessor(), gpu->glCaps(),
                          gen_transform_key(fps, requiresLocalCoordAttrib), 0, &b)) {
             desc->fKey.reset();
index aa9e40c3f2acf942f2f2eeec64e2ed7d7ba6a377..2f4329ae048b0704d756c672df65274d01c0b193 100644 (file)
@@ -359,12 +359,13 @@ void GrGLProgramBuilder::emitAndInstallProc(const GrGeometryProcessor& gp,
     SkASSERT(!fGeometryProcessor);
     fGeometryProcessor = SkNEW(GrGLInstalledGeoProc);
 
-    fGeometryProcessor->fGLProc.reset(gp.getFactory().createGLInstance(gp));
+    const GrBatchTracker& bt = fOptState.getBatchTracker();
+    fGeometryProcessor->fGLProc.reset(gp.getFactory().createGLInstance(gp, bt));
 
     SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures());
     this->emitSamplers(gp, &samplers, fGeometryProcessor);
 
-    GrGLGeometryProcessor::EmitArgs args(this, gp, outColor, outCoverage, samplers);
+    GrGLGeometryProcessor::EmitArgs args(this, gp, bt, outColor, outCoverage, samplers);
     fGeometryProcessor->fGLProc->emitCode(args);
 
     // We have to check that effects and the code they emit are consistent, ie if an effect