Exemplo n.º 1
0
static void restore_mode_if_last_fullscreen_display(ALLEGRO_SYSTEM_XGLX *s,
   ALLEGRO_DISPLAY_XGLX *d)
{
   bool last_fullscreen = true;
   size_t i;

   /* If any other fullscreen display is still active on the same adapter,
    * we must not touch the video mode.
    */
   for (i = 0; i < s->system.displays._size; i++) {
      ALLEGRO_DISPLAY_XGLX **slot = _al_vector_ref(&s->system.displays, i);
      ALLEGRO_DISPLAY_XGLX *living = *slot;

      if (living == d)
         continue;

      /* Check for fullscreen displays on the same adapter. */
      if (living->adapter == d->adapter
            && (living->display.flags & ALLEGRO_FULLSCREEN)) {
         last_fullscreen = false;
      }
   }

   if (last_fullscreen) {
      ALLEGRO_DEBUG("restore mode.\n");
      _al_xglx_restore_video_mode(s, d->adapter);
   }
   else {
      ALLEGRO_DEBUG("*not* restoring mode.\n");
   }
}
Exemplo n.º 2
0
static void ogl_unlock_region_nonbb_nonfbo(ALLEGRO_BITMAP *bitmap,
   ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap, int gl_y)
{
   const int lock_format = bitmap->locked_region.format;
   unsigned char *start_ptr;
   GLenum e;

   if (bitmap->lock_flags & ALLEGRO_LOCK_WRITEONLY) {
      ALLEGRO_DEBUG("Unlocking non-backbuffer non-FBO WRITEONLY\n");
      start_ptr = ogl_bitmap->lock_buffer;
   }
   else {
      ALLEGRO_DEBUG("Unlocking non-backbuffer non-FBO READWRITE\n");
      glPixelStorei(GL_UNPACK_ROW_LENGTH, ogl_bitmap->true_w);
      start_ptr = (unsigned char *)bitmap->lock_data
            + (bitmap->lock_h - 1) * bitmap->locked_region.pitch;
   }

   glTexSubImage2D(GL_TEXTURE_2D, 0,
      bitmap->lock_x, gl_y,
      bitmap->lock_w, bitmap->lock_h,
      get_glformat(lock_format, 2),
      get_glformat(lock_format, 1),
      start_ptr);

   e = glGetError();
   if (e) {
      ALLEGRO_ERROR("glTexSubImage2D for format %s failed (%s).\n",
         _al_pixel_format_name(lock_format), _al_gl_error_string(e));
   }
}
Exemplo n.º 3
0
static void xfvm_store_video_mode(ALLEGRO_SYSTEM_XGLX *s)
{
    int n;

    ALLEGRO_DEBUG("xfullscreen: xfvm_store_video_mode\n");

#ifdef ALLEGRO_XWINDOWS_WITH_XINERAMA
    /* TwinView workarounds, nothing to do here, since we can't really change or restore modes */
    if (s->xinerama_available && s->xinerama_screen_count != s->xfvm_screen_count) {
        return;
    }
#endif

    // save all original modes
    int i;
    for (i = 0; i < s->xfvm_screen_count; i++) {
        n = xfvm_get_num_modes(s, i);
        if (n == 0) {
            /* XXX what to do here? */
            continue;
        }

        s->xfvm_screen[i].original_mode = s->xfvm_screen[i].modes[0];

        int j;
        for (j = 0; j <  s->xfvm_screen[i].mode_count; j++) {
            ALLEGRO_DEBUG("xfvm: screen[%d] mode[%d] = (%d, %d)\n",
                          i, j, s->xfvm_screen[i].modes[j]->hdisplay, s->xfvm_screen[i].modes[j]->vdisplay);
        }
        ALLEGRO_INFO("xfvm: screen[%d] original mode = (%d, %d)\n",
                     i, s->xfvm_screen[i].original_mode->hdisplay, s->xfvm_screen[i].original_mode->vdisplay);
    }
}
Exemplo n.º 4
0
/* The close method should close the device, freeing any resources, and allow
   other processes to use the device */
