<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 "gm.h"
#if SK_SUPPORT_GPU
#include "GrTest.h"
#include "effects/GrRRectEffect.h"
#endif
#include "SkDevice.h"
#include "SkRRect.h"

namespace skiagm {

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

class RRectGM : public GM {
public:
    enum Type {
        kBW_Draw_Type,
        kAA_Draw_Type,
        kBW_Clip_Type,
        kAA_Clip_Type,
        kEffect_Type,
    };
    RRectGM(Type type) : fType(type) {
        this->setBGColor(0xFFDDDDDD);
        this->setUpRRects();
    }

protected:
    SkString onShortName() SK_OVERRIDE {
        SkString name("rrect");
        switch (fType) {
            case kBW_Draw_Type:
                name.append("_draw_bw");
                break;
            case kAA_Draw_Type:
                name.append("_draw_aa");
                break;
            case kBW_Clip_Type:
                name.append("_clip_bw");
                break;
            case kAA_Clip_Type:
                name.append("_clip_aa");
                break;
            case kEffect_Type:
                name.append("_effect");
                break;
        }
        return name;
    }

    virtual SkISize onISize() SK_OVERRIDE { return make_isize(kImageWidth, kImageHeight); }

    virtual uint32_t onGetFlags() const SK_OVERRIDE {
        if (kEffect_Type == fType) {
            return kGPUOnly_Flag;
        } else {
            return 0;
        }
    }

    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
#if SK_SUPPORT_GPU
        SkBaseDevice* device = canvas->getTopDevice();
        GrContext* context = NULL;
        GrRenderTarget* rt = device->accessRenderTarget();
        if (NULL != rt) {
            context = rt->getContext();
        }
        if (kEffect_Type == fType && NULL == context) {
            return;
        }
#endif

        SkPaint paint;
        if (kAA_Draw_Type == fType) {
            paint.setAntiAlias(true);
        }

        static const SkRect kMaxTileBound = SkRect::MakeWH(SkIntToScalar(kTileX),
                                                           SkIntToScalar(kTileY));
#ifdef SK_DEBUG
        static const SkRect kMaxImageBound = SkRect::MakeWH(SkIntToScalar(kImageWidth),
                                                            SkIntToScalar(kImageHeight));
#endif

        int lastEdgeType = (kEffect_Type == fType) ? kLast_GrEffectEdgeType: 0;

