VirtualBox

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

Last change on this file since 97364 was 96407, checked in by vboxsync, 22 months ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/** @file
2 *
3 * VBox frontends: Framebuffer (FB, DirectFB):
4 * Helper routines
5 */
6
7/*
8 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
9 *
10 * This file is part of VirtualBox base platform packages, as
11 * available from https://www.virtualbox.org.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation, in version 3 of the
16 * License.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <https://www.gnu.org/licenses>.
25 *
26 * SPDX-License-Identifier: GPL-3.0-only
27 */
28
29#include "VBoxFB.h"
30#include "Helper.h"
31
32/**
33 * Globals
34 */
35videoMode videoModes[MAX_VIDEOMODES] = {{0}};
36uint32_t numVideoModes = 0;
37
38/**
39 * callback handler for populating the supported video modes
40 *
41 * @returns callback success indicator
42 * @param width width in pixels of the current video mode
43 * @param height height in pixels of the current video mode
44 * @param bpp bits per pixel of the current video mode
45 * @param callbackdata user data pointer
46 */
47DFBEnumerationResult enumVideoModesHandler(int width, int height, int bpp, void *callbackdata)
48{
49 if (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 ((videoModes[existingMode].width != (uint32_t)width) ||
61 (videoModes[existingMode].height != (uint32_t)height) ||
62 (videoModes[existingMode].bpp != (uint32_t)bpp)))
63 {
64 videoModes[numVideoModes].width = (uint32_t)width;
65 videoModes[numVideoModes].height = (uint32_t)height;
66 videoModes[numVideoModes].bpp = (uint32_t)bpp;
67 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 < numVideoModes; i++)
86 {
87 // is this mode compatible?
88 if ((videoModes[i].width >= width) && (videoModes[i].height >= height) &&
89 (videoModes[i].bpp >= bpp))
90 {
91 // first suitable mode?
92 if (bestMode == -1)
93 {
94 bestMode = i;
95 } else
96 {
97 // is it better than the one we got before?
98 if ((videoModes[i].width < videoModes[bestMode].width) ||
99 (videoModes[i].height < videoModes[bestMode].height) ||
100 (videoModes[i].bpp < videoModes[bestMode].bpp))
101 {
102 bestMode = i;
103 }
104 }
105 }
106 }
107 return bestMode;
108}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use