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

#include "GrOptDrawState.h"

#include "GrDrawState.h"
#include "GrDrawTargetCaps.h"

GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
                               BlendOptFlags blendOptFlags,
                               GrBlendCoeff optSrcCoeff,
                               GrBlendCoeff optDstCoeff,
                               const GrDrawTargetCaps& caps) {
    fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()),
                              GrIORef::kWrite_IOType);
    fColor = drawState.getColor();
    fCoverage = drawState.getCoverage();
    fViewMatrix = drawState.getViewMatrix();
    fBlendConstant = drawState.getBlendConstant();
    fFlagBits = drawState.getFlagBits();
    fVAPtr = drawState.getVertexAttribs();
    fVACount = drawState.getVertexAttribCount();
    fVAStride = drawState.getVertexStride();
    fStencilSettings = drawState.getStencil();
    fDrawFace = (DrawFace)drawState.getDrawFace();
    fBlendOptFlags = blendOptFlags;
    fSrcBlend = optSrcCoeff;
    fDstBlend = optDstCoeff;

    memcpy(fFixedFunctionVertexAttribIndices,
           drawState.getFixedFunctionVertexAttribIndices(),
           sizeof(fFixedFunctionVertexAttribIndices));

    fInputColorIsUsed = true;
    fInputCoverageIsUsed = true;

    int firstColorStageIdx = 0;
    int firstCoverageStageIdx = 0;
    bool separateCoverageFromColor;

    uint8_t fixedFunctionVAToRemove = 0;

    this->computeEffectiveColorStages(drawState, &firstColorStageIdx, &fixedFunctionVAToRemove);
    this->computeEffectiveCoverageStages(drawState, &firstCoverageStageIdx);
    this->adjustFromBlendOpts(drawState, &firstColorStageIdx, &firstCoverageStageIdx,
                              &fixedFunctionVAToRemove);
    // Should not be setting any more FFVA to be removed at this point
    this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove);
    this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx);
    this->setOutputStateInfo(drawState, caps, firstCoverageStageIdx, &separateCoverageFromColor);

    // Copy GeometryProcesssor from DS or ODS
    if (drawState.hasGeometryProcessor()) {
        fGeometryProcessor.reset(SkNEW_ARGS(GrGeometryStage, (*drawState.getGeometryProcessor())));
    } else {
        fGeometryProcessor.reset(NULL);
    }

    // Copy Color Stages from DS to ODS
    if (firstColorStageIdx < drawState.numColorStages()) {
        fColorStages.reset(&drawState.getColorStage(firstColorStageIdx),
                           drawState.numColorStages() - firstColorStageIdx);
    } else {
        fColorStages.reset();
    }

    // Copy Coverage Stages from DS to ODS
    if (drawState.numCoverageStages() > 0 && separateCoverageFromColor) {
        fCoverageStages.reset(&drawState.getCoverageStage(firstCoverageStageIdx),
                              drawState.numCoverageStages() - firstCoverageStageIdx);
    } else {
        fCoverageStages.reset();
        if (drawState.numCoverageStages() > 0) {
            // TODO: Once we have flag to know if we only multiply on stages, only push coverage
            // into color stages if everything is multiply
            fColorStages.push_back_n(drawState.numCoverageStages() - firstCoverageStageIdx,
                                     &drawState.getCoverageStage(firstCoverageStageIdx));
        }
    }
};
<commit_msg>Fix conditional check when copying coverage stages in ODS<commit_after>/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrOptDrawState.h"

#include "GrDrawState.h"
#include "GrDrawTargetCaps.h"

GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
                               BlendOptFlags blendOptFlags,
                               GrBlendCoeff optSrcCoeff,
                               GrBlendCoeff optDstCoeff,
                               const GrDrawTargetCaps& caps) {
    fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()),
                              GrIORef::kWrite_IOType);
    fColor = drawState.getColor();
    fCoverage = drawState.getCoverage();
    fViewMatrix = drawState.getViewMatrix();
    fBlendConstant = drawState.getBlendConstant();
    fFlagBits = drawState.getFlagBits();
    fVAPtr = drawState.getVertexAttribs();
    fVACount = drawState.getVertexAttribCount();
    fVAStride = drawState.getVertexStride();
    fStencilSettings = drawState.getStencil();
    fDrawFace = (DrawFace)drawState.getDrawFace();
    fBlendOptFlags = blendOptFlags;
    fSrcBlend = optSrcCoeff;
    fDstBlend = optDstCoeff;

    memcpy(fFixedFunctionVertexAttribIndices,
           drawState.getFixedFunctionVertexAttribIndices(),
           sizeof(fFixedFunctionVertexAttribIndices));

    fInputColorIsUsed = true;
    fInputCoverageIsUsed = true;

    int firstColorStageIdx = 0;
    int firstCoverageStageIdx = 0;
    bool separateCoverageFromColor;

    uint8_t fixedFunctionVAToRemove = 0;

    this->computeEffectiveColorStages(drawState, &firstColorStageIdx, &fixedFunctionVAToRemove);
    this->computeEffectiveCoverageStages(drawState, &firstCoverageStageIdx);
    this->adjustFromBlendOpts(drawState, &firstColorStageIdx, &firstCoverageStageIdx,
                              &fixedFunctionVAToRemove);
    // Should not be setting any more FFVA to be removed at this point
    this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove);
    this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx);
    this->setOutputStateInfo(drawState, caps, firstCoverageStageIdx, &separateCoverageFromColor);

    // Copy GeometryProcesssor from DS or ODS
    if (drawState.hasGeometryProcessor()) {
        fGeometryProcessor.reset(SkNEW_ARGS(GrGeometryStage, (*drawState.getGeometryProcessor())));
    } else {
        fGeometryProcessor.reset(NULL);
    }

    // Copy Color Stages from DS to ODS
    if (firstColorStageIdx < drawState.numColorStages()) {
        fColorStages.reset(&drawState.getColorStage(firstColorStageIdx),
                           drawState.numColorStages() - firstColorStageIdx);
    } else {
        fColorStages.reset();
    }

    // Copy Coverage Stages from DS to ODS
    if (firstCoverageStageIdx < drawState.numCoverageStages() && separateCoverageFromColor) {
        fCoverageStages.reset(&drawState.getCoverageStage(firstCoverageStageIdx),
                              drawState.numCoverageStages() - firstCoverageStageIdx);
    } else {
        fCoverageStages.reset();
        if (firstCoverageStageIdx < drawState.numCoverageStages()) {
            // TODO: Once we have flag to know if we only multiply on stages, only push coverage
            // into color stages if everything is multiply
            fColorStages.push_back_n(drawState.numCoverageStages() - firstCoverageStageIdx,
                                     &drawState.getCoverageStage(firstCoverageStageIdx));
        }
    }
};

{'fraction_non_alphanumeric': 0.08309859154929577, 'fraction_numerical': 0.0025352112676056337, 'mean_word_length': 3.0232294617563737, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4197304', 'n_tokens_mistral': 2093, 'n_tokens_neox': 2022, 'n_words': 388}