        int y = 1;
        for (int et = (GrEffectEdgeType) 0; et <= lastEdgeType; ++et) {
            int x = 1;
            for (int curRRect = 0; curRRect < kNumRRects; ++curRRect) {
                bool drew = true;
#ifdef SK_DEBUG
                SkASSERT(kMaxTileBound.contains(fRRects[curRRect].getBounds()));
                SkRect imageSpaceBounds = fRRects[curRRect].getBounds();
                imageSpaceBounds.offset(SkIntToScalar(x), SkIntToScalar(y));
                SkASSERT(kMaxImageBound.contains(imageSpaceBounds));
#endif
                canvas->save();
                    canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
                    if (kEffect_Type == fType) {
#if SK_SUPPORT_GPU
                        GrTestTarget tt;
                        context->getTestTarget(&tt);
                        if (NULL == tt.target()) {
                            SkDEBUGFAIL("Couldn't get Gr test target.");
                            return;
                        }
                        GrDrawState* drawState = tt.target()->drawState();

                        SkRRect rrect = fRRects[curRRect];
                        rrect.offset(SkIntToScalar(x), SkIntToScalar(y));
                        GrEffectEdgeType edgeType = (GrEffectEdgeType) et;
                        SkAutoTUnref<GrEffectRef> effect(GrRRectEffect::Create(edgeType, rrect));
                        if (effect) {
                            drawState->addCoverageEffect(effect);
                            drawState->setIdentityViewMatrix();<commit_msg>Fix no GPU build after r13728<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 "gm.h"
#if SK_SUPPORT_GPU
#include "GrTest.h"
#include "effects/GrRRectEffect.h"
#endif
#include "SkDevice.h"
#include "SkRRect.h"

namespace skiagm {

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

class RRectGM : public GM {
public:
    enum Type {
        kBW_Draw_Type,
        kAA_Draw_Type,
        kBW_Clip_Type,
        kAA_Clip_Type,
        kEffect_Type,
    };
    RRectGM(Type type) : fType(type) {
        this->setBGColor(0xFFDDDDDD);
        this->setUpRRects();
    }

protected:
    SkString onShortName() SK_OVERRIDE {
        SkString name("rrect");
        switch (fType) {
            case kBW_Draw_Type:
                name.append("_draw_bw");
                break;
            case kAA_Draw_Type:
                name.append("_draw_aa");
                break;
            case kBW_Clip_Type:
                name.append("_clip_bw");
                break;
            case kAA_Clip_Type:
                name.append("_clip_aa");
                break;
            case kEffect_Type:
                name.append("_effect");
                break;
        }
        return name;
    }

    virtual SkISize onISize() SK_OVERRIDE { return make_isize(kImageWidth, kImageHeight); }

    virtual uint32_t onGetFlags() const SK_OVERRIDE {
        if (kEffect_Type == fType) {
            return kGPUOnly_Flag;
        } else {
            return 0;
        }
    }

    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
#if SK_SUPPORT_GPU
        SkBaseDevice* device = canvas->getTopDevice();
        GrContext* context = NULL;
        GrRenderTarget* rt = device->accessRenderTarget();
        if (NULL != rt) {
            context = rt->getContext();
        }
        if (kEffect_Type == fType && NULL == context) {
            return;
        }
#endif

        SkPaint paint;
        if (kAA_Draw_Type == fType) {
            paint.setAntiAlias(true);
        }

        static const SkRect kMaxTileBound = SkRect::MakeWH(SkIntToScalar(kTileX),
                                                           SkIntToScalar(kTileY));
#ifdef SK_DEBUG
        static const SkRect kMaxImageBound = SkRect::MakeWH(SkIntToScalar(kImageWidth),
                                                            SkIntToScalar(kImageHeight));
#endif

#if SK_SUPPORT_GPU
        int lastEdgeType = (kEffect_Type == fType) ? kLast_GrEffectEdgeType: 0;
#else
        int lastEdgeType = 0;
#endif

        int y = 1;
        for (int et = 0; et <= lastEdgeType; ++et) {
            int x = 1;
            for (int curRRect = 0; curRRect < kNumRRects; ++curRRect) {
                bool drew = true;
#ifdef SK_DEBUG
                SkASSERT(kMaxTileBound.contains(fRRects[curRRect].getBounds()));
                SkRect imageSpaceBounds = fRRects[curRRect].getBounds();
                imageSpaceBounds.offset(SkIntToScalar(x), SkIntToScalar(y));
                SkASSERT(kMaxImageBound.contains(imageSpaceBounds));
#endif
                canvas->save();
                    canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
                    if (kEffect_Type == fType) {
#if SK_SUPPORT_GPU
                        GrTestTarget tt;
                        context->getTestTarget(&tt);
                        if (NULL == tt.target()) {
                            SkDEBUGFAIL("Couldn't get Gr test target.");
                            return;
                        }
                        GrDrawState* drawState = tt.target()->drawState();

                        SkRRect rrect = fRRects[curRRect];
                        rrect.offset(SkIntToScalar(x), SkIntToScalar(y));
                        GrEffectEdgeType edgeType = (GrEffectEdgeType) et;
                        SkAutoTUnref<GrEffectRef> effect(GrRRectEffect::Create(edgeType, rrect));
                        if (effect) {
                            drawState->addCoverageEffect(effect);
                            drawState->setIdentityViewMatrix();
{'fraction_non_alphanumeric': 0.11374924288310115, 'fraction_numerical': 0.0038764385221078134, 'mean_word_length': 1.536405529953917, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '6666117', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2273, 'n_words': 478}