static void _dsound_close()
{
   ALLEGRO_DEBUG("Releasing device\n");
   device->Release();
   ALLEGRO_DEBUG("Released device\n");
   ALLEGRO_INFO("DirectSound closed\n");
}
Exemplo n.º 5
0
static void *android_app_trampoline(ALLEGRO_THREAD *thr, void *arg)
{
   const int argc = 1;
   const char *argv[2] = {system_data.user_lib, NULL};
   int ret;

   (void)thr;
   (void)arg;

   ALLEGRO_DEBUG("signaling running");

   al_lock_mutex(system_data.mutex);
   system_data.trampoline_running = true;
   al_broadcast_cond(system_data.cond);
   al_unlock_mutex(system_data.mutex);

   ALLEGRO_DEBUG("entering main function %p", system_data.user_main);

   ret = (system_data.user_main)(argc, (char **)argv);

   /* Can we do anything with this exit code? */
   ALLEGRO_DEBUG("returned from main function, exit code = %d", ret);

   /* NOTE: don't put any ALLEGRO_DEBUG in here after running main! */

   android_cleanup(true);

   return NULL;
}
Exemplo n.º 6
0
static void xfvm_exit(ALLEGRO_SYSTEM_XGLX *s)
{
    int adapter;
    ALLEGRO_DEBUG("xfullscreen: XFVM exit\n");

    for (adapter = 0; adapter < s->xfvm_screen_count; adapter++) {
        if (s->xfvm_screen[adapter].mode_count > 0) {
            int i;
            for (i = 0; i < s->xfvm_screen[adapter].mode_count; i++) {
                if (s->xfvm_screen[adapter].modes[i]->privsize > 0) {
                    //XFree(s->xfvm_screen[adapter].modes[i]->private);
                }
            }
            //XFree(s->xfvm_screen[adapter].modes);
        }

        s->xfvm_screen[adapter].mode_count = 0;
        s->xfvm_screen[adapter].modes = NULL;
        s->xfvm_screen[adapter].original_mode = NULL;

        ALLEGRO_DEBUG("xfullscreen: XFVM freed adapter %d.\n", adapter);
    }

    al_free(s->xfvm_screen);
    s->xfvm_screen = NULL;
}
Exemplo n.º 7
0
ALLEGRO_BITMAP_OGL* _al_ogl_create_backbuffer(ALLEGRO_DISPLAY *disp)
{
   ALLEGRO_BITMAP_OGL *ogl_backbuffer;
   ALLEGRO_BITMAP *backbuffer;
   ALLEGRO_STATE backup;
   int format;

   ALLEGRO_DEBUG("Creating backbuffer\n");

   al_store_state(&backup, ALLEGRO_STATE_NEW_BITMAP_PARAMETERS);

   // FIXME: _al_deduce_color_format would work fine if the display paramerers
   // are filled in, for WIZ and IPOD
#ifdef ALLEGRO_GP2XWIZ
   format = ALLEGRO_PIXEL_FORMAT_RGB_565; /* Only support display format */
#elif defined ALLEGRO_IPHONE
   format = ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE;
   // TODO: This one is also supported
   //format = ALLEGRO_PIXEL_FORMAT_RGB_565;
#else
   format = _al_deduce_color_format(&disp->extra_settings);
   /* Eww. No OpenGL hardware in the world does that - let's just
    * switch to some default.
    */
   if (al_get_pixel_size(format) == 3) {
      /* Or should we use RGBA? Maybe only if not Nvidia cards? */
      format = ALLEGRO_PIXEL_FORMAT_ABGR_8888;
   }
#endif
   ALLEGRO_TRACE_CHANNEL_LEVEL("display", 1)("Deduced format %s for backbuffer.\n",
      _al_pixel_format_name(format));

   /* Now that the display backbuffer has a format, update extra_settings so
    * the user can query it back.
    */
   _al_set_color_components(format, &disp->extra_settings, ALLEGRO_REQUIRE);
   disp->backbuffer_format = format;

   ALLEGRO_DEBUG("Creating backbuffer bitmap\n");
   al_set_new_bitmap_format(format);
   /* Using ALLEGRO_NO_PRESERVE_TEXTURE prevents extra memory being allocated */
   al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP | ALLEGRO_NO_PRESERVE_TEXTURE);
   backbuffer = _al_ogl_create_bitmap(disp, disp->w, disp->h);
   al_restore_state(&backup);

   if (!backbuffer) {
      ALLEGRO_DEBUG("Backbuffer bitmap creation failed.\n");
      return NULL;
   }
   
   ALLEGRO_TRACE_CHANNEL_LEVEL("display", 1)(
      "Created backbuffer bitmap (actual format: %s)\n",
      _al_pixel_format_name(backbuffer->format));

   ogl_backbuffer = (ALLEGRO_BITMAP_OGL*)backbuffer;
   ogl_backbuffer->is_backbuffer = 1;
   backbuffer->display = disp;

   return ogl_backbuffer;
}
Exemplo n.º 8
0
/* Function: al_set_voice_playing
 */
