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



#include "Test.h"
// This is a GPU-backend specific test
#if SK_SUPPORT_GPU

#if SK_ANGLE
#include "gl/SkANGLEGLContext.h"
#endif
#include "gl/SkNativeGLContext.h"
#if SK_MESA
#include "gl/SkMesaGLContext.h"
#endif

static void GLInterfaceValidationTest(skiatest::Reporter* reporter) {
    typedef const GrGLInterface* (*interfaceFactory)();
    struct {
       interfaceFactory fFactory;
       const char* fName;
    } interfaceFactories[] = {
#if SK_ANGLE
        {GrGLCreateANGLEInterface, "ANGLE"},
#endif
        {GrGLCreateNativeInterface, "Native"},
#if SK_MESA
        {GrGLCreateMesaInterface, "Mesa"},
#endif
        {GrGLCreateDebugInterface, "Debug"},
        {GrGLCreateNullInterface, "Null"},
    };

    static const int kBogusSize = 16;

#if SK_ANGLE
    SkANGLEGLContext::AutoContextRestore angleACR;
    SkANGLEGLContext angleContext;
    bool angleContextInit = angleContext.init(kBogusSize, kBogusSize);
    REPORTER_ASSERT(reporter, angleContextInit);
    if (!angleContextInit) {
        return;
    }
#endif

    // On some platforms GrGLCreateNativeInterface will fail unless an OpenGL
    // context has been created. Also, preserve the current context that may
    // be in use by outer test harness.
    SkNativeGLContext::AutoContextRestore nglACR;
    SkNativeGLContext nglctx;
    bool nativeContextInit = nglctx.init(kBogusSize, kBogusSize);
    REPORTER_ASSERT(reporter, nativeContextInit);
    if (!nativeContextInit) {
        return;
    }

#if SK_MESA
    // We must have a current OSMesa context to initialize an OSMesa
    // GrGLInterface
    SkMesaGLContext::AutoContextRestore mglACR;
    SkMesaGLContext mglctx;
    bool mesaContextInit = mglctx.init(kBogusSize, kBogusSize);
    REPORTER_ASSERT(reporter, mesaContextInit);
    if(!mesaContextInit) {
        return;
    }
#endif

    SkAutoTUnref<const GrGLInterface> iface;
    for (size_t i = 0; i < SK_ARRAY_COUNT(interfaceFactories); ++i) {
        iface.reset(interfaceFactories[i].fFactory());
        REPORTER_ASSERT(reporter, NULL != iface.get());
        if (iface.get()) {
            for (GrGLBinding binding = kFirstGrGLBinding;
                 binding <= kLastGrGLBinding;
                 binding = static_cast<GrGLBinding>(binding << 1)) {
                if (iface.get()->fBindingsExported & binding) {
                    REPORTER_ASSERT(reporter, iface.get()->validate(binding));
                }
            }
        }
    }
}


#include "TestClassDef.h"
DEFINE_TESTCLASS("GLInterfaceValidation",
                 GLInterfaceValidationTestClass,
                 GLInterfaceValidationTest)

#endif<commit_msg>Simplify the GL interface validation test. Review URL: https://codereview.chromium.org/12703003<commit_after>
/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */



#include "Test.h"
// This is a GPU-backend specific test
#if SK_SUPPORT_GPU

#include "GrContextFactory.h"

static void GLInterfaceValidationTest(skiatest::Reporter* reporter, GrContextFactory* factory) {
    for (int i = 0; i <= GrContextFactory::kLastGLContextType; ++i) {
        GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType)i;
        // this forces the factory to make the context if it hasn't yet
        factory->get(glCtxType);
        SkGLContextHelper* glCtxHelper = factory->getGLContext(glCtxType);
        REPORTER_ASSERT(reporter, NULL != glCtxHelper);
        if (NULL != glCtxHelper) {
            const GrGLInterface* interface = glCtxHelper->gl();
            for (GrGLBinding binding = kFirstGrGLBinding;
                 binding <= kLastGrGLBinding;
                 binding = static_cast<GrGLBinding>(binding << 1)) {
                if (interface->fBindingsExported & binding) {
                    REPORTER_ASSERT(reporter, interface->validate(binding));
                }
            }
        }
    }
}


#include "TestClassDef.h"
DEFINE_GPUTESTCLASS("GLInterfaceValidation",
                    GLInterfaceValidationTestClass,
                    GLInterfaceValidationTest)

#endif
{'fraction_non_alphanumeric': 0.0950046685340803, 'fraction_numerical': 0.005135387488328665, 'mean_word_length': 2.9712696941612604, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3844947', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1265, 'n_words': 306}