<commit_before>#include "rpi.h"

#include "bcm_host.h"

#include <linux/input.h>
#include <dirent.h>
#include <stdio.h>

#define DEBUG_GLES false
#define DEBUG_RENDER false
#define DEBUG_INPUT false

#define test_bit(bit, array) (array[bit / 8] & (1 << (bit % 8)))

/**
 * Raspberry Pi AminoGfx implementation.
 */
class AminoGfxRPi : public AminoGfx {
public:
    AminoGfxRPi(): AminoGfx(getFactory()->name) {
        //empty
    }

    /**
     * Get factory instance.
     */
    static AminoGfxRPiFactory* getFactory() {
        static AminoGfxRPiFactory *instance = NULL;

        if (!instance) {
            instance = new AminoGfxRPiFactory(New);
        }

        return instance;
    }

    /**
     * Add class template to module exports.
     */
    static NAN_MODULE_INIT(Init) {
        AminoGfxRPiFactory *factory = getFactory();

        AminoGfx::Init(target, factory);
    }

private:
    static int instanceCount;
    static bool glESInitialized;

    //OpenGL ES
    EGLDisplay display = EGL_NO_DISPLAY;
    EGLContext context = EGL_NO_CONTEXT;
    EGLSurface surface = EGL_NO_SURFACE;
    EGLConfig config;
    uint32_t screenW = 0;
    uint32_t screenH = 0;

    //input
    std::vector<int> fds;
    int mouse_x = 0;
    int mouse_y = 0;

    /**
     * JS object construction.
     */
    static NAN_METHOD(New) {
        AminoJSObject::createInstance(info, getFactory());
    }

    /**
     * Setup JS instance.
     */
    void setup() override {
        if (DEBUG_GLES) {
            printf("AminoGfxRPi.setup()\n");
        }

        //init OpenGL ES
        if (!glESInitialized) {
            //VideoCore IV
            bcm_host_init();

            glESInitialized = true;
        }

        instanceCount++;

        //basic EGL to get screen size
        initEGL();

        //base class
        AminoGfx::setup();
    }

    /**
     * Initialize EGL and get display size.
     */
    void initEGL() {
        //get an EGL display connection
        display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

        assert(display != EGL_NO_DISPLAY);

        //initialize the EGL display connection
        EGLBoolean res = eglInitialize(display, NULL, NULL);

        assert(EGL_FALSE != res);

        //get an appropriate EGL frame buffer configuration
        //this uses a BRCM extension that gets the closest match, rather than standard which returns anything that matches
        static const EGLint attribute_list[] = {
            //RGBA
            EGL_RED_SIZE, 8,
            EGL_GREEN_SIZE, 8,
            EGL_BLUE_SIZE, 8,
            EGL_ALPHA_SIZE, 8,

            //OpenGL ES 2.0
            EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,

            //buffers
            EGL_STENCIL_SIZE, 8,
            EGL_DEPTH_SIZE, 16,

            //sampling (quality)
            EGL_SAMPLE_BUFFERS, 1,
            EGL_SAMPLES, 1, //cbx 4, //4x MSAA
//cbx add flag
            //window
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,

            EGL_NONE
        };

        EGLint num_config;

        res = eglSaneChooseConfigBRCM(display, attribute_list, &config, 1, &num_config);

        assert(EGL_FALSE != res);

        //choose OpenGL ES 2
        res = eglBindAPI(EGL_OPENGL_ES_API);

        assert(EGL_FALSE != res);
<commit_msg>switched to flag<commit_after>#include "rpi.h"

#include "bcm_host.h"

#include <linux/input.h>
#include <dirent.h>
#include <stdio.h>

#define DEBUG_GLES false
#define DEBUG_RENDER false
#define DEBUG_INPUT false

#define AMINO_EGL_SAMPLES 4
#define test_bit(bit, array) (array[bit / 8] & (1 << (bit % 8)))

/**
 * Raspberry Pi AminoGfx implementation.
 */
class AminoGfxRPi : public AminoGfx {
public:
    AminoGfxRPi(): AminoGfx(getFactory()->name) {
        //empty
    }

    /**
     * Get factory instance.
     */
    static AminoGfxRPiFactory* getFactory() {
        static AminoGfxRPiFactory *instance = NULL;

        if (!instance) {
            instance = new AminoGfxRPiFactory(New);
        }

        return instance;
    }

    /**
     * Add class template to module exports.
     */
    static NAN_MODULE_INIT(Init) {
        AminoGfxRPiFactory *factory = getFactory();

        AminoGfx::Init(target, factory);
    }

private:
    static int instanceCount;
    static bool glESInitialized;

    //OpenGL ES
    EGLDisplay display = EGL_NO_DISPLAY;
    EGLContext context = EGL_NO_CONTEXT;
    EGLSurface surface = EGL_NO_SURFACE;
    EGLConfig config;
    uint32_t screenW = 0;
    uint32_t screenH = 0;

    //input
    std::vector<int> fds;
    int mouse_x = 0;
    int mouse_y = 0;

    /**
     * JS object construction.
     */
    static NAN_METHOD(New) {
        AminoJSObject::createInstance(info, getFactory());
    }

    /**
     * Setup JS instance.
     */
    void setup() override {
        if (DEBUG_GLES) {
            printf("AminoGfxRPi.setup()\n");
        }

        //init OpenGL ES
        if (!glESInitialized) {
            //VideoCore IV
            bcm_host_init();

            glESInitialized = true;
        }

        instanceCount++;

        //basic EGL to get screen size
        initEGL();

        //base class
        AminoGfx::setup();
    }

    /**
     * Initialize EGL and get display size.
     */
    void initEGL() {
        //get an EGL display connection
        display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

        assert(display != EGL_NO_DISPLAY);

        //initialize the EGL display connection
        EGLBoolean res = eglInitialize(display, NULL, NULL);

        assert(EGL_FALSE != res);

        //get an appropriate EGL frame buffer configuration
        //this uses a BRCM extension that gets the closest match, rather than standard which returns anything that matches
        static const EGLint attribute_list[] = {
            //RGBA
            EGL_RED_SIZE, 8,
            EGL_GREEN_SIZE, 8,
            EGL_BLUE_SIZE, 8,
            EGL_ALPHA_SIZE, 8,

            //OpenGL ES 2.0
            EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,

            //buffers
            EGL_STENCIL_SIZE, 8,
            EGL_DEPTH_SIZE, 16,

            //sampling (quality)
            EGL_SAMPLE_BUFFERS, 1,
            EGL_SAMPLES, AMINO_EGL_SAMPLES, //4: 4x MSAA

            //window
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,

            EGL_NONE
        };

        EGLint num_config;

        res = eglSaneChooseConfigBRCM(display, attribute_list, &config, 1, &num_config);

        assert(EGL_FALSE != res);

        //choose OpenGL ES 2
        res = eglBindAPI(EGL_OPENGL_ES_API);

        assert(EGL_FALSE != res);

{'fraction_non_alphanumeric': 0.09864308583625553, 'fraction_numerical': 0.0082329623418204, 'mean_word_length': 1.9536244934714093, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '704060', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2111, 'n_words': 507}