|
Blender
V2.59
|
00001 /* 00002 * $Id: GHOST_DisplayManager.cpp 35152 2011-02-25 11:28:33Z jesterking $ 00003 * ***** BEGIN GPL LICENSE BLOCK ***** 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software Foundation, 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00020 * All rights reserved. 00021 * 00022 * The Original Code is: all of this file. 00023 * 00024 * Contributor(s): none yet. 00025 * 00026 * ***** END GPL LICENSE BLOCK ***** 00027 */ 00028 00040 #include "GHOST_DisplayManager.h" 00041 #include "GHOST_Debug.h" 00042 00043 00044 GHOST_DisplayManager::GHOST_DisplayManager( 00045 void) 00046 : m_settingsInitialized(false) 00047 { 00048 } 00049 00050 00051 GHOST_DisplayManager::~GHOST_DisplayManager(void) 00052 { 00053 } 00054 00055 00056 GHOST_TSuccess 00057 GHOST_DisplayManager::initialize( 00058 void) 00059 { 00060 GHOST_TSuccess success; 00061 if (!m_settingsInitialized) { 00062 success = initializeSettings(); 00063 m_settingsInitialized = true; 00064 } 00065 else { 00066 success = GHOST_kSuccess; 00067 } 00068 return success; 00069 } 00070 00071 00072 GHOST_TSuccess 00073 GHOST_DisplayManager::getNumDisplays( 00074 GHOST_TUns8& /*numDisplays*/) const 00075 { 00076 // Don't know if we have a display... 00077 return GHOST_kFailure; 00078 } 00079 00080 00081 GHOST_TSuccess 00082 GHOST_DisplayManager::getNumDisplaySettings( 00083 GHOST_TUns8 display, 00084 GHOST_TInt32& numSettings) const 00085 { 00086 GHOST_TSuccess success; 00087 00088 GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::getNumDisplaySettings(): m_settingsInitialized=false"); 00089 GHOST_TUns8 numDisplays; 00090 success = getNumDisplays(numDisplays); 00091 if (success == GHOST_kSuccess) { 00092 if (display < numDisplays) { 00093 numSettings = m_settings[display].size(); 00094 } 00095 else { 00096 success = GHOST_kFailure; 00097 } 00098 } 00099 return success; 00100 } 00101 00102 00103 GHOST_TSuccess 00104 GHOST_DisplayManager::getDisplaySetting( 00105 GHOST_TUns8 display, 00106 GHOST_TInt32 index, 00107 GHOST_DisplaySetting& setting) const 00108 { 00109 GHOST_TSuccess success; 00110 00111 GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::getNumDisplaySettings(): m_settingsInitialized=false"); 00112 GHOST_TUns8 numDisplays; 00113 success = getNumDisplays(numDisplays); 00114 if (success == GHOST_kSuccess) { 00115 if (display < numDisplays && ((GHOST_TUns8)index < m_settings[display].size())) { 00116 setting = m_settings[display][index]; 00117 } 00118 else { 00119 success = GHOST_kFailure; 00120 } 00121 } 00122 return success; 00123 } 00124 00125 00126 GHOST_TSuccess 00127 GHOST_DisplayManager::getCurrentDisplaySetting( 00128 GHOST_TUns8 /*display*/, 00129 GHOST_DisplaySetting& /*setting*/) const 00130 { 00131 return GHOST_kFailure; 00132 } 00133 00134 00135 GHOST_TSuccess 00136 GHOST_DisplayManager::setCurrentDisplaySetting( 00137 GHOST_TUns8 /*display*/, 00138 const GHOST_DisplaySetting& /*setting*/) 00139 { 00140 return GHOST_kFailure; 00141 } 00142 00143 00144 GHOST_TSuccess 00145 GHOST_DisplayManager::findMatch( 00146 GHOST_TUns8 display, 00147 const GHOST_DisplaySetting& setting, 00148 GHOST_DisplaySetting& match) const 00149 { 00150 GHOST_TSuccess success = GHOST_kSuccess; 00151 GHOST_ASSERT(m_settingsInitialized, "GHOST_DisplayManager::findMatch(): m_settingsInitialized=false"); 00152 00153 int criteria[4] = { setting.xPixels, setting.yPixels, setting.bpp, setting.frequency }; 00154 int capabilities[4]; 00155 double field, score; 00156 double best = 1e12; // A big number 00157 int found = 0; 00158 00159 // Look at all the display modes 00160 for (int i = 0; (i < (int)m_settings[display].size()); i++) { 00161 // Store the capabilities of the display device 00162 capabilities[0] = m_settings[display][i].xPixels; 00163 capabilities[1] = m_settings[display][i].yPixels; 00164 capabilities[2] = m_settings[display][i].bpp; 00165 capabilities[3] = m_settings[display][i].frequency; 00166 00167 // Match against all the fields of the display settings 00168 score = 0; 00169 for (int j = 0; j < 4; j++) { 00170 field = capabilities[j] - criteria[j]; 00171 score += field * field; 00172 } 00173 00174 if (score < best) { 00175 found = i; 00176 best = score; 00177 } 00178 } 00179 00180 match = m_settings[display][found]; 00181 00182 GHOST_PRINT("GHOST_DisplayManager::findMatch(): settings of match:\n"); 00183 GHOST_PRINT(" setting.xPixels=" << match.xPixels << "\n"); 00184 GHOST_PRINT(" setting.yPixels=" << match.yPixels << "\n"); 00185 GHOST_PRINT(" setting.bpp=" << match.bpp << "\n"); 00186 GHOST_PRINT(" setting.frequency=" << match.frequency << "\n"); 00187 00188 return success; 00189 } 00190 00191 00192 GHOST_TSuccess 00193 GHOST_DisplayManager::initializeSettings( 00194 void) 00195 { 00196 GHOST_TUns8 numDisplays; 00197 GHOST_TSuccess success = getNumDisplays(numDisplays); 00198 if (success == GHOST_kSuccess) { 00199 for (GHOST_TUns8 display = 0; (display < numDisplays) && (success == GHOST_kSuccess); display++) { 00200 GHOST_DisplaySettings displaySettings; 00201 m_settings.push_back(displaySettings); 00202 GHOST_TInt32 numSettings; 00203 success = getNumDisplaySettings(display, numSettings); 00204 if (success == GHOST_kSuccess) { 00205 GHOST_TInt32 index; 00206 GHOST_DisplaySetting setting; 00207 for (index = 0; (index < numSettings) && (success == GHOST_kSuccess); index++) { 00208 success = getDisplaySetting(display, index, setting); 00209 m_settings[display].push_back(setting); 00210 } 00211 } 00212 else { 00213 break; 00214 } 00215 } 00216 } 00217 return success; 00218 }