bool al_set_voice_playing(ALLEGRO_VOICE *voice, bool val)
{
   ASSERT(voice);

   if (!voice->attached_stream) {
      ALLEGRO_DEBUG("Voice has no attachment\n");
      return false;
   }

   if (voice->is_streaming) {
      ALLEGRO_WARN("Attempted to change the playing state of a voice "
         "with a streaming attachment (mixer or audiostreams)\n");
      return false;
   }
   else {
      bool playing = al_get_voice_playing(voice);
      if (playing == val) {
         if (playing) {
            ALLEGRO_DEBUG("Voice is already playing\n");
         }
         else {
            ALLEGRO_DEBUG("Voice is already stopped\n");
         }
         return true;
      }

      return _al_kcm_set_voice_playing(voice, voice->mutex, val);
   }
}
Exemplo n.º 9
0
static bool ogl_lock_region_nonbb_readwrite(
   ALLEGRO_BITMAP *bitmap, ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap,
   int x, int gl_y, int w, int h, int format, bool* restore_fbo)
{
   bool ok;

   ASSERT(bitmap->parent == NULL);
   ASSERT(bitmap->locked == false);
   ASSERT(_al_get_bitmap_display(bitmap) == al_get_current_display());

   /* Try to create an FBO if there isn't one. */
   *restore_fbo =
      _al_ogl_setup_fbo_non_backbuffer(_al_get_bitmap_display(bitmap), bitmap);

   if (ogl_bitmap->fbo_info) {
      ALLEGRO_DEBUG("Locking non-backbuffer READWRITE with fbo\n");
      ok = ogl_lock_region_nonbb_readwrite_fbo(bitmap, ogl_bitmap,
         x, gl_y, w, h, format);
   }
   else {
      ALLEGRO_DEBUG("Locking non-backbuffer READWRITE no fbo\n");
      ok = ogl_lock_region_nonbb_readwrite_nonfbo(bitmap, ogl_bitmap,
         x, gl_y, w, h, format);
   }

   return ok;
}
Exemplo n.º 10
0
static bool convert_compressed(LPDIRECT3DTEXTURE9 dest, LPDIRECT3DTEXTURE9 src,
   int x, int y, int width, int height) {
#ifdef ALLEGRO_CFG_D3DX9
   bool ok = true;
   LPDIRECT3DSURFACE9 dest_texture_surface = NULL;
   LPDIRECT3DSURFACE9 src_texture_surface = NULL;

   if (dest->GetSurfaceLevel(0, &dest_texture_surface) != D3D_OK) {
      ALLEGRO_ERROR("convert_compressed: GetSurfaceLevel failed on dest.\n");
      ok = false;
   }

   if (ok && src->GetSurfaceLevel(0, &src_texture_surface) != D3D_OK) {
      ALLEGRO_ERROR("convert_compressed: GetSurfaceLevel failed on src.\n");
      ok = false;
   }

   RECT rect;
   rect.left = x;
   rect.top = y;
   rect.right = x + width;
   rect.bottom = y + height;

   if (ok && _al_imp_D3DXLoadSurfaceFromSurface &&
       _al_imp_D3DXLoadSurfaceFromSurface(dest_texture_surface,
                                          NULL,
                                          &rect,
                                          src_texture_surface,
                                          NULL,
                                          &rect,
                                          D3DX_FILTER_NONE,
                                          0) != D3D_OK) {
      ALLEGRO_ERROR("convert_compressed: D3DXLoadSurfaceFromSurface failed.\n");
      ok = false;
   }

   int i;
   if (src_texture_surface) {
       if ((i = src_texture_surface->Release()) != 0) {
          ALLEGRO_DEBUG("convert_compressed (src) ref count == %d\n", i);
       }
   }
   if (dest_texture_surface) {
       if ((i = dest_texture_surface->Release()) != 0) {
          // This can be non-zero
          ALLEGRO_DEBUG("convert_compressed (dest) ref count == %d\n", i);
       }
   }
   return ok;
#else
   (void)dest;
   (void)src;
   (void)x;
   (void)y;
   (void)width;
   (void)height;
   return false;
#endif
}
/* The close method should close the device, freeing any resources, and allow
   other processes to use the device */
