Exemplo n.º 1
0
    void onEmitCode(const EmitArgs& args) override {
        const ShaderPDXferProcessor& xp = args.fXP.cast<ShaderPDXferProcessor>();
        GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();

        SkXfermode::Coeff srcCoeff, dstCoeff;
        SkXfermode::ModeAsCoeff(xp.getXfermode(), &srcCoeff, &dstCoeff);

        const char* dstColor = fsBuilder->dstColor();

        fsBuilder->codeAppend("vec4 colorBlend =");
        // append src blend
        bool didAppend = append_porterduff_term(fsBuilder, srcCoeff,
                                                args.fInputColor, args.fInputColor,
                                                dstColor, false);
        // append dst blend
        SkAssertResult(append_porterduff_term(fsBuilder, dstCoeff,
                                              dstColor, args.fInputColor,
                                              dstColor, didAppend));
        fsBuilder->codeAppend(";");

        fsBuilder->codeAppendf("%s = %s * colorBlend + (vec4(1.0) - %s) * %s;",
                               args.fOutputPrimary, args.fInputCoverage, args.fInputCoverage,
                               dstColor);
    }
    void emitBlendCodeForDstRead(GrGLXPBuilder* pb, const char* srcColor, const char* dstColor,
                                 const char* outColor, const GrXferProcessor& proc) override {
        const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>();
        GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();

        SkXfermode::Coeff srcCoeff, dstCoeff;
        SkXfermode::ModeAsCoeff(xp.getXfermode(), &srcCoeff, &dstCoeff);

        fsBuilder->codeAppendf("%s =", outColor);
        // append src blend
        bool didAppend = append_porterduff_term(fsBuilder, srcCoeff, srcColor, srcColor, dstColor,
                                                false);
        // append dst blend
        SkAssertResult(append_porterduff_term(fsBuilder, dstCoeff, dstColor, srcColor, dstColor,
                                              didAppend));
        fsBuilder->codeAppend(";");
    }
Exemplo n.º 3
0
    void onEmitCode(const EmitArgs& args) override {
        const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcessor>();
        GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
        if (PorterDuffXferProcessor::kCustom_PrimaryOutputType != xp.primaryOutputType()) {
            SkASSERT(!xp.willReadDstColor());
            switch(xp.secondaryOutputType()) {
                case PorterDuffXferProcessor::kNone_SecondaryOutputType:
                    break;
                case PorterDuffXferProcessor::kCoverage_SecondaryOutputType:
                    fsBuilder->codeAppendf("%s = %s;", args.fOutputSecondary,
                                           args.fInputCoverage);
                    break;
                case PorterDuffXferProcessor::kCoverageISA_SecondaryOutputType:
                    fsBuilder->codeAppendf("%s = (1.0 - %s.a) * %s;",
                                           args.fOutputSecondary, args.fInputColor,
                                           args.fInputCoverage);
                    break;
                case PorterDuffXferProcessor::kCoverageISC_SecondaryOutputType:
                    fsBuilder->codeAppendf("%s = (vec4(1.0) - %s) * %s;",
                                           args.fOutputSecondary, args.fInputColor,
                                           args.fInputCoverage);
                    break;
                default:
                    SkFAIL("Unexpected Secondary Output");
            }

            switch (xp.primaryOutputType()) {
                case PorterDuffXferProcessor::kNone_PrimaryOutputType:
                    fsBuilder->codeAppendf("%s = vec4(0);", args.fOutputPrimary);
                    break;
                case PorterDuffXferProcessor::kColor_PrimaryOutputType:
                    fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputColor);
                    break;
                case PorterDuffXferProcessor::kCoverage_PrimaryOutputType:
                    fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputCoverage);
                    break;
                case PorterDuffXferProcessor::kModulate_PrimaryOutputType:
                    fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInputColor,
                                           args.fInputCoverage);
                    break;
                default:
                    SkFAIL("Unexpected Primary Output");
            }
        } else {
            SkASSERT(xp.willReadDstColor());

            const char* dstColor = fsBuilder->dstColor();

            fsBuilder->codeAppend("vec4 colorBlend =");
            // append src blend
            bool didAppend = append_porterduff_term(fsBuilder, xp.getSrcBlend(),
                                                    args.fInputColor, args.fInputColor,
                                                    dstColor, false);
            // append dst blend
            SkAssertResult(append_porterduff_term(fsBuilder, xp.getDstBlend(),
                                                  dstColor, args.fInputColor,
                                                  dstColor, didAppend));
            fsBuilder->codeAppend(";");

            fsBuilder->codeAppendf("%s = %s * colorBlend + (vec4(1.0) - %s) * %s;",
                                   args.fOutputPrimary, args.fInputCoverage, args.fInputCoverage,
                                   dstColor);
        }
    }