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



#include "GrAtlas.h"
#include "GrDefaultTextContext.h"
#include "GrContext.h"
#include "GrDrawTarget.h"
#include "GrFontScaler.h"
#include "GrGpuVertex.h"
#include "GrTemplates.h"
#include "GrTextStrike.h"
#include "GrTextStrike_impl.h"

void GrDefaultTextContext::flushGlyphs() {
    GrAssert(this->isValid());
    if (fCurrVertex > 0) {
        GrDrawTarget::AutoStateRestore asr(fDrawTarget);
        GrDrawState* drawState = fDrawTarget->drawState();
        // setup our sampler state for our text texture/atlas
        GrSamplerState::Filter filter;
        if (fExtMatrix.isIdentity()) {
            filter = GrSamplerState::kNearest_Filter;
        } else {
            filter = GrSamplerState::kBilinear_Filter;
        }
        drawState->sampler(kGlyphMaskStage)->reset(
            GrSamplerState::kRepeat_WrapMode,filter);

        GrAssert(GrIsALIGN4(fCurrVertex));
        int nIndices = fCurrVertex + (fCurrVertex >> 1);
        GrAssert(fCurrTexture);
        drawState->setTexture(kGlyphMaskStage, fCurrTexture);

        if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
            if (kOne_BlendCoeff != fGrPaint.fSrcBlendCoeff ||
                kISA_BlendCoeff != fGrPaint.fDstBlendCoeff ||
                fGrPaint.hasTexture()) {
                GrPrintf("LCD Text will not draw correctly.\n");
            }
            // setup blend so that we get mask * paintColor + (1-mask)*dstColor
            drawState->setBlendConstant(fGrPaint.fColor);
            drawState->setBlendFunc(kConstC_BlendCoeff, kISC_BlendCoeff);
            // don't modulate by the paint's color in the frag since we're
            // already doing it via the blend const.
            drawState->setColor(0xffffffff);
        } else {
            // set back to normal in case we took LCD path previously.
            drawState->setBlendFunc(fGrPaint.fSrcBlendCoeff, fGrPaint.fDstBlendCoeff);
            drawState->setColor(fGrPaint.fColor);
        }

        fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());

        fDrawTarget->drawIndexed(kTriangles_PrimitiveType,
                                 0, 0, fCurrVertex, nIndices);
        fVertices = NULL;
        this->INHERITED::reset();
    }
}

GrDefaultTextContext::GrDefaultTextContext() {
}

GrDefaultTextContext::~GrDefaultTextContext() {
}

void GrDefaultTextContext::init(GrContext* context,
                                const GrPaint& paint,
                                const GrMatrix* extMatrix) {
    this->INHERITED::init(context, paint, extMatrix);

    fStrike = NULL;

    if (NULL != extMatrix) {
        fExtMatrix = *extMatrix;
    } else {
        fExtMatrix = GrMatrix::I();
    }
    if (context->getClip().hasConservativeBounds()) {
        if (!fExtMatrix.isIdentity()) {
            GrMatrix inverse;
            GrRect r = context->getClip().getConservativeBounds();
            if (fExtMatrix.invert(&inverse)) {
                inverse.mapRect(&r);
                r.roundOut(&fClipRect);
            }
        } else {
            context->getClip().getConservativeBounds().roundOut(&fClipRect);
        }
    } else {
        fClipRect.setLargest();
    }<commit_msg>Call reset() in text context rather than set to SkMatrix::I(). Perf improvement in bench.<commit_after>
/*
 * Copyright 2010 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */



#include "GrAtlas.h"
#include "GrDefaultTextContext.h"
#include "GrContext.h"
#include "GrDrawTarget.h"
#include "GrFontScaler.h"
#include "GrGpuVertex.h"
#include "GrTemplates.h"
#include "GrTextStrike.h"
#include "GrTextStrike_impl.h"

void GrDefaultTextContext::flushGlyphs() {
    GrAssert(this->isValid());
    if (fCurrVertex > 0) {
        GrDrawTarget::AutoStateRestore asr(fDrawTarget);
        GrDrawState* drawState = fDrawTarget->drawState();
        // setup our sampler state for our text texture/atlas
        GrSamplerState::Filter filter;
        if (fExtMatrix.isIdentity()) {
            filter = GrSamplerState::kNearest_Filter;
        } else {
            filter = GrSamplerState::kBilinear_Filter;
        }
        drawState->sampler(kGlyphMaskStage)->reset(
            GrSamplerState::kRepeat_WrapMode,filter);

        GrAssert(GrIsALIGN4(fCurrVertex));
        int nIndices = fCurrVertex + (fCurrVertex >> 1);
        GrAssert(fCurrTexture);
        drawState->setTexture(kGlyphMaskStage, fCurrTexture);

        if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
            if (kOne_BlendCoeff != fGrPaint.fSrcBlendCoeff ||
                kISA_BlendCoeff != fGrPaint.fDstBlendCoeff ||
                fGrPaint.hasTexture()) {
                GrPrintf("LCD Text will not draw correctly.\n");
            }
            // setup blend so that we get mask * paintColor + (1-mask)*dstColor
            drawState->setBlendConstant(fGrPaint.fColor);
            drawState->setBlendFunc(kConstC_BlendCoeff, kISC_BlendCoeff);
            // don't modulate by the paint's color in the frag since we're
            // already doing it via the blend const.
            drawState->setColor(0xffffffff);
        } else {
            // set back to normal in case we took LCD path previously.
            drawState->setBlendFunc(fGrPaint.fSrcBlendCoeff, fGrPaint.fDstBlendCoeff);
            drawState->setColor(fGrPaint.fColor);
        }

        fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());

        fDrawTarget->drawIndexed(kTriangles_PrimitiveType,
                                 0, 0, fCurrVertex, nIndices);
        fVertices = NULL;
        this->INHERITED::reset();
    }
}

GrDefaultTextContext::GrDefaultTextContext() {
}

GrDefaultTextContext::~GrDefaultTextContext() {
}

void GrDefaultTextContext::init(GrContext* context,
                                const GrPaint& paint,
                                const GrMatrix* extMatrix) {
    this->INHERITED::init(context, paint, extMatrix);

    fStrike = NULL;

    if (NULL != extMatrix) {
        fExtMatrix = *extMatrix;
    } else {
        fExtMatrix.reset();
    }
    if (context->getClip().hasConservativeBounds()) {
        if (!fExtMatrix.isIdentity()) {
            GrMatrix inverse;
            GrRect r = context->getClip().getConservativeBounds();
            if (fExtMatrix.invert(&inverse)) {
                inverse.mapRect(&r);
                r.roundOut(&fClipRect);
            }
        } else {
            context->getClip().getConservativeBounds().roundOut(&fClipRect);
        }
    } else {
        fClipRect.setLargest();
    }
{'fraction_non_alphanumeric': 0.10960118168389955, 'fraction_numerical': 0.0032496307237813884, 'mean_word_length': 2.407649723200805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '2248214', 'n_tokens_mistral': 2085, 'n_tokens_neox': 2021, 'n_words': 394}