コード例 #1
0
ファイル: graphics_mode.cpp プロジェクト: ScummQuest/ags
void log_out_driver_modes(const int color_depth)
{
    IGfxModeList *modes = gfxDriver->GetSupportedModeList(color_depth);
    if (!modes)
    {
        Out::FPrint("Couldn't get a list of supported resolutions for color depth = %d", color_depth);
        return;
    }
    const int mode_count = modes->GetModeCount();
    DisplayResolution mode;
    String mode_str;
    for (int i = 0, in_str = 0; i < mode_count; ++i)
    {
        if (!modes->GetMode(i, mode) || mode.ColorDepth != color_depth)
            continue;
        mode_str.Append(String::FromFormat("%dx%d;", mode.Width, mode.Height));
        if (++in_str % 8 == 0)
            mode_str.Append("\n\t");
    }
    delete modes;

    String out_str = String::FromFormat("Supported gfx modes (%d-bit): ", color_depth);
    if (!mode_str.IsEmpty())
    {
        out_str.Append("\n\t");
        out_str.Append(mode_str);
    }
    else
        out_str.Append("none");
    Out::FPrint(out_str);
}
コード例 #2
0
ファイル: graphics_mode.cpp プロジェクト: salty-horse/ags
int find_max_supported_uniform_scaling(const Size &base_size, Size &found_size, const int color_depth,
                                          const Size *ratio_reference = NULL, const bool keep_width = false, const bool keep_height = false)
{
    IGfxModeList *modes = gfxDriver->GetSupportedModeList(color_depth);
    if (!modes)
    {
        Out::FPrint("Couldn't get a list of supported resolutions");
        return 0;
    }

    int wanted_ratio = 0;
    if (ratio_reference)
    {
        wanted_ratio = (ratio_reference->Height << 10) / ratio_reference->Width;
    }

    int least_supported_scaling = 0;
    int mode_count = modes->GetModeCount();
    DisplayResolution mode;
    for (int i = 0; i < mode_count; ++i)
    {
        if (!modes->GetMode(i, mode))
        {
            continue;
        }
        if (mode.ColorDepth != color_depth)
        {
            continue;
        }
        if (wanted_ratio > 0)
        {
            int mode_ratio = (mode.Height << 10) / mode.Width;
            if (mode_ratio != wanted_ratio)
            {
                continue;
            }
        }

        if (mode.Width >= base_size.Width &&
            mode.Height >= base_size.Height)
        {
            int scaling_factor;
            if (is_scaling_supported(base_size, mode, 0, scaling_factor) &&
                (!keep_width  || mode.Width  / scaling_factor == base_size.Width) &&
                (!keep_height || mode.Height / scaling_factor == base_size.Height) &&
                scaling_factor > least_supported_scaling)
            {
                found_size = Size(mode.Width, mode.Height);
                least_supported_scaling = scaling_factor;
            }
        }
    }

    delete modes;
    return least_supported_scaling;
}
コード例 #3
0
ファイル: graphics_mode.cpp プロジェクト: Kitai/agsfr
int find_max_supported_uniform_multiplier(const Size &base_size, const int color_depth, int width_range_allowed)
{
    IGfxModeList *modes = gfxDriver->GetSupportedModeList(color_depth);
    if (!modes)
    {
        Out::FPrint("Couldn't get a list of supported resolutions");
        return 0;
    }

    int least_supported_multiplier = 0;
    int mode_count = modes->GetModeCount();
    DisplayResolution mode;
    for (int i = 0; i < mode_count; ++i)
    {
        if (!modes->GetMode(i, mode))
        {
            continue;
        }
        if (mode.ColorDepth != color_depth)
        {
            continue;
        }

        if (mode.Width > base_size.Width &&
            mode.Height > base_size.Height && mode.Height % base_size.Height == 0)
        {
            int multiplier_x = mode.Width / base_size.Width;
            int remainder_x = mode.Width % base_size.Width;
            int multiplier_y = mode.Height / base_size.Height;
            if (multiplier_x == multiplier_y && (remainder_x / multiplier_x <= width_range_allowed) &&
                multiplier_x > least_supported_multiplier)
            {
                least_supported_multiplier = multiplier_x;
            }
        }
    }

    delete modes;

    if (least_supported_multiplier == 0)
    {
        Out::FPrint("Couldn't find acceptable supported resolution");
    }
    return least_supported_multiplier;
}
コード例 #4
0
ファイル: graphics_mode.cpp プロジェクト: salty-horse/ags
bool find_nearest_supported_mode(const Size &base_size, const int scaling_factor, Size &found_size, const int color_depth,
                                 const Size *ratio_reference = NULL, const bool keep_width = false, const bool keep_height = false)
{
    IGfxModeList *modes = gfxDriver->GetSupportedModeList(color_depth);
    if (!modes)
    {
        Out::FPrint("Couldn't get a list of supported resolutions");
        return false;
    }

    Size wanted_size = base_size * scaling_factor;
    int wanted_ratio = 0;
    if (ratio_reference)
    {
        wanted_ratio = (ratio_reference->Height << 10) / ratio_reference->Width;
    }
    
    int nearest_width = 0;
    int nearest_height = 0;
    int nearest_width_diff = 0;
    int nearest_height_diff = 0;
    int mode_count = modes->GetModeCount();
    DisplayResolution mode;
    for (int i = 0; i < mode_count; ++i)
    {
        if (!modes->GetMode(i, mode))
        {
            continue;
        }
        if (mode.ColorDepth != color_depth)
        {
            continue;
        }
        if (wanted_ratio > 0)
        {
            int mode_ratio = (mode.Height << 10) / mode.Width;
            if (mode_ratio != wanted_ratio)
            {
                continue;
            }
        }
        if (mode.Width == wanted_size.Width && mode.Height == wanted_size.Height)
        {
            nearest_width = mode.Width;
            nearest_height = mode.Height;
            break;
        }
        if (keep_width && mode.Width != wanted_size.Width ||
            keep_height && mode.Height != wanted_size.Height ||
            // current implementation does not allow downscaling
            mode.Width < wanted_size.Width ||
            mode.Height < wanted_size.Height)
        {
            continue;
        }
      
        int diff_w = abs(wanted_size.Width - mode.Width);
        int diff_h = abs(wanted_size.Height - mode.Height);
        bool same_diff_w_higher = (diff_w == nearest_width_diff && nearest_width < mode.Width);
        bool same_diff_h_higher = (diff_h == nearest_height_diff && nearest_height < mode.Height);

        int multiplier;
        if (is_scaling_supported(base_size, mode, scaling_factor, multiplier) &&
            nearest_width == 0 ||
            (diff_w < nearest_width_diff || same_diff_w_higher) && diff_h <= nearest_height_diff ||
            (diff_h < nearest_height_diff || same_diff_h_higher) && diff_w <= nearest_width_diff)
        {
            nearest_width = mode.Width;
            nearest_width_diff = diff_w;
            nearest_height = mode.Height;
            nearest_height_diff = diff_h;
        }
    }

    delete modes;
    if (nearest_width > 0 && nearest_height > 0)
    {
        found_size.Width = nearest_width;
        found_size.Height = nearest_height;
        return true;
    }
    return false;
}
コード例 #5
0
ファイル: graphics_mode.cpp プロジェクト: Farious/ags
bool find_nearest_supported_mode(const IGfxModeList &modes, Size &wanted_size, int *mode_index, const int color_depth,
                                 const Size *ratio_reference, const Size *upper_bound)
{
    uint32_t wanted_ratio = 0;
    if (ratio_reference && !ratio_reference->IsNull())
    {
        wanted_ratio = (ratio_reference->Height << kShift) / ratio_reference->Width;
    }
    
    int nearest_width = 0;
    int nearest_height = 0;
    int nearest_width_diff = 0;
    int nearest_height_diff = 0;
    int nearest_mode_index = -1;
    int mode_count = modes.GetModeCount();
    DisplayMode mode;
    for (int i = 0; i < mode_count; ++i)
    {
        if (!modes.GetMode(i, mode))
        {
            continue;
        }
        if (mode.ColorDepth != color_depth)
        {
            continue;
        }
        if (wanted_ratio > 0)
        {
            uint32_t mode_ratio = (mode.Height << kShift) / mode.Width;
            if (mode_ratio != wanted_ratio)
            {
                continue;
            }
        }
        if (upper_bound && (mode.Width > upper_bound->Width || mode.Height > upper_bound->Height))
            continue;
        if (mode.Width == wanted_size.Width && mode.Height == wanted_size.Height)
        {
            nearest_width = mode.Width;
            nearest_height = mode.Height;
            nearest_mode_index = i;
            break;
        }
      
        int diff_w = abs(wanted_size.Width - mode.Width);
        int diff_h = abs(wanted_size.Height - mode.Height);
        bool same_diff_w_higher = (diff_w == nearest_width_diff && nearest_width < wanted_size.Width);
        bool same_diff_h_higher = (diff_h == nearest_height_diff && nearest_height < wanted_size.Height);

        if (nearest_width == 0 ||
            (diff_w < nearest_width_diff || same_diff_w_higher) && diff_h <= nearest_height_diff ||
            (diff_h < nearest_height_diff || same_diff_h_higher) && diff_w <= nearest_width_diff)
        {
            nearest_width = mode.Width;
            nearest_width_diff = diff_w;
            nearest_height = mode.Height;
            nearest_height_diff = diff_h;
            nearest_mode_index = i;
        }
    }

    if (nearest_width > 0 && nearest_height > 0)
    {
        wanted_size.Width = nearest_width;
        wanted_size.Height = nearest_height;
        if (mode_index)
            *mode_index = nearest_mode_index;
        return true;
    }
    return false;
}
コード例 #6
0
ファイル: graphics_mode.cpp プロジェクト: Kitai/agsfr
int find_supported_resolution_width(const Size &ideal_size, int color_depth, int width_range_allowed)
{
    // Temporary hack for incomplete OpenGL driver (always returns ideal width)
    if (strcmp(gfxDriver->GetDriverID(), "OGL") == 0)
    {
        return ideal_size.Width;
    }

    IGfxModeList *modes = gfxDriver->GetSupportedModeList(color_depth);
    if (!modes)
    {
        Out::FPrint("Couldn't get a list of supported resolutions");
        return 0;
    }

    int ideal_width_scaled = ideal_size.Width;
    int ideal_height_scaled = ideal_size.Height;
    filter->GetRealResolution(&ideal_width_scaled, &ideal_height_scaled);
    const int filter_factor = ideal_width_scaled / ideal_size.Width;
    const int max_width_diff = width_range_allowed * filter_factor;

    int nearest_width = 0;
    int mode_count = modes->GetModeCount();
    DisplayResolution mode;
    for (int i = 0; i < mode_count; ++i)
    {
        if (!modes->GetMode(i, mode))
        {
            continue;
        }
        if (mode.ColorDepth != color_depth)
        {
            continue;
        }

        if (mode.Height == ideal_height_scaled)
        {
            if (mode.Width == ideal_width_scaled)
            {
                nearest_width = mode.Width;
                break;
            }

            const int mode_diff    = abs(mode.Width - ideal_width_scaled);
            const int nearest_diff = abs(nearest_width - ideal_width_scaled);
            if (mode_diff <= max_width_diff &&
                (mode_diff < nearest_diff ||
                 mode_diff == nearest_diff && mode.Width > nearest_diff))
            {
                nearest_width = mode.Width;
            }
        }
    }

    delete modes;

    if (nearest_width == 0)
    {
        Out::FPrint("Couldn't find acceptable supported resolution");
    }
    return nearest_width / filter_factor;
}