static void _dsound_close()
{
   ALLEGRO_DEBUG("Releasing device\n");
   device->Release();
   ALLEGRO_DEBUG("Released device\n");

   _al_close_library(_al_dsound_module);
   ALLEGRO_INFO("DirectSound closed\n");
}
/* The deallocate_voice method should free the resources for the given voice,
   but still retain a hold on the device. The voice should be stopped and
   unloaded by the time this is called */
static void _dsound_deallocate_voice(ALLEGRO_VOICE *voice)
{
   ALLEGRO_DEBUG("Deallocating voice\n");

   al_free(voice->extra);
   voice->extra = NULL;

   ALLEGRO_DEBUG("Deallocated voice\n");
}
/* The unload_voice method unloads a sample previously loaded with load_voice.
   This method should not be called on a streaming voice. */
static void _dsound_unload_voice(ALLEGRO_VOICE *voice)
{
   ALLEGRO_DS_DATA *ex_data = (ALLEGRO_DS_DATA *)voice->extra;

   ALLEGRO_DEBUG("Unloading voice\n");

   ex_data->ds8_buffer->Release();

   ALLEGRO_DEBUG("Unloaded voice\n");
}
/* joydx_exit_joystick: [primary thread]
 *  Shuts down the DirectInput joystick devices.
 */
static void joydx_exit_joystick(void)
{
   int i;
   ALLEGRO_SYSTEM *system;
   size_t j;

   ALLEGRO_DEBUG("Entering joydx_exit_joystick\n");

   ASSERT(joydx_thread);

   /* stop the thread */
   SetEvent(STOP_EVENT);
   WaitForSingleObject(joydx_thread, INFINITE);
   CloseHandle(joydx_thread);
   joydx_thread = NULL;

   /* free thread resources */
   CloseHandle(STOP_EVENT);
   STOP_EVENT = NULL;
   DeleteCriticalSection(&joydx_thread_cs);

   /* The toplevel display is assumed to have the input acquired. Release it. */
   system = al_get_system_driver();
   for (j = 0; j < _al_vector_size(&system->displays); j++) {
      ALLEGRO_DISPLAY_WIN **pwin_disp = _al_vector_ref(&system->displays, j);
      ALLEGRO_DISPLAY_WIN *win_disp = *pwin_disp;
      if (win_disp->window == GetForegroundWindow()) {
         ALLEGRO_DEBUG("Requesting window unacquire joystick devices\n");
         _al_win_wnd_call_proc(win_disp->window,
                               _al_win_joystick_dinput_unacquire,
                               win_disp);
      }
   }

   /* destroy the devices */
   for (i = 0; i < MAX_JOYSTICKS; i++) {
      joydx_inactivate_joy(&joydx_joystick[i]);
   }
   joydx_num_joysticks = 0;

   for (i = 0; i < MAX_JOYSTICKS; i++) {
      JOYSTICK_WAKER(i) = NULL;
   }

   /* destroy the DirectInput interface */
   IDirectInput8_Release(joystick_dinput);
   joystick_dinput = NULL;

   /* release module handle */
   FreeLibrary(_al_dinput_module);
   _al_dinput_module = NULL;

   ALLEGRO_DEBUG("Leaving joydx_exit_joystick\n");
}
Exemplo n.º 15
0
static void decrease_window_counter()
{
   g_static_mutex_lock(&gtk_lock);
   --window_counter;
   ALLEGRO_DEBUG("--window_counter = %d\n", window_counter);
   if (window_counter == 0) {
      gtk_main_quit();
      ALLEGRO_DEBUG("Called gtk_main_quit.\n");
   }
   g_static_mutex_unlock(&gtk_lock);
}
Exemplo n.º 16
0
/* Copies video texture to system texture and bitmap->memory */
static void _al_d3d_sync_bitmap(ALLEGRO_BITMAP *dest)
{
   ALLEGRO_BITMAP_D3D *d3d_dest;
   LPDIRECT3DSURFACE9 system_texture_surface;
   LPDIRECT3DSURFACE9 video_texture_surface;
   UINT i;

   if (!_al_d3d_render_to_texture_supported())
      return;

   if (dest->locked) {
      return;
   }

   d3d_dest = (ALLEGRO_BITMAP_D3D *)dest;

   if (d3d_dest->system_texture == NULL || d3d_dest->video_texture == NULL) {
      return;
   }

   if (dest->parent) {
      dest = dest->parent;
   }

   if (d3d_dest->system_texture->GetSurfaceLevel(
         0, &system_texture_surface) != D3D_OK) {
      ALLEGRO_ERROR("_al_d3d_sync_bitmap: GetSurfaceLevel failed while updating video texture.\n");
      return;
   }

   if (d3d_dest->video_texture->GetSurfaceLevel(
         0, &video_texture_surface) != D3D_OK) {
      ALLEGRO_ERROR("_al_d3d_sync_bitmap: GetSurfaceLevel failed while updating video texture.\n");
      return;
   }

   if (d3d_dest->display->device->GetRenderTargetData(
         video_texture_surface,
         system_texture_surface) != D3D_OK) {
      ALLEGRO_ERROR("_al_d3d_sync_bitmap: GetRenderTargetData failed.\n");
      return;
   }

   if ((i = system_texture_surface->Release()) != 0) {
      ALLEGRO_DEBUG("_al_d3d_sync_bitmap (system) ref count == %d\n", i);
   }

   if ((i = video_texture_surface->Release()) != 0) {
      // This can be non-zero
      ALLEGRO_DEBUG("_al_d3d_sync_bitmap (video) ref count == %d\n", i);
   }

   d3d_sync_bitmap_memory(dest);
}
Exemplo n.º 17
0
static void ogl_unlock_region_nonbb_fbo(ALLEGRO_BITMAP *bitmap,
   ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap, int gl_y, int orig_format)
{
   if (bitmap->lock_flags & ALLEGRO_LOCK_WRITEONLY) {
      ALLEGRO_DEBUG("Unlocking non-backbuffer FBO WRITEONLY\n");
      ogl_unlock_region_nonbb_fbo_writeonly(bitmap, ogl_bitmap, gl_y,
         orig_format);
   }
   else {
      ALLEGRO_DEBUG("Unlocking non-backbuffer FBO READWRITE\n");
      ogl_unlock_region_nonbb_fbo_readwrite(bitmap, ogl_bitmap, gl_y);
   }
}
Exemplo n.º 18
0
/* The open method starts up the driver and should lock the device, using the
   previously set paramters, or defaults. It shouldn't need to start sending
   audio data to the device yet, however. */
