Beispiel #1
0
unsigned int get_timer_ticks_per_draw() {
    if (get_refresh_rate() != 0) {
        const unsigned i = timer_ticks_per_second / get_refresh_rate();
        if (i > 0) return i;
        else       return 1;
    }
    else return 1; // was previously gloB->screen_vsync + 1;
}
Beispiel #2
0
void
screen_mode::SetTo(display_mode& mode)
{
	width = mode.virtual_width;
	height = mode.virtual_height;
	space = (color_space)mode.space;
	refresh = get_refresh_rate(mode);
}
Beispiel #3
0
static int
compare_mode(const void* _mode1, const void* _mode2)
{
	display_mode *mode1 = (display_mode *)_mode1;
	display_mode *mode2 = (display_mode *)_mode2;

	uint16 width1, width2, height1, height2;
	width1 = mode1->virtual_width;
	height1 = mode1->virtual_height;
	width2 = mode2->virtual_width;
	height2 = mode2->virtual_height;

	if (width1 != width2)
		return width1 - width2;

	if (height1 != height2)
		return height1 - height2;

	return (int)(10 * get_refresh_rate(*mode1) - 10 * get_refresh_rate(*mode2));
}
Beispiel #4
0
bool
ScreenMode::GetDisplayMode(const screen_mode& mode, display_mode& displayMode)
{
	uint16 virtualWidth, virtualHeight;
	int32 bestIndex = -1;
	float bestDiff = 999;

	virtualWidth = mode.width;
	virtualHeight = mode.height;

	// try to find mode in list provided by driver
	for (uint32 i = 0; i < fModeCount; i++) {
		if (fModeList[i].virtual_width != virtualWidth
			|| fModeList[i].virtual_height != virtualHeight
			|| (color_space)fModeList[i].space != mode.space)
			continue;

		float refresh = get_refresh_rate(fModeList[i]);
		if (refresh == mode.refresh) {
			// we have luck - we can use this mode directly
			displayMode = fModeList[i];
			displayMode.h_display_start = 0;
			displayMode.v_display_start = 0;
			return true;
		}

		float diff = fabs(refresh - mode.refresh);
		if (diff < bestDiff) {
			bestDiff = diff;
			bestIndex = i;
		}
	}

	// we didn't find the exact mode, but something very similar?
	if (bestIndex == -1)
		return false;

	// now, we are better of using GMT formula, but
	// as we don't have it, we just tune the pixel
	// clock of the best mode.

	displayMode = fModeList[bestIndex];
	displayMode.h_display_start = 0;
	displayMode.v_display_start = 0;

	// after some fiddling, it looks like this is the formula
	// used by the original panel (notice that / 10 happens before
	// multiplying with refresh rate - this leads to different
	// rounding)
	displayMode.timing.pixel_clock = ((uint32)displayMode.timing.h_total
		* displayMode.timing.v_total / 10 * int32(mode.refresh * 10)) / 1000;

	return true;
}
Beispiel #5
0
boolean
stw_init(const struct stw_winsys *stw_winsys)
{
   static struct stw_device stw_dev_storage;
   struct pipe_screen *screen;

   debug_disable_error_message_boxes();

   debug_printf("%s\n", __FUNCTION__);

   assert(!stw_dev);

   stw_tls_init();

   stw_dev = &stw_dev_storage;
   memset(stw_dev, 0, sizeof(*stw_dev));

#ifdef DEBUG
   stw_dev->memdbg_no = debug_memory_begin();
#endif

   stw_dev->stw_winsys = stw_winsys;

   stw_dev->stapi = stw_st_create_api();
   stw_dev->smapi = CALLOC_STRUCT(st_manager);
   if (!stw_dev->stapi || !stw_dev->smapi)
      goto error1;

   screen = stw_winsys->create_screen();
   if (!screen)
      goto error1;

   if (stw_winsys->get_adapter_luid)
      stw_winsys->get_adapter_luid(screen, &stw_dev->AdapterLuid);

   stw_dev->smapi->screen = screen;
   stw_dev->smapi->get_param = stw_get_param;
   stw_dev->screen = screen;

   stw_dev->max_2d_levels =
         screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS);
   stw_dev->max_2d_length = 1 << (stw_dev->max_2d_levels - 1);

   InitializeCriticalSection(&stw_dev->ctx_mutex);
   InitializeCriticalSection(&stw_dev->fb_mutex);

   stw_dev->ctx_table = handle_table_create();
   if (!stw_dev->ctx_table) {
      goto error1;
   }

   stw_pixelformat_init();

   /* env var override for WGL_EXT_swap_control, useful for testing/debugging */
   const char *s = os_get_option("WGL_SWAP_INTERVAL");
   if (s) {
      stw_dev->swap_interval = atoi(s);
   }
   stw_dev->refresh_rate = get_refresh_rate();

   stw_dev->initialized = true;

   return TRUE;

error1:
   FREE(stw_dev->smapi);
   if (stw_dev->stapi)
      stw_dev->stapi->destroy(stw_dev->stapi);

   stw_dev = NULL;
   return FALSE;
}
Beispiel #6
0
static bool init_sdl(const char * fileLoc) {

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
        std::cerr << "Could not initialize SDL : " << SDL_GetError() << std::endl;
        return false;
    }

    /*  START VIDEO */
    //set window title
    char windowTitle[100];
    strcpy(windowTitle, "XeNES: ");
    strcat(windowTitle, fileLoc);

    int outputHeight;

    if (REMOVE_OVERSCAN) {
        outputHeight = (NES_SCREEN_HEIGHT - 16);
    } else {
        outputHeight = NES_SCREEN_HEIGHT;
    }

    window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
        NES_SCREEN_WIDTH * SCALE_FACTOR, outputHeight * SCALE_FACTOR, SDL_WINDOW_RESIZABLE);

    if (window == NULL) {
        std::cerr << "Could not create SDL window : " << SDL_GetError() << std::endl;
        SDL_Quit();
        return false;
    }

    //SDL_RENDERER_PRESENTVSYNC
    if (get_refresh_rate(window) == 60) {
    	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
    	SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
    } else {	
    	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    	SDL_SetHint(SDL_HINT_RENDER_VSYNC, "0");
    }
    

    if (renderer == NULL) {
        std::cerr << "Could not create SDL renderer : " << SDL_GetError() << std::endl;
        SDL_DestroyWindow(window);
        SDL_Quit();
        return false;
    }

    texture = SDL_CreateTexture(renderer,
        SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, NES_SCREEN_WIDTH, outputHeight);

    if (texture == NULL) {
        std::cerr << "Could not create SDL texture : " << SDL_GetError() << std::endl;
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        return false;
    }

    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 0); 
    /* END VIDEO */

    /* START AUDIO */
    SDL_AudioSpec want;
    SDL_memset(&want, 0, sizeof(want));

    SDL_AudioSpec have;
    want.freq = samplingFrequency;
    want.format = format;        //32-bit floating point samples in little-endian byte order
    want.channels = channels;
    want.samples = samplingFrequency * sampleBytes / 60;

    sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);

    if (sdlAudioDevice == 0) {
        std::cerr << "Failed to open audio : " << SDL_GetError() << std::endl;
        SDL_DestroyTexture(texture);
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        return false;
    }

    /* END AUDIO */
    
    return true;
}