Esempio n. 1
0
int64_t sinsp::get_file_size(const std::string& fname, char *error)
{
	static string err_str = "Could not determine capture file size: ";
	std::string errdesc;
#ifdef _WIN32
	LARGE_INTEGER li = { 0 };
	HANDLE fh = CreateFile(fname.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
		OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
	if (fh != INVALID_HANDLE_VALUE)
	{
		if (0 != GetFileSizeEx(fh, &li))
		{
			CloseHandle(fh);
			return li.QuadPart;
		}
		errdesc = get_error_desc(err_str);
		CloseHandle(fh);
	}
#else
	struct stat st;
	if (0 == stat(fname.c_str(), &st))
	{
		return st.st_size;
	}
#endif
	if(errdesc.empty()) errdesc = get_error_desc(err_str);
	strncpy(error, errdesc.c_str(), errdesc.size() > SCAP_LASTERR_SIZE ? SCAP_LASTERR_SIZE : errdesc.size());
	return -1;
}
Esempio n. 2
0
static bool init_touch_input(void)
{
   unsigned i;
   ALLEGRO_SYSTEM* system;

   if (installed)
      return false;

   if (!_al_win_init_touch_input_api())
      return false;

   memset(&touch_input_state, 0, sizeof(touch_input_state));

   _al_event_source_init(&touch_input.es);
   _al_event_source_init(&touch_input.mouse_emulation_es);

   touch_input.mouse_emulation_mode = ALLEGRO_MOUSE_EMULATION_TRANSPARENT;

   installed = true;

   system = al_get_system_driver();
   for (i = 0; i < _al_vector_size(&system->displays); ++i) {
      bool r;
      ALLEGRO_DISPLAY_WIN *win_display = *((ALLEGRO_DISPLAY_WIN**)_al_vector_ref(&system->displays, i));
      r = _al_win_register_touch_window(win_display->window, 0);
	  ALLEGRO_INFO("registering touch window %p: %d\n", win_display, r);
	  if (!r) {
		 ALLEGRO_ERROR("RegisterTouchWindow failed: %s\n", get_error_desc(GetLastError()));
	     return false;
	  }
   }

   return true;
}
Esempio n. 3
0
static HGLRC init_temp_context(HWND wnd)
{
   PIXELFORMATDESCRIPTOR pfd;
   int pf;
   HDC dc;
   HGLRC glrc;

   dc = GetDC(wnd);

   memset(&pfd, 0, sizeof(pfd));
   pfd.nSize = sizeof(pfd);
   pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL
	           | PFD_DOUBLEBUFFER_DONTCARE | PFD_STEREO_DONTCARE;
   pfd.iPixelType = PFD_TYPE_RGBA;
   pfd.iLayerType = PFD_MAIN_PLANE;
   pfd.cColorBits = 32;

   pf = ChoosePixelFormat(dc, &pfd);
   if (!pf) {
      ALLEGRO_ERROR("Unable to chose a temporary pixel format. %s\n",
                     get_error_desc(GetLastError()));
      return NULL;
   }

   memset(&pfd, 0, sizeof(pfd));
   if (!SetPixelFormat(dc, pf, &pfd)) {
      ALLEGRO_ERROR("Unable to set a temporary pixel format. %s\n",
                     get_error_desc(GetLastError()));
      return NULL;
   }

   glrc = wglCreateContext(dc);
   if (!glrc) {
      ALLEGRO_ERROR("Unable to create a render context. %s\n",
                     get_error_desc(GetLastError()));
      return NULL;
   }

   if (!wglMakeCurrent(dc, glrc)) {
      ALLEGRO_ERROR("Unable to set the render context as current. %s\n",
                     get_error_desc(GetLastError()));
      wglDeleteContext(glrc);
      return NULL;
   }

   return glrc;
}
Esempio n. 4
0
void test_cunit_CUError(void)
{
  CU_ErrorCode old_err = CU_get_error();
  CU_ErrorAction old_action = CU_get_error_action();

  test_cunit_start_tests("CUError.c");

  /* CU_set_error() & CU_get_error() */
  CU_set_error(CUE_NOMEMORY);
  TEST(CU_get_error() != CUE_SUCCESS);
  TEST(CU_get_error() == CUE_NOMEMORY);

  CU_set_error(CUE_NOREGISTRY);
  TEST(CU_get_error() != CUE_SUCCESS);
  TEST(CU_get_error() == CUE_NOREGISTRY);

  /* CU_get_error_msg() */
  CU_set_error(CUE_SUCCESS);
  TEST(!strcmp(CU_get_error_msg(), get_error_desc(CUE_SUCCESS)));

  CU_set_error(CUE_NOTEST);
  TEST(!strcmp(CU_get_error_msg(), get_error_desc(CUE_NOTEST)));

  CU_set_error(CUE_NOMEMORY);
  TEST(!strcmp(CU_get_error_msg(), get_error_desc(CUE_NOMEMORY)));
  TEST(strcmp(CU_get_error_msg(), get_error_desc(CUE_SCLEAN_FAILED)));

  TEST(!strcmp(get_error_desc(100), "Undefined Error"));

  /* CU_set_error_action() & CU_get_error_action() */
  CU_set_error_action(CUEA_FAIL);
  TEST(CU_get_error_action() != CUEA_IGNORE);
  TEST(CU_get_error_action() == CUEA_FAIL);
  TEST(CU_get_error_action() != CUEA_ABORT);

  CU_set_error_action(CUEA_ABORT);
  TEST(CU_get_error_action() != CUEA_IGNORE);
  TEST(CU_get_error_action() != CUEA_FAIL);
  TEST(CU_get_error_action() == CUEA_ABORT);

  /* reset  values */
  CU_set_error(old_err);
  CU_set_error_action(old_action);

  test_cunit_end_tests();
}
Esempio n. 5
0
static void wgl_unset_current_display(ALLEGRO_DISPLAY *d)
{
   (void)d;

   if (!wglMakeCurrent(NULL, NULL)) {
      ALLEGRO_ERROR("Unable unset the current context! %s\n",
                     get_error_desc(GetLastError()));
   }
}
Esempio n. 6
0
static int get_pixel_formats_count_old(HDC dc)
{
   PIXELFORMATDESCRIPTOR pfd;
   int ret;

   ret = DescribePixelFormat(dc, 1, sizeof(pfd), &pfd);
   if (!ret) {
      ALLEGRO_ERROR("DescribePixelFormat failed! %s\n",
                     get_error_desc(GetLastError()));
   }

   return ret;
}
Esempio n. 7
0
static int get_pixel_formats_count_ext(HDC dc)
{
   int attrib[1];
   int value[1];

   attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB;
   if ((_wglGetPixelFormatAttribivARB(dc, 0, 0, 1, attrib, value) == GL_FALSE)
    && (_wglGetPixelFormatAttribivEXT(dc, 0, 0, 1, attrib, value) == GL_FALSE)) {
        ALLEGRO_ERROR("WGL_ARB/EXT_pixel_format use failed! %s\n",
                       get_error_desc(GetLastError()));
   }

   return value[0];
}
Esempio n. 8
0
/*=================================================================
 *  Public API functions
 *=================================================================*/
void CU_set_error(CU_ErrorCode error)
{
  if ((error != CUE_SUCCESS) && (g_error_action == CUEA_ABORT)) {
#ifndef CUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS
    fprintf(stderr, _("\nAborting due to error #%d: %s\n"),
            (int)error,
            get_error_desc(error));
    exit((int)error);
#else
    test_exit(error);
#endif
  }

  g_error_number = error;
}
Esempio n. 9
0
static bool wgl_set_current_display(ALLEGRO_DISPLAY *d)
{
   ALLEGRO_DISPLAY_WGL *wgl_disp = (ALLEGRO_DISPLAY_WGL *)d;
   HGLRC current_glrc;

   current_glrc = wglGetCurrentContext();

   if (!current_glrc || (current_glrc && current_glrc != wgl_disp->glrc)) {
      /* make the context the current one */
      if (!wglMakeCurrent(wgl_disp->dc, wgl_disp->glrc)) {
         ALLEGRO_ERROR("Unable to make the context current! %s\n",
                        get_error_desc(GetLastError()));
         return false;
      }

      _al_ogl_set_extensions(d->ogl_extras->extension_api);
   }

   return true;
}
Esempio n. 10
0
static ALLEGRO_EXTRA_DISPLAY_SETTINGS* read_pixel_format_old(int fmt, HDC dc)
{
   ALLEGRO_EXTRA_DISPLAY_SETTINGS *eds = NULL;
   PIXELFORMATDESCRIPTOR pfd;
   int result;

   result = DescribePixelFormat(dc, fmt+1, sizeof(pfd), &pfd);
   if (!result) {
      ALLEGRO_WARN("DescribePixelFormat() failed. %s\n",
                    get_error_desc(GetLastError()));
      return NULL;
   }

   eds = al_calloc(1, sizeof *eds);
   if (!decode_pixel_format_old(&pfd, eds)) {
      al_free(eds);
      return NULL;
   }

   return eds;
}
Esempio n. 11
0
static bool create_display_internals(ALLEGRO_DISPLAY_WGL *wgl_disp)
{
   ALLEGRO_DISPLAY     *disp     = (void*)wgl_disp;
   ALLEGRO_DISPLAY_WIN *win_disp = (void*)wgl_disp;
   WGL_DISPLAY_PARAMETERS ndp;
   int window_x, window_y;

   /* The window is created in a separate thread so we need to pass this
    * TLS on
    */
   al_get_new_window_position(&window_x, &window_y);
   ndp.window_x = window_x;
   ndp.window_y = window_y;

   /* _beginthread closes the handle automatically. */
   ndp.display = wgl_disp;
   ndp.init_failed = true;
   ndp.AckEvent = CreateEvent(NULL, false, false, NULL);
   _beginthread(display_thread_proc, 0, &ndp);

   /* Wait some _finite_ time (10 secs or so) for display thread to init, and
    * give up if something horrible happened to it, unless we're in debug mode
    * and we may have intentionally stopped the execution to analyze the code.
    */
#ifdef DEBUGMODE
   WaitForSingleObject(ndp.AckEvent, INFINITE);
#else
   WaitForSingleObject(ndp.AckEvent, 10*1000);
#endif

   CloseHandle(ndp.AckEvent);

   if (ndp.init_failed) {
      ALLEGRO_ERROR("Failed to create display.\n");
      return false;
   }

   /* WGL display lists cannot be shared with the API currently in use. */
   disp->ogl_extras->is_shared = false;
   
   if (!select_pixel_format(wgl_disp, wgl_disp->dc)) {
      destroy_display_internals(wgl_disp);
      return false;
   }

   if (disp->flags & ALLEGRO_OPENGL_3_0) {
      bool fc = (disp->flags & ALLEGRO_OPENGL_FORWARD_COMPATIBLE) != 0;
      wgl_disp->glrc = init_ogl_context_ex(wgl_disp->dc, fc, 3, 0);
   }
   else {
      wgl_disp->glrc = wglCreateContext(wgl_disp->dc);
   }

   if (!wgl_disp->glrc) {
      ALLEGRO_ERROR("Unable to create a render context! %s\n",
                     get_error_desc(GetLastError()));
      destroy_display_internals(wgl_disp);
      return false;
   }

   /* make the context the current one */
   if (!wglMakeCurrent(wgl_disp->dc, wgl_disp->glrc)) {
      ALLEGRO_ERROR("Unable to make the context current! %s\n",
                     get_error_desc(GetLastError()));
      destroy_display_internals(wgl_disp);
      return false;
   }

   _al_ogl_manage_extensions(disp);
   _al_ogl_set_extensions(disp->ogl_extras->extension_api);

   if (disp->ogl_extras->ogl_info.version < _ALLEGRO_OPENGL_VERSION_1_2) {
      ALLEGRO_EXTRA_DISPLAY_SETTINGS *eds = _al_get_new_display_settings();
      if (eds->required & (1<<ALLEGRO_COMPATIBLE_DISPLAY)) {
         ALLEGRO_WARN("Allegro requires at least OpenGL version 1.2 to work.\n");
         destroy_display_internals(wgl_disp);
         return false;
      }
      disp->extra_settings.settings[ALLEGRO_COMPATIBLE_DISPLAY] = 0;
   }

   disp->ogl_extras->backbuffer = _al_ogl_create_backbuffer(disp);
   if (!disp->ogl_extras->backbuffer) {
      ALLEGRO_ERROR("Failed to create a backbuffer.\n");
      destroy_display_internals(wgl_disp);
      return false;
   }

   /* Try to enable or disable vsync as requested */
   /* NOTE: my drivers claim I don't have WGL_EXT_swap_control
    * (according to al_have_opengl_extension), but wglSwapIntervalEXT
    * does get loaded, so just check for that.
    */
   if (wglSwapIntervalEXT) {
      if (disp->extra_settings.settings[ALLEGRO_VSYNC] == 1) {
         wglSwapIntervalEXT(1);
      }
      else if (disp->extra_settings.settings[ALLEGRO_VSYNC] == 2) {
         wglSwapIntervalEXT(0);
      }
   }
 
   win_disp->mouse_selected_hcursor = 0;
   win_disp->mouse_cursor_shown = false;
   win_disp->can_acknowledge = false;

   _al_win_grab_input(win_disp);

   if (disp->extra_settings.settings[ALLEGRO_COMPATIBLE_DISPLAY])
      setup_gl(disp);

   return true;
}
Esempio n. 12
0
static bool select_pixel_format(ALLEGRO_DISPLAY_WGL *d, HDC dc)
{
   ALLEGRO_EXTRA_DISPLAY_SETTINGS **eds = NULL;
   ALLEGRO_SYSTEM *system = (void *)al_get_system_driver();
   int eds_count = 0;
   int i;
   bool force_old = false;

   if (system->config) {
      const char *selection_mode;
      selection_mode = al_get_config_value(system->config, "graphics",
                          "config_selection");
      if (selection_mode && selection_mode[0] != '\0') {
         if (!_al_stricmp(selection_mode, "old")) {
            ALLEGRO_INFO("Forcing OLD visual selection method.\n");
            force_old = true;
         }
         else if (!_al_stricmp(selection_mode, "new"))
            force_old = false;
      }
   }

   if (!force_old)
      eds = get_available_pixel_formats_ext(&eds_count);
   if (!eds)
      eds = get_available_pixel_formats_old(&eds_count, dc);

   if (!eds || !eds_count) {
      ALLEGRO_ERROR("Didn't find any suitable pixel format!\n");
      return false;
   }

   qsort(eds, eds_count, sizeof(eds[0]), _al_display_settings_sorter);

   for (i = 0; i < eds_count ; i++) {
      if (SetPixelFormat(d->dc, eds[i]->index, NULL)) {
         ALLEGRO_INFO("Chose visual no. %i\n\n", eds[i]->index);
         display_pixel_format(eds[i]);
         break;
      }
      else {
         ALLEGRO_WARN("Unable to set pixel format! %s\n",
                       get_error_desc(GetLastError()));
         ALLEGRO_WARN("Trying next one.\n");
      }
   }

   if (i == eds_count) {
      ALLEGRO_ERROR("Unable to set any pixel format! %s\n",
                     get_error_desc(GetLastError()));
      for (i = 0; i < eds_count; i++)
         al_free(eds[i]);
      al_free(eds);
      return false;
   }

   memcpy(&d->win_display.display.extra_settings, eds[i], sizeof(ALLEGRO_EXTRA_DISPLAY_SETTINGS));

   for (i = 0; i < eds_count; i++)
      al_free(eds[i]);
   if (eds)
      al_free(eds);

   return true;
}
Esempio n. 13
0
static bool change_display_mode(ALLEGRO_DISPLAY *d)
{
   DEVMODE dm;
   DEVMODE fallback_dm;
   DISPLAY_DEVICE dd;
   char* dev_name = NULL;
   int i, modeswitch, result;
   int fallback_dm_valid = 0;
   int bpp;
   int adapter = al_get_new_display_adapter();

   if (adapter >= 0) {
      memset(&dd, 0, sizeof(dd));
      dd.cb = sizeof(dd);
      if (EnumDisplayDevices(NULL, adapter, &dd, 0) == false)
         return false;
      dev_name = dd.DeviceName;
   }

   memset(&fallback_dm, 0, sizeof(fallback_dm));
   memset(&dm, 0, sizeof(dm));
   dm.dmSize = sizeof(DEVMODE);

   bpp = d->extra_settings.settings[ALLEGRO_COLOR_SIZE];
   if (!bpp)
      bpp = 32;

   i = 0;
   do {
      modeswitch = EnumDisplaySettings(dev_name, i, &dm);
      if (!modeswitch)
         break;

      if ((dm.dmPelsWidth  == (unsigned) d->w)
         && (dm.dmPelsHeight == (unsigned) d->h)
         && (dm.dmBitsPerPel == (unsigned) bpp)
         && (dm.dmDisplayFrequency != (unsigned) d->refresh_rate))
      {
         /* Keep it as fallback if refresh rate request could not
          * be satisfied. Try to get as close to 60Hz as possible though,
          * it's a bit better for a fallback than just blindly picking
          * something like 47Hz or 200Hz.
          */
         if (!fallback_dm_valid) {
            fallback_dm = dm;
            fallback_dm_valid = 1;
         }
         else if (dm.dmDisplayFrequency >= 60) {
            if (dm.dmDisplayFrequency < fallback_dm.dmDisplayFrequency) {
                fallback_dm = dm;
            }
         }
      }
      i++;
   }
   while ((dm.dmPelsWidth  != (unsigned) d->w)
       || (dm.dmPelsHeight != (unsigned) d->h)
       || (dm.dmBitsPerPel != (unsigned) bpp)
       || (dm.dmDisplayFrequency != (unsigned) d->refresh_rate));

   if (!modeswitch && !fallback_dm_valid) {
      ALLEGRO_ERROR("Mode not found.\n");
      return false;
   }

   if (!modeswitch && fallback_dm_valid)
      dm = fallback_dm;

   dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
   result = ChangeDisplaySettingsEx(dev_name, &dm, NULL, CDS_FULLSCREEN, 0);

   if (result != DISP_CHANGE_SUCCESSFUL) {
      ALLEGRO_ERROR("Unable to set mode. %s\n",
                     get_error_desc(GetLastError()));
      return false;
   }

   ALLEGRO_INFO("Mode seccessfuly set.\n");
   return true;
}
Esempio n. 14
0
static ALLEGRO_EXTRA_DISPLAY_SETTINGS* read_pixel_format_ext(int fmt, HDC dc)
{
   ALLEGRO_EXTRA_DISPLAY_SETTINGS *eds = NULL;

   /* Note: Even though we use te ARB suffix, all those enums are compatible
    * with EXT_pixel_format.
    */
   int attrib[] = {
      WGL_SUPPORT_OPENGL_ARB,
      WGL_DRAW_TO_WINDOW_ARB,
      WGL_PIXEL_TYPE_ARB,
      WGL_ACCELERATION_ARB,
      WGL_DOUBLE_BUFFER_ARB,
      WGL_DEPTH_BITS_ARB,
      WGL_SWAP_METHOD_ARB,
      WGL_COLOR_BITS_ARB,
      WGL_RED_BITS_ARB,
      WGL_GREEN_BITS_ARB,
      WGL_BLUE_BITS_ARB,
      WGL_ALPHA_BITS_ARB,
      WGL_RED_SHIFT_ARB,
      WGL_GREEN_SHIFT_ARB,
      WGL_BLUE_SHIFT_ARB,
      WGL_ALPHA_SHIFT_ARB,
      WGL_STENCIL_BITS_ARB,
      WGL_STEREO_ARB,
      WGL_ACCUM_BITS_ARB,
      WGL_ACCUM_RED_BITS_ARB,
      WGL_ACCUM_GREEN_BITS_ARB,
      WGL_ACCUM_BLUE_BITS_ARB,
      WGL_ACCUM_ALPHA_BITS_ARB,
      WGL_AUX_BUFFERS_ARB,

      /* The following are used by extensions that add to WGL_pixel_format.
       * If WGL_p_f isn't supported though, we can't use the (then invalid)
       * enums. We can't use any magic number either, so we settle for 
       * replicating one. The pixel format decoder
       * (decode_pixel_format_attrib()) doesn't care about duplicates.
       */
      WGL_AUX_BUFFERS_ARB, /* placeholder for WGL_SAMPLE_BUFFERS_ARB */
      WGL_AUX_BUFFERS_ARB, /* placeholder for WGL_SAMPLES_ARB        */
      WGL_AUX_BUFFERS_ARB, /* placeholder for WGL_DEPTH_FLOAT_EXT    */
   };

   const int num_attribs = sizeof(attrib) / sizeof(attrib[0]);
   int *value = (int*)al_malloc(sizeof(int) * num_attribs);
   int ret;

   if (!value)
      return NULL;

   /* If multisampling is supported, query for it. */
   if (is_wgl_extension_supported("WGL_ARB_multisample", dc)) {
      attrib[num_attribs - 3] = WGL_SAMPLE_BUFFERS_ARB;
      attrib[num_attribs - 2] = WGL_SAMPLES_ARB;
   }
   if (is_wgl_extension_supported("WGL_EXT_depth_float", dc)) {
      attrib[num_attribs - 1] = WGL_DEPTH_FLOAT_EXT;
   }

   /* Get the pf attributes */
   if (_wglGetPixelFormatAttribivARB) {
      ret = _wglGetPixelFormatAttribivARB(dc, fmt+1, 0, num_attribs, attrib, value);
   }
   else if (_wglGetPixelFormatAttribivEXT) {
      ret = _wglGetPixelFormatAttribivEXT(dc, fmt+1, 0, num_attribs, attrib, value);
   }
   else {
      ret = 0;
   }
   
   if (!ret) {
      ALLEGRO_ERROR("wglGetPixelFormatAttrib failed! %s\n",
                     get_error_desc(GetLastError()));
      al_free(value);
      return NULL;
   }

   eds = al_calloc(1, sizeof *eds);
   if (!decode_pixel_format_attrib(eds, num_attribs, attrib, value)) {
      al_free(eds);
      eds = NULL;
   }

   al_free(value);
   
   /* Hack: for some reason this happens for me under Wine. */
   if (eds &&
      eds->settings[ALLEGRO_RED_SHIFT] == 0 &&
         eds->settings[ALLEGRO_GREEN_SHIFT] == 0 &&
         eds->settings[ALLEGRO_BLUE_SHIFT] == 0 &&
         eds->settings[ALLEGRO_ALPHA_SHIFT] == 0) {
      eds->settings[ALLEGRO_RED_SHIFT] = 0;
      eds->settings[ALLEGRO_GREEN_SHIFT] = 8;
      eds->settings[ALLEGRO_BLUE_SHIFT] = 16;
      eds->settings[ALLEGRO_ALPHA_SHIFT] = 24;
   }

   return eds;
}
Esempio n. 15
0
/*
 * The window must be created in the same thread that
 * runs the message loop.
 */
static void display_thread_proc(void *arg)
{
   WGL_DISPLAY_PARAMETERS *ndp = arg;
   ALLEGRO_DISPLAY *disp = (ALLEGRO_DISPLAY*)ndp->display;
   ALLEGRO_DISPLAY_WGL *wgl_disp = (void*)disp;
   ALLEGRO_DISPLAY_WIN *win_disp = (void*)disp;
   MSG msg;

   al_set_new_window_position(ndp->window_x, ndp->window_y);

   /* So that we can call the functions using TLS from this thread. */
   al_set_new_display_flags(disp->flags);
   
   if (disp->flags & ALLEGRO_FULLSCREEN) {
      if (!change_display_mode(disp)) {
         win_disp->thread_ended = true;
         destroy_display_internals(wgl_disp);
         SetEvent(ndp->AckEvent);
         return;
      }
   }
   else if (disp->flags & ALLEGRO_FULLSCREEN_WINDOW) {
      ALLEGRO_MONITOR_INFO mi;
      int adapter = win_disp->adapter;
      al_get_monitor_info(adapter, &mi);
      win_disp->toggle_w = disp->w;
      win_disp->toggle_h = disp->h;
      disp->w = mi.x2 - mi.x1;
      disp->h = mi.y2 - mi.y1;
   }
   else {
      win_disp->toggle_w = disp->w;
      win_disp->toggle_h = disp->h;
   }

   win_disp->window = _al_win_create_window(disp, disp->w, disp->h, disp->flags);

   if (!win_disp->window) {
      win_disp->thread_ended = true;
      destroy_display_internals(wgl_disp);
      SetEvent(ndp->AckEvent);
      return;
   }

   /* FIXME: can't _al_win_create_window() do this? */
   if ((disp->flags & ALLEGRO_FULLSCREEN) ||
         (disp->flags & ALLEGRO_FULLSCREEN_WINDOW)) {
      RECT rect;
      rect.left = 0;
      rect.right = disp->w;
      rect.top  = 0;
      rect.bottom = disp->h;
      SetWindowPos(win_disp->window, 0, rect.left, rect.top,
             rect.right - rect.left, rect.bottom - rect.top,
             SWP_NOZORDER | SWP_FRAMECHANGED);
   }
   
   if (disp->flags & ALLEGRO_FULLSCREEN_WINDOW) {
      bool frameless = true;
      _al_win_set_window_frameless(disp, win_disp->window, disp->w, disp->h, frameless);
   }

   /* Yep, the following is really needed sometimes. */
   /* ... Or is it now that we have dumped DInput? */
   /* <rohannessian> Win98/2k/XP's window forground rules don't let us
    * make our window the topmost window on launch. This causes issues on 
    * full-screen apps, as DInput loses input focus on them.
    * We use this trick to force the window to be topmost, when switching
    * to full-screen only. Note that this only works for Win98 and greater.
    * Win95 will ignore our SystemParametersInfo() calls.
    * 
    * See http://support.microsoft.com:80/support/kb/articles/Q97/9/25.asp
    * for details.
    */
   {
      DWORD lock_time;
      HWND wnd = win_disp->window;

#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
      if (disp->flags & ALLEGRO_FULLSCREEN) {
         SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,
               0, (LPVOID)&lock_time, 0);
         SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,
               0, (LPVOID)0, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
      }

      ShowWindow(wnd, SW_SHOWNORMAL);
      SetForegroundWindow(wnd);
      /* In some rare cases, it doesn't seem to work without the loop. And we
       * absolutely need this to succeed, else we trap the user in a
       * fullscreen window without input.
       */
      while (GetForegroundWindow() != wnd) {
         al_rest(0.01);
         SetForegroundWindow(wnd);
      }
      UpdateWindow(wnd);

      if (disp->flags & ALLEGRO_FULLSCREEN) {
         SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,
              0, (LPVOID)(DWORD)lock_time, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
      }
#undef SPI_GETFOREGROUNDLOCKTIMEOUT
#undef SPI_SETFOREGROUNDLOCKTIMEOUT
   }

#if 0
   if (disp->flags & ALLEGRO_FULLSCREEN && al_is_mouse_installed()) {
      RAWINPUTDEVICE rid[1];
      rid[0].usUsagePage = 0x01; 
      rid[0].usUsage = 0x02; 
      rid[0].dwFlags = RIDEV_NOLEGACY;
      rid[0].hwndTarget = 0;
      if (RegisterRawInputDevices(rid, 1, sizeof(rid[0])) == FALSE) {
          ALLEGRO_ERROR(
             "Failed to init mouse. %s\n", get_error_desc(GetLastError()));
      }
   }
#endif

   /* get the device context of our window */
   wgl_disp->dc = GetDC(win_disp->window);

   win_disp->thread_ended = false;
   win_disp->end_thread = false;
   ndp->init_failed = false;
   SetEvent(ndp->AckEvent);

   while (!win_disp->end_thread) {
      /* get a message from the queue */
      if (GetMessage(&msg, NULL, 0, 0) != 0)
         DispatchMessage(&msg);
      else
         break;                 /* WM_QUIT received or error (GetMessage returned -1)  */
   }

   if (wgl_disp->glrc) {
      wglDeleteContext(wgl_disp->glrc);
      wgl_disp->glrc = NULL;
   }
   if (wgl_disp->dc) {
      ReleaseDC(win_disp->window, wgl_disp->dc);
      wgl_disp->dc = NULL;
   }

   if (disp->flags & ALLEGRO_FULLSCREEN && !_wgl_do_not_change_display_mode) {
      ChangeDisplaySettings(NULL, 0);
   }

   if (win_disp->window) {
      DestroyWindow(win_disp->window);
      win_disp->window = NULL;
   }

   ALLEGRO_INFO("wgl display thread exits\n");
   win_disp->thread_ended = true;
}
Esempio n. 16
0
/*------------------------------------------------------------------------*/
const char* CU_get_error_msg(void)
{
	return get_error_desc(g_error_number);
}