static int _openal_open(void)
{
   ALenum openal_err;
   ALCenum alc_err;

   ALLEGRO_INFO("Starting OpenAL\n");

   /* clear the error state */
   openal_err = alGetError();

   /* pick default device. always a good choice */
   openal_dev = alcOpenDevice(NULL);

   alc_err = ALC_NO_ERROR;
   if (!openal_dev || (alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) {
      ALLEGRO_ERROR("Could not open audio device: %s\n",
         alc_get_err_str(alc_err));
      return 1;
   }

   openal_context = alcCreateContext(openal_dev, NULL);
   alc_err = ALC_NO_ERROR;
   if (!openal_context || (alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) {
      ALLEGRO_ERROR("Could not create current device context: %s\n",
         alc_get_err_str(alc_err));
      return 1;
   }

   alcMakeContextCurrent(openal_context);
#if !defined ALLEGRO_IPHONE
   if ((alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) {
      ALLEGRO_ERROR("Could not make context current: %s\n",
         alc_get_err_str(alc_err));
      return 1;
   }

   alDistanceModel(AL_NONE);
   if ((openal_err = alGetError()) != AL_NO_ERROR) {
      ALLEGRO_ERROR("Could not set distance model: %s\n",
         openal_get_err_str(openal_err));
      return 1;
   }
#endif

   ALLEGRO_DEBUG("Vendor: %s\n", alGetString(AL_VENDOR));
   ALLEGRO_DEBUG("Version: %s\n", alGetString(AL_VERSION));
   ALLEGRO_DEBUG("Renderer: %s\n", alGetString(AL_RENDERER));
   ALLEGRO_DEBUG("Extensions: %s\n", alGetString(AL_EXTENSIONS));

   return 0;
}
Exemplo n.º 19
0
static void xdpy_destroy_display(ALLEGRO_DISPLAY *d)
{
   ALLEGRO_SYSTEM_XGLX *s = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
   ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)d;
   ALLEGRO_OGL_EXTRAS *ogl = d->ogl_extras;
   bool is_last;

   ALLEGRO_DEBUG("destroying display.\n");

   /* If we're the last display, convert all bitmaps to display independent
    * (memory) bitmaps. Otherwise, pass all bitmaps to any other living
    * display. We assume all displays are compatible.)
    */
   is_last = (s->system.displays._size == 1);
   if (is_last)
      convert_display_bitmaps_to_memory_bitmap(d);
   else
      transfer_display_bitmaps_to_any_other_display(s, d);

   _al_ogl_unmanage_extensions(d);
   ALLEGRO_DEBUG("unmanaged extensions.\n");

   _al_mutex_lock(&s->lock);
   _al_vector_find_and_delete(&s->system.displays, &d);

   if (ogl->backbuffer) {
      _al_ogl_destroy_backbuffer(ogl->backbuffer);
      ogl->backbuffer = NULL;
      ALLEGRO_DEBUG("destroy backbuffer.\n");
   }

   if (glx->overridable_vt) {
      glx->overridable_vt->destroy_display_hook(d, is_last);
   }

   if (s->mouse_grab_display == d) {
      s->mouse_grab_display = NULL;
   }

   _al_vector_free(&d->bitmaps);
   _al_event_source_free(&d->es);

   al_free(d->ogl_extras);
   al_free(d->vertex_cache);
   al_free(d);

   _al_mutex_unlock(&s->lock);

   ALLEGRO_DEBUG("destroy display finished.\n");
}
Exemplo n.º 20
0
void _al_xglx_set_above(ALLEGRO_DISPLAY *display, int value)
{
   ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver();
   ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)display;
   Display *x11 = system->x11display;

   ALLEGRO_DEBUG("Toggling _NET_WM_STATE_ABOVE hint: %d\n", value);

   XEvent xev;
   xev.xclient.type = ClientMessage;
   xev.xclient.serial = 0;
   xev.xclient.send_event = True;
   xev.xclient.message_type = X11_ATOM(_NET_WM_STATE);
   xev.xclient.window = glx->window;
   xev.xclient.format = 32;

   // Note: It seems 0 is not reliable except when mapping a window -
   // 2 is all we need though.
   xev.xclient.data.l[0] = value; /* 0 = off, 1 = on, 2 = toggle */

   xev.xclient.data.l[1] = X11_ATOM(_NET_WM_STATE_ABOVE);
   xev.xclient.data.l[2] = 0;
   xev.xclient.data.l[3] = 0;
   xev.xclient.data.l[4] = 1;

   XSendEvent(x11, DefaultRootWindow(x11), False,
      SubstructureRedirectMask | SubstructureNotifyMask, &xev);
}
Exemplo n.º 21
0
static HMODULE load_library_at_path(const char *path_str)
{
    HMODULE lib;

    /*
     * XXX LoadLibrary will search the current directory for any dependencies of
     * the library we are loading.  Using LoadLibraryEx with the appropriate
     * flags would fix that, but when I tried it I was unable to load dsound.dll
     * on Vista.
     */

    ALLEGRO_DEBUG("Calling LoadLibrary %s\n", path_str);
    lib = LoadLibraryA(path_str);
    if (lib) {
        ALLEGRO_INFO("Loaded %s\n", path_str);
    }
    else {
        DWORD error = GetLastError();
        HRESULT hr = HRESULT_FROM_WIN32(error);
        /* XXX do something with it */
        (void)hr;
        ALLEGRO_WARN("Failed to load %s (error: %ld)\n", path_str, error);
    }

    return lib;
}
Exemplo n.º 22
0
static uint32_t parse_opengl_version(const char *s)
{
    char *p = (char *) s;
    int v[4] = {0, 0, 0, 0};
    int n;
    uint32_t ver;

    /* e.g. "4.0.0 Vendor blah blah" */
    for (n = 0; n < 4; n++) {
        char *end;
        long l;

        errno = 0;
        l = strtol(p, &end, 10);
        if (errno)
            break;
        v[n] = _ALLEGRO_CLAMP(0, l, 255);
        if (*end != '.')
            break;
        p = end + 1; /* skip dot */
    }

    ver = (v[0] << 24) | (v[1] << 16) | (v[2] << 8) | v[3];
    ALLEGRO_DEBUG("Parsed '%s' as 0x%08x\n", s, ver);
    return ver;
}
Exemplo n.º 23
0
/* Note: The system mutex must be locked (exactly once) so when we
 * wait for the condition variable it gets auto-unlocked. For a
 * nested lock that would not be the case.
 */
void _al_display_xglx_await_resize(ALLEGRO_DISPLAY *d, int old_resize_count,
   bool delay_hack)
{
   ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver();
   ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)d;
   ALLEGRO_TIMEOUT timeout;

   ALLEGRO_DEBUG("Awaiting resize event\n");

   XSync(system->x11display, False);

   /* Wait until we are actually resized.
    * Don't wait forever if an event never comes.
    */
   al_init_timeout(&timeout, 1.0);
   while (old_resize_count == glx->resize_count) {
      if (_al_cond_timedwait(&system->resized, &system->lock, &timeout) == -1) {
         ALLEGRO_ERROR("Timeout while waiting for resize event.\n");
         return;
      }
   }

   /* XXX: This hack helps when toggling between fullscreen windows and not,
    * on various window managers.
    */
   if (delay_hack) {
      al_rest(0.2);
   }

   xdpy_acknowledge_resize(d);
}
Exemplo n.º 24
0
static void ljoy_merge(void)
{
    unsigned i;

    config_needs_merging = false;
    num_joysticks = 0;

    for (i = 0; i < _al_vector_size(&joysticks); i++) {
        ALLEGRO_JOYSTICK_LINUX **slot = _al_vector_ref(&joysticks, i);
        ALLEGRO_JOYSTICK_LINUX *joy = *slot;

        switch (joy->config_state) {
        case LJOY_STATE_UNUSED:
            break;

        case LJOY_STATE_BORN:
        case LJOY_STATE_ALIVE:
            joy->config_state = LJOY_STATE_ALIVE;
            num_joysticks++;
            break;

        case LJOY_STATE_DYING:
            inactivate_joy(joy);
            break;
        }
    }

    ALLEGRO_DEBUG("Merge done, num_joysticks=%d\n", num_joysticks);
}
Exemplo n.º 25
0
static ALLEGRO_DISPLAY_INTERFACE *xglx_get_display_driver(void)
{
   ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();

   /* Look up the toggle_mouse_grab_key binding.  This isn't such a great place
    * to do it, but the config file is not available until after the system driver
    * is initialised.
    */
   if (!system->toggle_mouse_grab_keycode) {
      const char *binding = al_get_config_value(al_get_system_config(),
         "keyboard", "toggle_mouse_grab_key");
      if (binding) {
         system->toggle_mouse_grab_keycode = _al_parse_key_binding(binding,
            &system->toggle_mouse_grab_modifiers);
         if (system->toggle_mouse_grab_keycode) {
            ALLEGRO_DEBUG("Toggle mouse grab key: '%s'\n", binding);
         }
         else {
            ALLEGRO_WARN("Cannot parse key binding '%s'\n", binding);
         }
      }
   }

   return _al_display_xglx_driver();
}
Exemplo n.º 26
0
static bool fill_joystick_buttons(ALLEGRO_JOYSTICK_LINUX *joy, int fd)
{
    unsigned long key_bits[NLONGS(KEY_CNT)] = {0};
    int b;
    int i;

    if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), key_bits) < 0)
        return false;

    b = 0;

    for (i = LJOY_BTN_RANGE_START; i < LJOY_BTN_RANGE_END; i++) {
        if (TEST_BIT(i, key_bits) && is_joystick_button(i)) {
            joy->button_mapping[b].ev_code = i;
            ALLEGRO_DEBUG("Input event code %d maps to button %d\n", i, b);

            joy->parent.info.button[b].name = al_malloc(32);
            snprintf((char *)joy->parent.info.button[b].name, 32, "B%d", b+1);

            b++;
            if (b == _AL_MAX_JOYSTICK_BUTTONS)
                break;
        }
    }

    joy->parent.info.num_buttons = b;

    /* Clear the rest. */
    for (; b < _AL_MAX_JOYSTICK_BUTTONS; b++) {
        joy->button_mapping[b].ev_code = -1;
    }

    return true;
}
Exemplo n.º 27
0
/* xmouse_get_mouse_num_buttons:
 *  Return the number of buttons on the mouse.
 */
