Beispiel #1
0
static int32_t init_mouse (void)
{
    if (!ppb_input_event_interface) {
        ppb_input_event_interface =
            (PPB_InputEvent *) NaCl_GetInterface(PPB_INPUT_EVENT_INTERFACE);
    }
    ppb_mouse_event_interface =
            (PPB_MouseInputEvent *) NaCl_GetInterface(
                    PPB_MOUSE_INPUT_EVENT_INTERFACE);

    if (!ppb_input_event_interface) {
        DEBUG_LOG("Could not acquire PPB_InputEvent interface.\n");
        return 0;
    }
    if (!ppb_mouse_event_interface) {
        DEBUG_LOG("Could not acquire PPB_MouseInputEvent interface.\n");
        return 0;
    }
    return 1;
}
Beispiel #2
0
int setup_sound(void)
{
    ppb_audio_interface = (PPB_Audio *) NaCl_GetInterface(PPB_AUDIO_INTERFACE);
    ppb_audio_config_interface = (PPB_AudioConfig *)
        NaCl_GetInterface(PPB_AUDIO_CONFIG_INTERFACE);
    pp_instance = NaCl_GetInstance();

    if (!ppb_audio_interface) {
        write_log("Could not acquire PPB_Audio interface.\n");
        return 0;
    }
    if (!ppb_audio_config_interface) {
        write_log("Could not acquire PPB_AudioConfig interface.\n");
        return 0;
    }
    if (!pp_instance) {
        write_log("Could not find current Pepper instance.\n");
        return 0;
    }

    if (!init_sound()) return 0;
    close_sound();

    write_log("Pepper audio successfully set up.\n");
    write_log("Frequency: %d\n", currprefs.sound_freq);
    write_log("Stereo   : %d\n", currprefs.sound_stereo);
    write_log("Latency  : %d\n", currprefs.sound_latency);

    init_sound_table16();
    sample_handler = sample16s_handler;
    obtainedfreq = currprefs.sound_freq;
    have_sound = 1;
    sound_available = 1;
    update_sound (fake_vblank_hz, 1, currprefs.ntscmode);

    return sound_available;
}
Beispiel #3
0
static int init_joysticks (void) {
    ppb_gamepad_interface = (PPB_Gamepad *)
        NaCl_GetInterface(PPB_GAMEPAD_INTERFACE);
    pp_instance = NaCl_GetInstance();

    if (!ppb_gamepad_interface) {
        DEBUG_LOG("Could not acquire PPB_Gamepad interface.\n");
        return 0;
    }
    if (!pp_instance) {
        DEBUG_LOG("Could not find current Pepper instance.\n");
        return 0;
    }
    return 0;
}
Beispiel #4
0
static int32_t init_kb(void)
{
    if (!ppb_input_event_interface) {
        ppb_input_event_interface =
                (PPB_InputEvent *) NaCl_GetInterface(PPB_INPUT_EVENT_INTERFACE);
    }
    ppb_keyboard_event_interface =
            (PPB_KeyboardInputEvent *) NaCl_GetInterface(
                    PPB_KEYBOARD_INPUT_EVENT_INTERFACE);

    if (!ppb_input_event_interface) {
        DEBUG_LOG("Could not acquire PPB_InputEvent interface.\n");
        return 0;
    }
    if (!ppb_keyboard_event_interface) {
        DEBUG_LOG("Could not acquire PPB_KeyboardInputEvent interface.\n");
        return 0;
    }

    inputdevice_release_all_keys ();
    reset_hotkeys ();

    return 1;
}
Beispiel #5
0
int32_t graphics_2d_subinit(uint32_t *Rmask, uint32_t *Gmask, uint32_t *Bmask,
                        uint32_t *Amask) {
    /* Pepper Graphics2D setup. */
    ppb_instance_interface = (PPB_Instance *)
        NaCl_GetInterface(PPB_INSTANCE_INTERFACE);
    if (!ppb_instance_interface) {
        write_log("Could not acquire PPB_Instance interface.\n");
        return 0;
    }
    ppb_g2d_interface = (PPB_Graphics2D *)
        NaCl_GetInterface(PPB_GRAPHICS_2D_INTERFACE);
    if (!ppb_g2d_interface) {
        write_log("Could not acquire PPB_Graphics2D interface.\n");
        return 0;
    }
    ppb_core_interface = (PPB_Core *) NaCl_GetInterface(PPB_CORE_INTERFACE);
    if (!ppb_core_interface) {
        write_log("Could not acquire PPB_Core interface.\n");
        return 0;
    }
    ppb_image_data_interface = (PPB_ImageData *)
        NaCl_GetInterface(PPB_IMAGEDATA_INTERFACE);
    if (!ppb_image_data_interface) {
        write_log("Could not acquire PPB_ImageData interface.\n");
        return 0;
    }
    pp_instance = NaCl_GetInstance();
    if (!pp_instance) {
        write_log("Could not find current Pepper instance.\n");
        return 0;
    }

    screenSize.width = canvasSize.width = gfxvidinfo.width;
    screenSize.height = canvasSize.height = gfxvidinfo.height;
    src_rect.point = origo;
    src_rect.size = canvasSize;
    graphics_context =
            ppb_g2d_interface->Create(pp_instance,
                                      &screenSize,
                                      PP_TRUE /* is_always_opaque */);
    if (!graphics_context) {
        write_log("Could not obtain a PPB_Graphics2D context.\n");
        return 0;
    }
    if (!ppb_instance_interface->BindGraphics(pp_instance, graphics_context)) {
        write_log("Failed to bind context to instance.\n");
        return 0;
    }

    preferredFormat = ppb_image_data_interface->GetNativeImageDataFormat();
    switch (preferredFormat) {
    case PP_IMAGEDATAFORMAT_BGRA_PREMUL:
        *Rmask = 0x00FF0000, *Gmask = 0x0000FF00, *Bmask = 0x000000FF;
        *Amask = 0xFF000000;
        alpha_mask = *Amask;
        break;
    case PP_IMAGEDATAFORMAT_RGBA_PREMUL:
        *Rmask = 0x000000FF, *Gmask = 0x0000FF00, *Bmask = 0x00FF0000;
        *Amask = 0xFF000000;
        alpha_mask = *Amask;
        break;
    default:
        write_log("Unrecognized preferred image data format: %d.\n",
                  preferredFormat);
        return 0;
    }
    image_data = ppb_image_data_interface->Create(pp_instance, preferredFormat,
            &canvasSize, /* init_to_zero = */ PP_FALSE);
     if (!image_data) {
         write_log("Could not create image data.\n");
         return 0;
     }

    /* UAE gfxvidinfo setup. */
    gfxvidinfo.pixbytes = 4; /* 32-bit graphics */
    gfxvidinfo.rowbytes = gfxvidinfo.width * gfxvidinfo.pixbytes;
    gfxvidinfo.bufmem = (uint8_t *) ppb_image_data_interface->Map(image_data);
    gfxvidinfo.emergmem = 0;
    gfxvidinfo.flush_screen = pepper_graphics2d_flush_screen;

    graphics_initialized = 1;
    return 1;
}
Beispiel #6
0
int32_t graphics_3d_subinit(uint32_t *Rmask, uint32_t *Gmask, uint32_t *Bmask,
                        uint32_t *Amask) {
    /* Pepper Graphics3D setup. */
    PPB_Instance *ppb_instance_interface =
        (PPB_Instance *) NaCl_GetInterface(PPB_INSTANCE_INTERFACE);
    if (!ppb_instance_interface) {
        write_log("Could not acquire PPB_Instance interface.\n");
        return 0;
    }
    ppb_g3d_interface =
        (PPB_Graphics3D *) NaCl_GetInterface(PPB_GRAPHICS_3D_INTERFACE);
    if (!ppb_g3d_interface) {
        write_log("Could not acquire PPB_Graphics3D interface.\n");
        return 0;
    }
    pp_instance = NaCl_GetInstance();
    if (!pp_instance) {
        write_log("Could not find current Pepper instance.\n");
        return 0;
    }

    int32_t attribs[] = {
      PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
      PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
      PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
      PP_GRAPHICS3DATTRIB_SAMPLES, 0,
      PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
      PP_GRAPHICS3DATTRIB_WIDTH, gfxvidinfo.width,
      PP_GRAPHICS3DATTRIB_HEIGHT, gfxvidinfo.height,
      PP_GRAPHICS3DATTRIB_GPU_PREFERENCE,
          PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_PERFORMANCE,
      PP_GRAPHICS3DATTRIB_NONE
    };

    graphics_context = ppb_g3d_interface->Create(
            pp_instance,
            0 /* share_context */,
            attribs);
    if (!graphics_context) {
        write_log("Could not obtain a PPB_Graphics3D context.\n");
        return 0;
    }
    if (!ppb_instance_interface->BindGraphics(pp_instance, graphics_context)) {
        write_log("Failed to bind context to instance.\n");
        return 0;
    }
    glSetCurrentContextPPAPI(graphics_context);

    /* UAE gfxvidinfo setup. */
    /* TODO(cstefansen): Implement gfx double-buffering if perf. mandates it. */
    gfxvidinfo.pixbytes = 2; /* 16-bit graphics */
    gfxvidinfo.rowbytes = gfxvidinfo.width * gfxvidinfo.pixbytes;
    gfxvidinfo.bufmem =
            (uint8_t *) calloc(round_up_to_power_of_2(gfxvidinfo.rowbytes),
                              round_up_to_power_of_2(gfxvidinfo.height));
    gfxvidinfo.flush_screen = pepper_graphics3d_flush_screen;
    *Rmask = 0x0000F800, *Gmask = 0x000007E0, *Bmask = 0x0000001F, *Amask = 0;

    /* OpenGL ES setup. */
    glViewport(0, 0, gfxvidinfo.width, gfxvidinfo.height);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glDisable(GL_DEPTH_TEST);

    /* Uniform index. */
    enum {
        UNIFORM_VIDEOFRAME,
        UNIFORM_INPUTCOLOR,
        UNIFORM_THRESHOLD,
        NUM_UNIFORMS
    };
    GLint uniforms[NUM_UNIFORMS];

    /* Attribute index. */
    enum {
        ATTRIB_VERTEX,
        ATTRIB_TEXTUREPOSITON,
        NUM_ATTRIBUTES
    };

    static GLuint g_programObj;
    static GLuint g_textureID;

    char *g_VShaderData =
            "attribute vec4 position;"
            "attribute vec4 inputTextureCoordinate;"
            "varying vec2 textureCoordinate;"
            "void main()"
            "{"
            "gl_Position = position;"
            "textureCoordinate = inputTextureCoordinate.xy;"
            "}";

    char *g_FShaderData =
            "varying highp vec2 textureCoordinate;"
            "uniform sampler2D videoFrame;"
            "void main()"
            "{"
            "gl_FragColor = texture2D(videoFrame, textureCoordinate);"
            "}";

    GLuint g_vertexShader;
    GLuint g_fragmentShader;

    g_vertexShader = compileShader(GL_VERTEX_SHADER, g_VShaderData);
    g_fragmentShader = compileShader(GL_FRAGMENT_SHADER, g_FShaderData);

    g_programObj = glCreateProgram();
    glAttachShader(g_programObj, g_vertexShader);
    glAttachShader(g_programObj, g_fragmentShader);

    glBindAttribLocation(g_programObj, ATTRIB_VERTEX, "position");
    glBindAttribLocation(g_programObj, ATTRIB_TEXTUREPOSITON,
                         "inputTextureCoordinate");

    glLinkProgram(g_programObj);

    uniforms[UNIFORM_VIDEOFRAME] = glGetUniformLocation(g_programObj,
                                                        "videoFrame");
    uniforms[UNIFORM_INPUTCOLOR] = glGetUniformLocation(g_programObj,
                                                        "inputColor");
    uniforms[UNIFORM_THRESHOLD] = glGetUniformLocation(g_programObj,
                                                       "threshold");

    glGenTextures(1, &g_textureID);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, g_textureID);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    GLint textureWidth = round_up_to_power_of_2(gfxvidinfo.width);
    GLint textureHeight = round_up_to_power_of_2(gfxvidinfo.height);
    glTexImage2D(GL_TEXTURE_2D, 0 /* level */, GL_RGB,
            textureWidth, textureHeight,
                 0, GL_RGB, pixel_data_type, gfxvidinfo.bufmem);

    static const GLfloat squareVertices[] = {
            -1.0f, -1.0,
             1.0f, -1.0,
            -1.0f,  1.0,
             1.0f,  1.0,
    };

    GLfloat xFraction = ((GLfloat) gfxvidinfo.width)  / (GLfloat) textureWidth;
    GLfloat yFraction = ((GLfloat) gfxvidinfo.height) / (GLfloat) textureHeight;
    static GLfloat textureVertices[] = {
            0.0f,                 0.0f /* yFraction */,
            0.0f /* xFraction */, 0.0f /* yFraction */,
            0.0f,                 0.0f,
            0.0f /* xFraction */, 0.0f,
    };
    textureVertices[1] = yFraction;
    textureVertices[2] = xFraction;
    textureVertices[3] = yFraction;
    textureVertices[6] = xFraction;

    glUseProgram(g_programObj);
    glUniform1i(uniforms[UNIFORM_VIDEOFRAME], 0);
    glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
    glEnableVertexAttribArray(ATTRIB_VERTEX);
    glVertexAttribPointer(ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0,
                          textureVertices);
    glEnableVertexAttribArray(ATTRIB_TEXTUREPOSITON);

    DEBUG_LOG("Shaders compiled and program linked.\n");

    GLenum glErrorStatus = glGetError();
    if (glErrorStatus) {
        write_log("GL error %d while initializing.\n", glErrorStatus);
        return 0;
    }

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    ppb_g3d_interface->SwapBuffers(graphics_context, PP_BlockUntilComplete());

    gettimeofday(&tv_prev, NULL);

    return 1; /* Success! */
}