<commit_before>/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrConfigConversionEffect.h"
#include "gl/GrGLProgramStage.h"

class GrGLConfigConversionEffect : public GrGLProgramStage {
public:
    GrGLConfigConversionEffect(const GrProgramStageFactory& factory,
                               const GrCustomStage& s) : INHERITED (factory) {
        const GrConfigConversionEffect& stage = static_cast<const GrConfigConversionEffect&>(s);
        fSwapRedAndBlue = stage.swapsRedAndBlue();
        fPMConversion = stage.pmConversion();
    }

    virtual void emitVS(GrGLShaderBuilder* builder,
                        const char* vertexCoords) SK_OVERRIDE { }
    virtual void emitFS(GrGLShaderBuilder* builder,
                        const char* outputColor,
                        const char* inputColor,
                        const char* samplerName) SK_OVERRIDE {
        builder->fFSCode.append("\tvec4 tempColor;\n");
        builder->emitDefaultFetch("tempColor", samplerName);
        if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) {
            GrAssert(fSwapRedAndBlue);
            builder->fFSCode.appendf("\t%s = tempColor.bgra;\n", outputColor);
        } else {
            const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb";
            switch (fPMConversion) {
                case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion:
                    builder->fFSCode.appendf(
                        "\t%s = vec4(ceil(tempColor.%s*tempColor.a*255.0)/255.0, tempColor.a);\n",
                         outputColor, swiz);
                    break;
                case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversion:
                    builder->fFSCode.appendf(
                        "\t%s = vec4(floor(tempColor.%s*tempColor.a*255.0)/255.0, tempColor.a);\n",
                         outputColor, swiz);
                    break;
                case GrConfigConversionEffect::kDivByAlpha_RoundUp_PMConversion:
                    builder->fFSCode.appendf("\t%s = tempColor.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(tempColor.%s / tempColor.a * 255.0)/255.0, tempColor.a);\n",
                        outputColor, swiz);
                    break;
                case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversion:
                    builder->fFSCode.appendf("\t%s = tempColor.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(tempColor.%s / tempColor.a * 255.0)/255.0, tempColor.a);\n",
                        outputColor, swiz);
                    break;
            }
        }
    }

    static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps&) {
        const GrConfigConversionEffect& stage = static_cast<const GrConfigConversionEffect&>(s);
        return static_cast<int>(stage.swapsRedAndBlue()) | (stage.pmConversion() << 1);
    }

private:
    bool                                    fSwapRedAndBlue;
    GrConfigConversionEffect::PMConversion  fPMConversion;

    typedef GrGLProgramStage INHERITED;

};

///////////////////////////////////////////////////////////////////////////////

GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture,
                                                   bool swapRedAndBlue,<commit_msg>Added default to switch to stop compiler failure in Chrome (unreviewed)<commit_after>/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrConfigConversionEffect.h"
#include "gl/GrGLProgramStage.h"

class GrGLConfigConversionEffect : public GrGLProgramStage {
public:
    GrGLConfigConversionEffect(const GrProgramStageFactory& factory,
                               const GrCustomStage& s) : INHERITED (factory) {
        const GrConfigConversionEffect& stage = static_cast<const GrConfigConversionEffect&>(s);
        fSwapRedAndBlue = stage.swapsRedAndBlue();
        fPMConversion = stage.pmConversion();
    }

    virtual void emitVS(GrGLShaderBuilder* builder,
                        const char* vertexCoords) SK_OVERRIDE { }
    virtual void emitFS(GrGLShaderBuilder* builder,
                        const char* outputColor,
                        const char* inputColor,
                        const char* samplerName) SK_OVERRIDE {
        builder->fFSCode.append("\tvec4 tempColor;\n");
        builder->emitDefaultFetch("tempColor", samplerName);
        if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) {
            GrAssert(fSwapRedAndBlue);
            builder->fFSCode.appendf("\t%s = tempColor.bgra;\n", outputColor);
        } else {
            const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb";
            switch (fPMConversion) {
                case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion:
                    builder->fFSCode.appendf(
                        "\t%s = vec4(ceil(tempColor.%s*tempColor.a*255.0)/255.0, tempColor.a);\n",
                         outputColor, swiz);
                    break;
                case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversion:
                    builder->fFSCode.appendf(
                        "\t%s = vec4(floor(tempColor.%s*tempColor.a*255.0)/255.0, tempColor.a);\n",
                         outputColor, swiz);
                    break;
                case GrConfigConversionEffect::kDivByAlpha_RoundUp_PMConversion:
                    builder->fFSCode.appendf("\t%s = tempColor.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(tempColor.%s / tempColor.a * 255.0)/255.0, tempColor.a);\n",
                        outputColor, swiz);
                    break;
                case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversion:
                    builder->fFSCode.appendf("\t%s = tempColor.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(tempColor.%s / tempColor.a * 255.0)/255.0, tempColor.a);\n",
                        outputColor, swiz);
                    break;
                default:
                    GrCrash("Unknown conversion op.");
                    break;
            }
        }
    }

    static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps&) {
        const GrConfigConversionEffect& stage = static_cast<const GrConfigConversionEffect&>(s);
        return static_cast<int>(stage.swapsRedAndBlue()) | (stage.pmConversion() << 1);
    }

private:
    bool                                    fSwapRedAndBlue;
    GrConfigConversionEffect::PMConversion  fPMConversion;

    typedef GrGLProgramStage INHERITED;

};

///////////////////////////////////////////////////////////////////////////////

GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture,
                                                   bool swapRedAndBlue,
{'fraction_non_alphanumeric': 0.12097361900597581, 'fraction_numerical': 0.016324150998396736, 'mean_word_length': 1.9212430821626223, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6805965', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1878, 'n_words': 344}