static unsigned int xmouse_get_mouse_num_buttons(void)
{
   int num_buttons;
   unsigned char map[32];
   ALLEGRO_SYSTEM_XGLX *system = (void *)al_get_system_driver();

   ASSERT(xmouse_installed);

   _al_mutex_lock(&system->lock);
   num_buttons = XGetPointerMapping(system->x11display, map, sizeof(map));
   _al_mutex_unlock(&system->lock);
   
   if (num_buttons > (int)sizeof(map))
      num_buttons = sizeof(map);
   
   #ifdef DEBUGMODE
   char debug[num_buttons * 4 + 1];
   debug[0] = 0;
   int i;
   for (i = 0; i < num_buttons; i++) {
      sprintf(debug + strlen(debug), "%2d,", map[i]);
   }
   ALLEGRO_DEBUG("XGetPointerMapping: %s\n", debug);
   #endif

   if (num_buttons < 1)
      num_buttons = 1;

   return num_buttons;
}
Exemplo n.º 28
0
static void *file_stdio_fopen(const char *path, const char *mode)
{
   FILE *fp;
   USERDATA *userdata;

   ALLEGRO_DEBUG("opening %s %s\n", path, mode);

#ifdef ALLEGRO_WINDOWS
   {
      wchar_t *wpath = _al_win_utf8_to_utf16(path);
      wchar_t *wmode = _al_win_utf8_to_utf16(mode);
      fp = _wfopen(wpath, wmode);
      al_free(wpath);
      al_free(wmode);
   }
#else
   fp = fopen(path, mode);
#endif

   if (!fp) {
      al_set_errno(errno);
      return NULL;
   }

   userdata = al_malloc(sizeof(USERDATA));
   if (!userdata) {
      fclose(fp);
      return NULL;
   }

   userdata->fp = fp;
   userdata->errnum = 0;

   return userdata;
}
Exemplo n.º 29
0
/* find_unknown_key_assignment
 *  In some cases, X11 doesn't report any KeySym for a key - so the earliest
 *  time we can map it to an Allegro key is when it is first pressed.
 */
