VirtualBox

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

Last change on this file since 2426 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/** @file
2 *
3 * VBox frontends: Framebuffer (FB, DirectFB):
4 * Helper routines
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#include "VBoxFB.h"
24#include "Helper.h"
25
26/**
27 * Globals
28 */
29videoMode videoModes[MAX_VIDEOMODES] = {0};
30uint32_t numVideoModes = 0;
31
32/**
33 * callback handler for populating the supported video modes
34 *
35 * @returns callback success indicator
36 * @param width width in pixels of the current video mode
37 * @param height height in pixels of the current video mode
38 * @param bpp bits per pixel of the current video mode
39 * @param callbackdata user data pointer
40 */
41DFBEnumerationResult enumVideoModesHandler(int width, int height, int bpp, void *callbackdata)
42{
43 if (numVideoModes >= MAX_VIDEOMODES)
44 {
45 return DFENUM_CANCEL;
46 }
47 // don't take palette based modes
48 if (bpp >= 16)
49 {
50 // don't take modes we already have (I have seen many cases where
51 // DirectFB returns the same modes several times)
52 int32_t existingMode = getBestVideoMode(width, height, bpp);
53 if ((existingMode == -1) ||
54 ((videoModes[existingMode].width != (uint32_t)width) ||
55 (videoModes[existingMode].height != (uint32_t)height) ||
56 (videoModes[existingMode].bpp != (uint32_t)bpp)))
57 {
58 videoModes[numVideoModes].width = (uint32_t)width;
59 videoModes[numVideoModes].height = (uint32_t)height;
60 videoModes[numVideoModes].bpp = (uint32_t)bpp;
61 numVideoModes++;
62 }
63 }
64 return DFENUM_OK;
65}
66
67/**
68 * Returns the best fitting video mode for the given characteristics.
69 *
70 * @returns index of the best video mode, -1 if no suitable mode found
71 * @param width requested width
72 * @param height requested height
73 * @param bpp requested bit depth
74 */
75int32_t getBestVideoMode(uint32_t width, uint32_t height, uint32_t bpp)
76{
77 int32_t bestMode = -1;
78
79 for (uint32_t i = 0; i < numVideoModes; i++)
80 {
81 // is this mode compatible?
82 if ((videoModes[i].width >= width) && (videoModes[i].height >= height) &&
83 (videoModes[i].bpp >= bpp))
84 {
85 // first suitable mode?
86 if (bestMode == -1)
87 {
88 bestMode = i;
89 } else
90 {
91 // is it better than the one we got before?
92 if ((videoModes[i].width < videoModes[bestMode].width) ||
93 (videoModes[i].height < videoModes[bestMode].height) ||
94 (videoModes[i].bpp < videoModes[bestMode].bpp))
95 {
96 bestMode = i;
97 }
98 }
99 }
100 }
101 return bestMode;
102}
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