VirtualBox

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

Last change on this file since 12467 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • 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-2007 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
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