static int find_unknown_key_assignment(int i)
{
    int j;

    for (j = 1; j < ALLEGRO_KEY_MAX; j++) {
        if (!used[j]) {
            const char *str;
            keycode_to_scancode[i] = j;
            str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode)]);
            if (str)
                key_names[j] = str;
            else {
                key_names[j] = _al_keyboard_common_names[j];
            }
            used[j] = 1;
            break;
        }
    }

    if (j == ALLEGRO_KEY_MAX) {
        ALLEGRO_ERROR("You have more keys reported by X than Allegro's "
                      "maximum of %i keys. Please send a bug report.\n", ALLEGRO_KEY_MAX);
        keycode_to_scancode[i] = 0;
    }

    char str[1024];
    sprintf(str, "Key %i missing:", i);
    for (j = 0; j < sym_per_key; j++) {
        char *sym_str = XKeysymToString(keysyms[sym_per_key * (i - min_keycode) + j]);
        sprintf(str + strlen(str), " %s", sym_str ? sym_str : "NULL");
    }
    ALLEGRO_DEBUG("%s assigned to %i.\n", str, keycode_to_scancode[i]);

    return keycode_to_scancode[i];
}
static bool joydx_scan(bool configure)
{
   HRESULT hr;
   unsigned i;

   /* Clear mark bits. */
   for (i = 0; i < MAX_JOYSTICKS; i++)
      joydx_joystick[i].marked = false;

   /* enumerate the joysticks attached to the system */
   hr = IDirectInput8_EnumDevices(joystick_dinput, DI8DEVCLASS_GAMECTRL,
      joystick_enum_callback, NULL, DIEDFL_ATTACHEDONLY);
   if (FAILED(hr)) {
      /* XXX will this ruin everything? */
      IDirectInput8_Release(joystick_dinput);
      joystick_dinput = NULL;
      return false;
   }

   /* Schedule unmarked structures to be inactivated. */
   for (i = 0; i < MAX_JOYSTICKS; i++) {
      ALLEGRO_JOYSTICK_DIRECTX *joy = &joydx_joystick[i];

      if (joy->config_state == STATE_ALIVE && !joy->marked) {
         ALLEGRO_DEBUG("Joystick %s to be inactivated\n", joydx_guid_string(joy));
         joy->config_state = STATE_DYING;
         config_needs_merging = true;
      }
   }

   if (config_needs_merging && configure)
      joydx_generate_configure_event();

   return config_needs_merging;
}