VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxFB/Helper.cpp@ 103914

Last change on this file since 103914 was 98176, checked in by vboxsync, 23 months ago

VBoxFB: Made the code build again (still doesn't actually work) and switched it from the VBOXR3NPEXE to the VBOXMAINCLIENTEXE template. bugref:10348

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: Helper.cpp 98176 2023-01-21 22:09:36Z vboxsync $ */
2/** @file
3 * VBoxFB - Helper routines.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#include "VBoxFB.h"
29#include "Helper.h"
30
31/**
32 * Globals
33 */
34videoMode g_videoModes[MAX_VIDEOMODES] = {{0}};
35uint32_t g_numVideoModes = 0;
36
37/**
38 * callback handler for populating the supported video modes
39 *
40 * @returns callback success indicator
41 * @param width width in pixels of the current video mode
42 * @param height height in pixels of the current video mode
43 * @param bpp bits per pixel of the current video mode
44 * @param callbackdata user data pointer
45 */
46DFBEnumerationResult enumVideoModesHandler(int width, int height, int bpp, void *callbackdata)
47{
48 RT_NOREF(callbackdata);
49 if (g_numVideoModes >= MAX_VIDEOMODES)
50 {
51 return DFENUM_CANCEL;
52 }
53 // don't take palette based modes
54 if (bpp >= 16)
55 {
56 // don't take modes we already have (I have seen many cases where
57 // DirectFB returns the same modes several times)
58 int32_t existingMode = getBestVideoMode(width, height, bpp);
59 if ( existingMode == -1
60 || g_videoModes[existingMode].width != (uint32_t)width
61 || g_videoModes[existingMode].height != (uint32_t)height
62 || g_videoModes[existingMode].bpp != (uint32_t)bpp)
63 {
64 g_videoModes[g_numVideoModes].width = (uint32_t)width;
65 g_videoModes[g_numVideoModes].height = (uint32_t)height;
66 g_videoModes[g_numVideoModes].bpp = (uint32_t)bpp;
67 g_numVideoModes++;
68 }
69 }
70 return DFENUM_OK;
71}
72
73/**
74 * Returns the best fitting video mode for the given characteristics.
75 *
76 * @returns index of the best video mode, -1 if no suitable mode found
77 * @param width requested width
78 * @param height requested height
79 * @param bpp requested bit depth
80 */
81int32_t getBestVideoMode(uint32_t width, uint32_t height, uint32_t bpp)
82{
83 int32_t bestMode = -1;
84
85 for (uint32_t i = 0; i < g_numVideoModes; i++)
86 {
87 // is this mode compatible?
88 if (g_videoModes[i].width >= width && g_videoModes[i].height >= height && g_videoModes[i].bpp >= bpp)
89 {
90 // first suitable mode?
91 if (bestMode == -1)
92 bestMode = i;
93 else
94 {
95 // is it better than the one we got before?
96 if ( g_videoModes[i].width < g_videoModes[bestMode].width
97 || g_videoModes[i].height < g_videoModes[bestMode].height
98 || g_videoModes[i].bpp < g_videoModes[bestMode].bpp)
99 {
100 bestMode = i;
101 }
102 }
103 }
104 }
105 return bestMode;
106}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette