daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1 | // |
daniel@transgaming.com | c6f7f9d | 2012-01-27 15:40:00 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Display.cpp: Implements the egl::Display class, representing the abstract |
| 8 | // display on which graphics are drawn. Implements EGLDisplay. |
| 9 | // [EGL 1.4] section 2.1.2 page 3. |
| 10 | |
| 11 | #include "libEGL/Display.h" |
| 12 | |
| 13 | #include <algorithm> |
jbauman@chromium.org | 84d7cbc | 2011-07-14 22:53:19 +0000 | [diff] [blame] | 14 | #include <map> |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
| 17 | #include "common/debug.h" |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 18 | #include "libGLESv2/mathutil.h" |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 19 | #include "libGLESv2/utilities.h" |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 20 | |
| 21 | #include "libEGL/main.h" |
| 22 | |
baustin@google.com | 250f06c | 2011-06-06 16:59:53 +0000 | [diff] [blame] | 23 | // Can also be enabled by defining FORCE_REF_RAST in the project's predefined macros |
| 24 | #define REF_RAST 0 |
| 25 | |
| 26 | // The "Debug This Pixel..." feature in PIX often fails when using the |
| 27 | // D3D9Ex interfaces. In order to get debug pixel to work on a Vista/Win 7 |
| 28 | // machine, define "ANGLE_ENABLE_D3D9EX=0" in your project file. |
| 29 | #if !defined(ANGLE_ENABLE_D3D9EX) |
| 30 | // Enables use of the IDirect3D9Ex interface, when available |
| 31 | #define ANGLE_ENABLE_D3D9EX 1 |
| 32 | #endif // !defined(ANGLE_ENABLE_D3D9EX) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 33 | |
| 34 | namespace egl |
| 35 | { |
jbauman@chromium.org | 84d7cbc | 2011-07-14 22:53:19 +0000 | [diff] [blame] | 36 | namespace |
| 37 | { |
| 38 | typedef std::map<EGLNativeDisplayType, Display*> DisplayMap; |
| 39 | DisplayMap displays; |
| 40 | } |
| 41 | |
| 42 | egl::Display *Display::getDisplay(EGLNativeDisplayType displayId) |
| 43 | { |
| 44 | if (displays.find(displayId) != displays.end()) |
| 45 | { |
| 46 | return displays[displayId]; |
| 47 | } |
| 48 | |
| 49 | egl::Display *display = NULL; |
| 50 | |
| 51 | if (displayId == EGL_DEFAULT_DISPLAY) |
| 52 | { |
| 53 | display = new egl::Display(displayId, (HDC)NULL, false); |
| 54 | } |
| 55 | else if (displayId == EGL_SOFTWARE_DISPLAY_ANGLE) |
| 56 | { |
| 57 | display = new egl::Display(displayId, (HDC)NULL, true); |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | // FIXME: Check if displayId is a valid display device context |
| 62 | |
| 63 | display = new egl::Display(displayId, (HDC)displayId, false); |
| 64 | } |
| 65 | |
| 66 | displays[displayId] = display; |
| 67 | return display; |
| 68 | } |
| 69 | |
| 70 | Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool software) : mDc(deviceContext) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 71 | { |
| 72 | mD3d9Module = NULL; |
| 73 | |
| 74 | mD3d9 = NULL; |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 75 | mD3d9Ex = NULL; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 76 | mDevice = NULL; |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 77 | mDeviceEx = NULL; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 78 | mDeviceWindow = NULL; |
| 79 | |
| 80 | mAdapter = D3DADAPTER_DEFAULT; |
| 81 | |
| 82 | #if REF_RAST == 1 || defined(FORCE_REF_RAST) |
| 83 | mDeviceType = D3DDEVTYPE_REF; |
| 84 | #else |
| 85 | mDeviceType = D3DDEVTYPE_HAL; |
| 86 | #endif |
| 87 | |
| 88 | mMinSwapInterval = 1; |
| 89 | mMaxSwapInterval = 1; |
jbauman@chromium.org | 84d7cbc | 2011-07-14 22:53:19 +0000 | [diff] [blame] | 90 | mSoftwareDevice = software; |
| 91 | mDisplayId = displayId; |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame] | 92 | mDeviceLost = false; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | Display::~Display() |
| 96 | { |
| 97 | terminate(); |
jbauman@chromium.org | 84d7cbc | 2011-07-14 22:53:19 +0000 | [diff] [blame] | 98 | |
| 99 | DisplayMap::iterator thisDisplay = displays.find(mDisplayId); |
| 100 | |
| 101 | if (thisDisplay != displays.end()) |
| 102 | { |
| 103 | displays.erase(thisDisplay); |
| 104 | } |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | bool Display::initialize() |
| 108 | { |
| 109 | if (isInitialized()) |
| 110 | { |
| 111 | return true; |
| 112 | } |
| 113 | |
jbauman@chromium.org | 84d7cbc | 2011-07-14 22:53:19 +0000 | [diff] [blame] | 114 | if (mSoftwareDevice) |
| 115 | { |
| 116 | mD3d9Module = GetModuleHandle(TEXT("swiftshader_d3d9.dll")); |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | mD3d9Module = GetModuleHandle(TEXT("d3d9.dll")); |
| 121 | } |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 122 | if (mD3d9Module == NULL) |
| 123 | { |
| 124 | terminate(); |
| 125 | return false; |
| 126 | } |
| 127 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 128 | typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT, IDirect3D9Ex**); |
| 129 | Direct3DCreate9ExFunc Direct3DCreate9ExPtr = reinterpret_cast<Direct3DCreate9ExFunc>(GetProcAddress(mD3d9Module, "Direct3DCreate9Ex")); |
| 130 | |
| 131 | // Use Direct3D9Ex if available. Among other things, this version is less |
| 132 | // inclined to report a lost context, for example when the user switches |
| 133 | // desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available. |
baustin@google.com | 250f06c | 2011-06-06 16:59:53 +0000 | [diff] [blame] | 134 | if (ANGLE_ENABLE_D3D9EX && Direct3DCreate9ExPtr && SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9Ex))) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 135 | { |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 136 | ASSERT(mD3d9Ex); |
| 137 | mD3d9Ex->QueryInterface(IID_IDirect3D9, reinterpret_cast<void**>(&mD3d9)); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 138 | ASSERT(mD3d9); |
| 139 | } |
| 140 | else |
| 141 | { |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 142 | mD3d9 = Direct3DCreate9(D3D_SDK_VERSION); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | if (mD3d9) |
| 146 | { |
| 147 | if (mDc != NULL) |
| 148 | { |
| 149 | // UNIMPLEMENTED(); // FIXME: Determine which adapter index the device context corresponds to |
| 150 | } |
| 151 | |
| 152 | HRESULT result; |
| 153 | |
apatrick@chromium.org | 1c76801 | 2010-10-07 00:35:24 +0000 | [diff] [blame] | 154 | // Give up on getting device caps after about one second. |
| 155 | for (int i = 0; i < 10; ++i) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 156 | { |
| 157 | result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps); |
apatrick@chromium.org | 1c76801 | 2010-10-07 00:35:24 +0000 | [diff] [blame] | 158 | |
| 159 | if (SUCCEEDED(result)) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 160 | { |
apatrick@chromium.org | 1c76801 | 2010-10-07 00:35:24 +0000 | [diff] [blame] | 161 | break; |
| 162 | } |
| 163 | else if (result == D3DERR_NOTAVAILABLE) |
| 164 | { |
| 165 | Sleep(100); // Give the driver some time to initialize/recover |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 166 | } |
| 167 | else if (FAILED(result)) // D3DERR_OUTOFVIDEOMEMORY, E_OUTOFMEMORY, D3DERR_INVALIDDEVICE, or another error we can't recover from |
| 168 | { |
apatrick@chromium.org | 1c76801 | 2010-10-07 00:35:24 +0000 | [diff] [blame] | 169 | terminate(); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 170 | return error(EGL_BAD_ALLOC, false); |
| 171 | } |
| 172 | } |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 173 | |
| 174 | if (mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(2, 0)) |
| 175 | { |
| 176 | terminate(); |
| 177 | return error(EGL_NOT_INITIALIZED, false); |
| 178 | } |
| 179 | |
apatrick@chromium.org | 1c76801 | 2010-10-07 00:35:24 +0000 | [diff] [blame] | 180 | // When DirectX9 is running with an older DirectX8 driver, a StretchRect from a regular texture to a render target texture is not supported. |
| 181 | // This is required by Texture2D::convertToRenderTarget. |
| 182 | if ((mDeviceCaps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) == 0) |
| 183 | { |
| 184 | terminate(); |
| 185 | return error(EGL_NOT_INITIALIZED, false); |
| 186 | } |
| 187 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 188 | mMinSwapInterval = 4; |
| 189 | mMaxSwapInterval = 0; |
| 190 | |
| 191 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) {mMinSwapInterval = std::min(mMinSwapInterval, 0); mMaxSwapInterval = std::max(mMaxSwapInterval, 0);} |
| 192 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) {mMinSwapInterval = std::min(mMinSwapInterval, 1); mMaxSwapInterval = std::max(mMaxSwapInterval, 1);} |
| 193 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) {mMinSwapInterval = std::min(mMinSwapInterval, 2); mMaxSwapInterval = std::max(mMaxSwapInterval, 2);} |
| 194 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) {mMinSwapInterval = std::min(mMinSwapInterval, 3); mMaxSwapInterval = std::max(mMaxSwapInterval, 3);} |
| 195 | if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) {mMinSwapInterval = std::min(mMinSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);} |
| 196 | |
jbauman@chromium.org | 03208d5 | 2011-06-15 01:15:24 +0000 | [diff] [blame] | 197 | mD3d9->GetAdapterIdentifier(mAdapter, 0, &mAdapterIdentifier); |
| 198 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 199 | const D3DFORMAT renderTargetFormats[] = |
| 200 | { |
| 201 | D3DFMT_A1R5G5B5, |
| 202 | // D3DFMT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value. |
| 203 | D3DFMT_A8R8G8B8, |
| 204 | D3DFMT_R5G6B5, |
daniel@transgaming.com | 73a5db6 | 2010-10-15 17:58:13 +0000 | [diff] [blame] | 205 | // D3DFMT_X1R5G5B5, // Has no compatible OpenGL ES renderbuffer format |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 206 | D3DFMT_X8R8G8B8 |
| 207 | }; |
| 208 | |
| 209 | const D3DFORMAT depthStencilFormats[] = |
| 210 | { |
daniel@transgaming.com | a114c27 | 2011-04-22 04:18:50 +0000 | [diff] [blame] | 211 | D3DFMT_UNKNOWN, |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 212 | // D3DFMT_D16_LOCKABLE, |
| 213 | D3DFMT_D32, |
| 214 | // D3DFMT_D15S1, |
| 215 | D3DFMT_D24S8, |
| 216 | D3DFMT_D24X8, |
| 217 | // D3DFMT_D24X4S4, |
| 218 | D3DFMT_D16, |
| 219 | // D3DFMT_D32F_LOCKABLE, |
| 220 | // D3DFMT_D24FS8 |
| 221 | }; |
| 222 | |
| 223 | D3DDISPLAYMODE currentDisplayMode; |
| 224 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 225 | |
| 226 | ConfigSet configSet; |
| 227 | |
| 228 | for (int formatIndex = 0; formatIndex < sizeof(renderTargetFormats) / sizeof(D3DFORMAT); formatIndex++) |
| 229 | { |
| 230 | D3DFORMAT renderTargetFormat = renderTargetFormats[formatIndex]; |
| 231 | |
| 232 | HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat); |
| 233 | |
| 234 | if (SUCCEEDED(result)) |
| 235 | { |
| 236 | for (int depthStencilIndex = 0; depthStencilIndex < sizeof(depthStencilFormats) / sizeof(D3DFORMAT); depthStencilIndex++) |
| 237 | { |
| 238 | D3DFORMAT depthStencilFormat = depthStencilFormats[depthStencilIndex]; |
daniel@transgaming.com | a114c27 | 2011-04-22 04:18:50 +0000 | [diff] [blame] | 239 | HRESULT result = D3D_OK; |
| 240 | |
| 241 | if(depthStencilFormat != D3DFMT_UNKNOWN) |
| 242 | { |
| 243 | result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat); |
| 244 | } |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 245 | |
| 246 | if (SUCCEEDED(result)) |
| 247 | { |
daniel@transgaming.com | a114c27 | 2011-04-22 04:18:50 +0000 | [diff] [blame] | 248 | if(depthStencilFormat != D3DFMT_UNKNOWN) |
| 249 | { |
| 250 | result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, currentDisplayMode.Format, renderTargetFormat, depthStencilFormat); |
| 251 | } |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 252 | |
| 253 | if (SUCCEEDED(result)) |
| 254 | { |
| 255 | // FIXME: enumerate multi-sampling |
| 256 | |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 257 | configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0, |
| 258 | mDeviceCaps.MaxTextureWidth, mDeviceCaps.MaxTextureHeight); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // Give the sorted configs a unique ID and store them internally |
| 266 | EGLint index = 1; |
| 267 | for (ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++) |
| 268 | { |
| 269 | Config configuration = *config; |
| 270 | configuration.mConfigID = index; |
| 271 | index++; |
| 272 | |
| 273 | mConfigSet.mSet.insert(configuration); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | if (!isInitialized()) |
| 278 | { |
| 279 | terminate(); |
| 280 | |
| 281 | return false; |
| 282 | } |
| 283 | |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 284 | initExtensionString(); |
| 285 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 286 | static const TCHAR windowName[] = TEXT("AngleHiddenWindow"); |
| 287 | static const TCHAR className[] = TEXT("STATIC"); |
| 288 | |
| 289 | mDeviceWindow = CreateWindowEx(WS_EX_NOACTIVATE, className, windowName, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL); |
| 290 | |
apatrick@chromium.org | cca2b70 | 2012-02-08 00:59:46 +0000 | [diff] [blame] | 291 | if (!createDevice()) |
| 292 | { |
| 293 | terminate(); |
| 294 | return false; |
| 295 | } |
| 296 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 297 | return true; |
| 298 | } |
| 299 | |
| 300 | void Display::terminate() |
| 301 | { |
| 302 | while (!mSurfaceSet.empty()) |
| 303 | { |
| 304 | destroySurface(*mSurfaceSet.begin()); |
| 305 | } |
| 306 | |
| 307 | while (!mContextSet.empty()) |
| 308 | { |
| 309 | destroyContext(*mContextSet.begin()); |
| 310 | } |
| 311 | |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 312 | while (!mEventQueryPool.empty()) |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 313 | { |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 314 | mEventQueryPool.back()->Release(); |
| 315 | mEventQueryPool.pop_back(); |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 316 | } |
| 317 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 318 | if (mDevice) |
| 319 | { |
| 320 | // If the device is lost, reset it first to prevent leaving the driver in an unstable state |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame] | 321 | if (testDeviceLost()) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 322 | { |
| 323 | resetDevice(); |
| 324 | } |
| 325 | |
| 326 | mDevice->Release(); |
| 327 | mDevice = NULL; |
| 328 | } |
| 329 | |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 330 | if (mDeviceEx) |
| 331 | { |
| 332 | mDeviceEx->Release(); |
| 333 | mDeviceEx = NULL; |
| 334 | } |
| 335 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 336 | if (mD3d9) |
| 337 | { |
| 338 | mD3d9->Release(); |
| 339 | mD3d9 = NULL; |
| 340 | } |
| 341 | |
| 342 | if (mDeviceWindow) |
| 343 | { |
| 344 | DestroyWindow(mDeviceWindow); |
| 345 | mDeviceWindow = NULL; |
| 346 | } |
| 347 | |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 348 | if (mD3d9Ex) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 349 | { |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 350 | mD3d9Ex->Release(); |
| 351 | mD3d9Ex = NULL; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | if (mD3d9Module) |
| 355 | { |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 356 | mD3d9Module = NULL; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | void Display::startScene() |
| 361 | { |
| 362 | if (!mSceneStarted) |
| 363 | { |
| 364 | long result = mDevice->BeginScene(); |
kbr@chromium.org | 1a2cd26 | 2011-07-08 17:30:18 +0000 | [diff] [blame] | 365 | if (SUCCEEDED(result)) { |
| 366 | // This is defensive checking against the device being |
| 367 | // lost at unexpected times. |
| 368 | mSceneStarted = true; |
| 369 | } |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
| 373 | void Display::endScene() |
| 374 | { |
| 375 | if (mSceneStarted) |
| 376 | { |
kbr@chromium.org | 1a2cd26 | 2011-07-08 17:30:18 +0000 | [diff] [blame] | 377 | // EndScene can fail if the device was lost, for example due |
| 378 | // to a TDR during a draw call. |
| 379 | mDevice->EndScene(); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 380 | mSceneStarted = false; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig) |
| 385 | { |
| 386 | return mConfigSet.getConfigs(configs, attribList, configSize, numConfig); |
| 387 | } |
| 388 | |
| 389 | bool Display::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value) |
| 390 | { |
| 391 | const egl::Config *configuration = mConfigSet.get(config); |
| 392 | |
| 393 | switch (attribute) |
| 394 | { |
| 395 | case EGL_BUFFER_SIZE: *value = configuration->mBufferSize; break; |
| 396 | case EGL_ALPHA_SIZE: *value = configuration->mAlphaSize; break; |
| 397 | case EGL_BLUE_SIZE: *value = configuration->mBlueSize; break; |
| 398 | case EGL_GREEN_SIZE: *value = configuration->mGreenSize; break; |
| 399 | case EGL_RED_SIZE: *value = configuration->mRedSize; break; |
| 400 | case EGL_DEPTH_SIZE: *value = configuration->mDepthSize; break; |
| 401 | case EGL_STENCIL_SIZE: *value = configuration->mStencilSize; break; |
| 402 | case EGL_CONFIG_CAVEAT: *value = configuration->mConfigCaveat; break; |
| 403 | case EGL_CONFIG_ID: *value = configuration->mConfigID; break; |
| 404 | case EGL_LEVEL: *value = configuration->mLevel; break; |
| 405 | case EGL_NATIVE_RENDERABLE: *value = configuration->mNativeRenderable; break; |
| 406 | case EGL_NATIVE_VISUAL_TYPE: *value = configuration->mNativeVisualType; break; |
| 407 | case EGL_SAMPLES: *value = configuration->mSamples; break; |
| 408 | case EGL_SAMPLE_BUFFERS: *value = configuration->mSampleBuffers; break; |
| 409 | case EGL_SURFACE_TYPE: *value = configuration->mSurfaceType; break; |
| 410 | case EGL_TRANSPARENT_TYPE: *value = configuration->mTransparentType; break; |
| 411 | case EGL_TRANSPARENT_BLUE_VALUE: *value = configuration->mTransparentBlueValue; break; |
| 412 | case EGL_TRANSPARENT_GREEN_VALUE: *value = configuration->mTransparentGreenValue; break; |
| 413 | case EGL_TRANSPARENT_RED_VALUE: *value = configuration->mTransparentRedValue; break; |
| 414 | case EGL_BIND_TO_TEXTURE_RGB: *value = configuration->mBindToTextureRGB; break; |
| 415 | case EGL_BIND_TO_TEXTURE_RGBA: *value = configuration->mBindToTextureRGBA; break; |
| 416 | case EGL_MIN_SWAP_INTERVAL: *value = configuration->mMinSwapInterval; break; |
| 417 | case EGL_MAX_SWAP_INTERVAL: *value = configuration->mMaxSwapInterval; break; |
| 418 | case EGL_LUMINANCE_SIZE: *value = configuration->mLuminanceSize; break; |
| 419 | case EGL_ALPHA_MASK_SIZE: *value = configuration->mAlphaMaskSize; break; |
| 420 | case EGL_COLOR_BUFFER_TYPE: *value = configuration->mColorBufferType; break; |
| 421 | case EGL_RENDERABLE_TYPE: *value = configuration->mRenderableType; break; |
| 422 | case EGL_MATCH_NATIVE_PIXMAP: *value = false; UNIMPLEMENTED(); break; |
| 423 | case EGL_CONFORMANT: *value = configuration->mConformant; break; |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 424 | case EGL_MAX_PBUFFER_WIDTH: *value = configuration->mMaxPBufferWidth; break; |
| 425 | case EGL_MAX_PBUFFER_HEIGHT: *value = configuration->mMaxPBufferHeight; break; |
| 426 | case EGL_MAX_PBUFFER_PIXELS: *value = configuration->mMaxPBufferPixels; break; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 427 | default: |
| 428 | return false; |
| 429 | } |
| 430 | |
| 431 | return true; |
| 432 | } |
| 433 | |
| 434 | bool Display::createDevice() |
| 435 | { |
| 436 | D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); |
| 437 | DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES; |
| 438 | |
| 439 | HRESULT result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presentParameters, &mDevice); |
| 440 | |
| 441 | if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DEVICELOST) |
| 442 | { |
| 443 | return error(EGL_BAD_ALLOC, false); |
| 444 | } |
| 445 | |
| 446 | if (FAILED(result)) |
| 447 | { |
| 448 | result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &mDevice); |
| 449 | |
| 450 | if (FAILED(result)) |
| 451 | { |
| 452 | ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_NOTAVAILABLE || result == D3DERR_DEVICELOST); |
| 453 | return error(EGL_BAD_ALLOC, false); |
| 454 | } |
| 455 | } |
| 456 | |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 457 | if (mD3d9Ex) |
| 458 | { |
| 459 | result = mDevice->QueryInterface(IID_IDirect3DDevice9Ex, (void**) &mDeviceEx); |
| 460 | ASSERT(SUCCEEDED(result)); |
| 461 | } |
| 462 | |
daniel@transgaming.com | e19d832 | 2011-12-13 17:30:48 +0000 | [diff] [blame] | 463 | initializeDevice(); |
| 464 | |
| 465 | return true; |
| 466 | } |
| 467 | |
| 468 | // do any one-time device initialization |
| 469 | // NOTE: this is also needed after a device lost/reset |
| 470 | // to reset the scene status and ensure the default states are reset. |
| 471 | void Display::initializeDevice() |
| 472 | { |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 473 | // Permanent non-default states |
| 474 | mDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE); |
daniel@transgaming.com | 7a2fdc9 | 2011-11-24 22:34:09 +0000 | [diff] [blame] | 475 | mDevice->SetRenderState(D3DRS_LASTPIXEL, FALSE); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 476 | |
| 477 | mSceneStarted = false; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | bool Display::resetDevice() |
| 481 | { |
| 482 | D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 483 | |
daniel@transgaming.com | 1043535 | 2011-11-09 17:44:21 +0000 | [diff] [blame] | 484 | HRESULT result = D3D_OK; |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame] | 485 | bool lost = testDeviceLost(); |
daniel@transgaming.com | 1043535 | 2011-11-09 17:44:21 +0000 | [diff] [blame] | 486 | int attempts = 3; |
daniel@transgaming.com | 94910c9 | 2011-11-09 17:44:15 +0000 | [diff] [blame] | 487 | |
daniel@transgaming.com | 1043535 | 2011-11-09 17:44:21 +0000 | [diff] [blame] | 488 | while (lost && attempts > 0) |
daniel@transgaming.com | 94910c9 | 2011-11-09 17:44:15 +0000 | [diff] [blame] | 489 | { |
daniel@transgaming.com | 1043535 | 2011-11-09 17:44:21 +0000 | [diff] [blame] | 490 | if (mDeviceEx) |
| 491 | { |
| 492 | Sleep(500); // Give the graphics driver some CPU time |
| 493 | result = mDeviceEx->ResetEx(&presentParameters, NULL); |
| 494 | } |
| 495 | else |
| 496 | { |
| 497 | result = mDevice->TestCooperativeLevel(); |
| 498 | |
| 499 | while (result == D3DERR_DEVICELOST) |
| 500 | { |
| 501 | Sleep(100); // Give the graphics driver some CPU time |
| 502 | result = mDevice->TestCooperativeLevel(); |
| 503 | } |
| 504 | |
| 505 | if (result == D3DERR_DEVICENOTRESET) |
| 506 | { |
| 507 | result = mDevice->Reset(&presentParameters); |
| 508 | } |
| 509 | } |
| 510 | |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame] | 511 | lost = testDeviceLost(); |
daniel@transgaming.com | 1043535 | 2011-11-09 17:44:21 +0000 | [diff] [blame] | 512 | attempts --; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 513 | } |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 514 | |
| 515 | if (FAILED(result)) |
| 516 | { |
daniel@transgaming.com | 1043535 | 2011-11-09 17:44:21 +0000 | [diff] [blame] | 517 | ERR("Reset/ResetEx failed multiple times: 0x%08X", result); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 518 | return error(EGL_BAD_ALLOC, false); |
| 519 | } |
| 520 | |
daniel@transgaming.com | e19d832 | 2011-12-13 17:30:48 +0000 | [diff] [blame] | 521 | // reset device defaults |
| 522 | initializeDevice(); |
| 523 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 524 | return true; |
| 525 | } |
| 526 | |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 527 | EGLSurface Display::createWindowSurface(HWND window, EGLConfig config, const EGLint *attribList) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 528 | { |
| 529 | const Config *configuration = mConfigSet.get(config); |
apatrick@chromium.org | f4490e2 | 2011-12-06 02:05:22 +0000 | [diff] [blame] | 530 | EGLint postSubBufferSupported = EGL_FALSE; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 531 | |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 532 | if (attribList) |
| 533 | { |
| 534 | while (*attribList != EGL_NONE) |
| 535 | { |
| 536 | switch (attribList[0]) |
| 537 | { |
| 538 | case EGL_RENDER_BUFFER: |
| 539 | switch (attribList[1]) |
| 540 | { |
| 541 | case EGL_BACK_BUFFER: |
| 542 | break; |
| 543 | case EGL_SINGLE_BUFFER: |
| 544 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); // Rendering directly to front buffer not supported |
| 545 | default: |
| 546 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 547 | } |
| 548 | break; |
apatrick@chromium.org | f4490e2 | 2011-12-06 02:05:22 +0000 | [diff] [blame] | 549 | case EGL_POST_SUB_BUFFER_SUPPORTED_NV: |
| 550 | postSubBufferSupported = attribList[1]; |
| 551 | break; |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 552 | case EGL_VG_COLORSPACE: |
| 553 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 554 | case EGL_VG_ALPHA_FORMAT: |
| 555 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 556 | default: |
| 557 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 558 | } |
| 559 | |
| 560 | attribList += 2; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | if (hasExistingWindowSurface(window)) |
| 565 | { |
| 566 | return error(EGL_BAD_ALLOC, EGL_NO_SURFACE); |
| 567 | } |
| 568 | |
daniel@transgaming.com | cf23c45 | 2011-11-09 17:47:26 +0000 | [diff] [blame] | 569 | if (testDeviceLost()) |
| 570 | { |
vangelis@google.com | 8c9c452 | 2011-09-09 18:22:28 +0000 | [diff] [blame] | 571 | if (!restoreLostDevice()) |
| 572 | return EGL_NO_SURFACE; |
| 573 | } |
| 574 | |
apatrick@chromium.org | f4490e2 | 2011-12-06 02:05:22 +0000 | [diff] [blame] | 575 | Surface *surface = new Surface(this, configuration, window, postSubBufferSupported); |
jbauman@chromium.org | 4e29770 | 2011-05-12 23:04:07 +0000 | [diff] [blame] | 576 | |
| 577 | if (!surface->initialize()) |
| 578 | { |
| 579 | delete surface; |
| 580 | return EGL_NO_SURFACE; |
| 581 | } |
| 582 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 583 | mSurfaceSet.insert(surface); |
| 584 | |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 585 | return success(surface); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 586 | } |
| 587 | |
jbauman@chromium.org | 4e29770 | 2011-05-12 23:04:07 +0000 | [diff] [blame] | 588 | EGLSurface Display::createOffscreenSurface(EGLConfig config, HANDLE shareHandle, const EGLint *attribList) |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 589 | { |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 590 | EGLint width = 0, height = 0; |
| 591 | EGLenum textureFormat = EGL_NO_TEXTURE; |
| 592 | EGLenum textureTarget = EGL_NO_TEXTURE; |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 593 | const Config *configuration = mConfigSet.get(config); |
| 594 | |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 595 | if (attribList) |
| 596 | { |
| 597 | while (*attribList != EGL_NONE) |
| 598 | { |
| 599 | switch (attribList[0]) |
| 600 | { |
| 601 | case EGL_WIDTH: |
| 602 | width = attribList[1]; |
| 603 | break; |
| 604 | case EGL_HEIGHT: |
| 605 | height = attribList[1]; |
| 606 | break; |
| 607 | case EGL_LARGEST_PBUFFER: |
| 608 | if (attribList[1] != EGL_FALSE) |
| 609 | UNIMPLEMENTED(); // FIXME |
| 610 | break; |
| 611 | case EGL_TEXTURE_FORMAT: |
| 612 | switch (attribList[1]) |
| 613 | { |
| 614 | case EGL_NO_TEXTURE: |
| 615 | case EGL_TEXTURE_RGB: |
| 616 | case EGL_TEXTURE_RGBA: |
| 617 | textureFormat = attribList[1]; |
| 618 | break; |
| 619 | default: |
| 620 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 621 | } |
| 622 | break; |
| 623 | case EGL_TEXTURE_TARGET: |
| 624 | switch (attribList[1]) |
| 625 | { |
| 626 | case EGL_NO_TEXTURE: |
| 627 | case EGL_TEXTURE_2D: |
| 628 | textureTarget = attribList[1]; |
| 629 | break; |
| 630 | default: |
| 631 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 632 | } |
| 633 | break; |
| 634 | case EGL_MIPMAP_TEXTURE: |
| 635 | if (attribList[1] != EGL_FALSE) |
| 636 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 637 | break; |
| 638 | case EGL_VG_COLORSPACE: |
| 639 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 640 | case EGL_VG_ALPHA_FORMAT: |
| 641 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 642 | default: |
| 643 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 644 | } |
| 645 | |
| 646 | attribList += 2; |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | if (width < 0 || height < 0) |
| 651 | { |
| 652 | return error(EGL_BAD_PARAMETER, EGL_NO_SURFACE); |
| 653 | } |
| 654 | |
| 655 | if (width == 0 || height == 0) |
| 656 | { |
| 657 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 658 | } |
| 659 | |
daniel@transgaming.com | 4f9ef0d | 2011-05-30 23:51:19 +0000 | [diff] [blame] | 660 | if (textureFormat != EGL_NO_TEXTURE && !getNonPower2TextureSupport() && (!gl::isPow2(width) || !gl::isPow2(height))) |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 661 | { |
| 662 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 663 | } |
| 664 | |
| 665 | if ((textureFormat != EGL_NO_TEXTURE && textureTarget == EGL_NO_TEXTURE) || |
| 666 | (textureFormat == EGL_NO_TEXTURE && textureTarget != EGL_NO_TEXTURE)) |
| 667 | { |
| 668 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 669 | } |
| 670 | |
| 671 | if (!(configuration->mSurfaceType & EGL_PBUFFER_BIT)) |
| 672 | { |
| 673 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
| 674 | } |
| 675 | |
| 676 | if ((textureFormat == EGL_TEXTURE_RGB && configuration->mBindToTextureRGB != EGL_TRUE) || |
| 677 | (textureFormat == EGL_TEXTURE_RGBA && configuration->mBindToTextureRGBA != EGL_TRUE)) |
| 678 | { |
| 679 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 680 | } |
| 681 | |
daniel@transgaming.com | cf23c45 | 2011-11-09 17:47:26 +0000 | [diff] [blame] | 682 | if (testDeviceLost()) |
| 683 | { |
vangelis@google.com | 8c9c452 | 2011-09-09 18:22:28 +0000 | [diff] [blame] | 684 | if (!restoreLostDevice()) |
| 685 | return EGL_NO_SURFACE; |
| 686 | } |
| 687 | |
jbauman@chromium.org | 4e29770 | 2011-05-12 23:04:07 +0000 | [diff] [blame] | 688 | Surface *surface = new Surface(this, configuration, shareHandle, width, height, textureFormat, textureTarget); |
| 689 | |
| 690 | if (!surface->initialize()) |
| 691 | { |
| 692 | delete surface; |
| 693 | return EGL_NO_SURFACE; |
| 694 | } |
| 695 | |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 696 | mSurfaceSet.insert(surface); |
| 697 | |
jbauman@chromium.org | 06d7a75 | 2011-04-30 01:02:52 +0000 | [diff] [blame] | 698 | return success(surface); |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 699 | } |
| 700 | |
daniel@transgaming.com | 4ff960d | 2011-11-09 17:47:09 +0000 | [diff] [blame] | 701 | EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *shareContext, bool notifyResets, bool robustAccess) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 702 | { |
| 703 | if (!mDevice) |
| 704 | { |
| 705 | if (!createDevice()) |
| 706 | { |
| 707 | return NULL; |
| 708 | } |
| 709 | } |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame] | 710 | else if (testDeviceLost()) // Lost device |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 711 | { |
vangelis@google.com | 8c9c452 | 2011-09-09 18:22:28 +0000 | [diff] [blame] | 712 | if (!restoreLostDevice()) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 713 | return NULL; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | const egl::Config *config = mConfigSet.get(configHandle); |
| 717 | |
daniel@transgaming.com | 4ff960d | 2011-11-09 17:47:09 +0000 | [diff] [blame] | 718 | gl::Context *context = glCreateContext(config, shareContext, notifyResets, robustAccess); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 719 | mContextSet.insert(context); |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame] | 720 | mDeviceLost = false; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 721 | |
| 722 | return context; |
| 723 | } |
| 724 | |
vangelis@google.com | 8c9c452 | 2011-09-09 18:22:28 +0000 | [diff] [blame] | 725 | bool Display::restoreLostDevice() |
| 726 | { |
daniel@transgaming.com | cf23c45 | 2011-11-09 17:47:26 +0000 | [diff] [blame] | 727 | for (ContextSet::iterator ctx = mContextSet.begin(); ctx != mContextSet.end(); ctx++) |
| 728 | { |
| 729 | if ((*ctx)->isResetNotificationEnabled()) |
| 730 | return false; // If reset notifications have been requested, application must delete all contexts first |
| 731 | } |
| 732 | |
vangelis@google.com | 8c9c452 | 2011-09-09 18:22:28 +0000 | [diff] [blame] | 733 | // Release surface resources to make the Reset() succeed |
| 734 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
| 735 | { |
| 736 | (*surface)->release(); |
| 737 | } |
| 738 | |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 739 | while (!mEventQueryPool.empty()) |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 740 | { |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 741 | mEventQueryPool.back()->Release(); |
| 742 | mEventQueryPool.pop_back(); |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 743 | } |
| 744 | |
vangelis@google.com | 8c9c452 | 2011-09-09 18:22:28 +0000 | [diff] [blame] | 745 | if (!resetDevice()) |
| 746 | { |
| 747 | return false; |
| 748 | } |
| 749 | |
| 750 | // Restore any surfaces that may have been lost |
| 751 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
| 752 | { |
| 753 | (*surface)->resetSwapChain(); |
| 754 | } |
| 755 | |
| 756 | return true; |
| 757 | } |
| 758 | |
| 759 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 760 | void Display::destroySurface(egl::Surface *surface) |
| 761 | { |
daniel@transgaming.com | c556fa5 | 2011-05-26 14:13:29 +0000 | [diff] [blame] | 762 | delete surface; |
| 763 | mSurfaceSet.erase(surface); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | void Display::destroyContext(gl::Context *context) |
| 767 | { |
| 768 | glDestroyContext(context); |
| 769 | mContextSet.erase(context); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 770 | } |
| 771 | |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame] | 772 | void Display::notifyDeviceLost() |
| 773 | { |
| 774 | for (ContextSet::iterator context = mContextSet.begin(); context != mContextSet.end(); context++) |
| 775 | { |
| 776 | (*context)->markContextLost(); |
| 777 | } |
| 778 | mDeviceLost = true; |
| 779 | error(EGL_CONTEXT_LOST); |
| 780 | } |
| 781 | |
| 782 | bool Display::isDeviceLost() |
| 783 | { |
| 784 | return mDeviceLost; |
| 785 | } |
| 786 | |
daniel@transgaming.com | 3b1703f | 2011-05-11 15:36:26 +0000 | [diff] [blame] | 787 | bool Display::isInitialized() const |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 788 | { |
| 789 | return mD3d9 != NULL && mConfigSet.size() > 0; |
| 790 | } |
| 791 | |
| 792 | bool Display::isValidConfig(EGLConfig config) |
| 793 | { |
| 794 | return mConfigSet.get(config) != NULL; |
| 795 | } |
| 796 | |
| 797 | bool Display::isValidContext(gl::Context *context) |
| 798 | { |
| 799 | return mContextSet.find(context) != mContextSet.end(); |
| 800 | } |
| 801 | |
| 802 | bool Display::isValidSurface(egl::Surface *surface) |
| 803 | { |
daniel@transgaming.com | c556fa5 | 2011-05-26 14:13:29 +0000 | [diff] [blame] | 804 | return mSurfaceSet.find(surface) != mSurfaceSet.end(); |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | bool Display::hasExistingWindowSurface(HWND window) |
| 808 | { |
| 809 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
| 810 | { |
| 811 | if ((*surface)->getWindowHandle() == window) |
| 812 | { |
| 813 | return true; |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | return false; |
| 818 | } |
| 819 | |
| 820 | EGLint Display::getMinSwapInterval() |
| 821 | { |
| 822 | return mMinSwapInterval; |
| 823 | } |
| 824 | |
| 825 | EGLint Display::getMaxSwapInterval() |
| 826 | { |
| 827 | return mMaxSwapInterval; |
| 828 | } |
| 829 | |
| 830 | IDirect3DDevice9 *Display::getDevice() |
| 831 | { |
| 832 | if (!mDevice) |
| 833 | { |
| 834 | if (!createDevice()) |
| 835 | { |
| 836 | return NULL; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return mDevice; |
| 841 | } |
| 842 | |
| 843 | D3DCAPS9 Display::getDeviceCaps() |
| 844 | { |
| 845 | return mDeviceCaps; |
| 846 | } |
| 847 | |
jbauman@chromium.org | 03208d5 | 2011-06-15 01:15:24 +0000 | [diff] [blame] | 848 | D3DADAPTER_IDENTIFIER9 *Display::getAdapterIdentifier() |
| 849 | { |
| 850 | return &mAdapterIdentifier; |
| 851 | } |
| 852 | |
daniel@transgaming.com | 09fcc9f | 2011-11-09 17:46:47 +0000 | [diff] [blame] | 853 | bool Display::testDeviceLost() |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 854 | { |
| 855 | if (mDeviceEx) |
| 856 | { |
| 857 | return FAILED(mDeviceEx->CheckDeviceState(NULL)); |
| 858 | } |
daniel@transgaming.com | 17f548c | 2011-11-09 17:47:02 +0000 | [diff] [blame] | 859 | else if (mDevice) |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 860 | { |
| 861 | return FAILED(mDevice->TestCooperativeLevel()); |
| 862 | } |
daniel@transgaming.com | fe4b0c9 | 2011-09-13 00:53:11 +0000 | [diff] [blame] | 863 | |
| 864 | return false; // No device yet, so no reset required |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 865 | } |
| 866 | |
daniel@transgaming.com | 17f548c | 2011-11-09 17:47:02 +0000 | [diff] [blame] | 867 | bool Display::testDeviceResettable() |
| 868 | { |
| 869 | HRESULT status = D3D_OK; |
| 870 | |
| 871 | if (mDeviceEx) |
| 872 | { |
| 873 | status = mDeviceEx->CheckDeviceState(NULL); |
| 874 | } |
| 875 | else if (mDevice) |
| 876 | { |
| 877 | status = mDevice->TestCooperativeLevel(); |
| 878 | } |
| 879 | |
| 880 | switch (status) |
| 881 | { |
| 882 | case D3DERR_DEVICENOTRESET: |
| 883 | case D3DERR_DEVICEHUNG: |
| 884 | return true; |
| 885 | default: |
| 886 | return false; |
| 887 | } |
| 888 | } |
| 889 | |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 890 | void Display::sync(bool block) |
| 891 | { |
| 892 | HRESULT result; |
| 893 | |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 894 | IDirect3DQuery9* query = allocateEventQuery(); |
| 895 | if (!query) |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 896 | { |
| 897 | return; |
| 898 | } |
| 899 | |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 900 | result = query->Issue(D3DISSUE_END); |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 901 | ASSERT(SUCCEEDED(result)); |
| 902 | |
| 903 | do |
| 904 | { |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 905 | result = query->GetData(NULL, 0, D3DGETDATA_FLUSH); |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 906 | |
| 907 | if(block && result == S_FALSE) |
| 908 | { |
| 909 | // Keep polling, but allow other threads to do something useful first |
| 910 | Sleep(0); |
| 911 | // explicitly check for device loss |
| 912 | // some drivers seem to return S_FALSE even if the device is lost |
| 913 | // instead of D3DERR_DEVICELOST like they should |
| 914 | if (testDeviceLost()) |
| 915 | { |
| 916 | result = D3DERR_DEVICELOST; |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | while(block && result == S_FALSE); |
| 921 | |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 922 | freeEventQuery(query); |
| 923 | |
daniel@transgaming.com | 2678b34 | 2012-01-18 16:29:40 +0000 | [diff] [blame] | 924 | if (isDeviceLostError(result)) |
| 925 | { |
| 926 | notifyDeviceLost(); |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | IDirect3DQuery9* Display::allocateEventQuery() |
| 931 | { |
| 932 | IDirect3DQuery9 *query = NULL; |
| 933 | |
| 934 | if (mEventQueryPool.empty()) |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 935 | { |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 936 | HRESULT result = mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &query); |
| 937 | ASSERT(SUCCEEDED(result)); |
| 938 | } |
| 939 | else |
| 940 | { |
| 941 | query = mEventQueryPool.back(); |
| 942 | mEventQueryPool.pop_back(); |
| 943 | } |
| 944 | |
| 945 | return query; |
| 946 | } |
| 947 | |
| 948 | void Display::freeEventQuery(IDirect3DQuery9* query) |
| 949 | { |
| 950 | if (mEventQueryPool.size() > 1000) |
| 951 | { |
| 952 | query->Release(); |
| 953 | } |
| 954 | else |
| 955 | { |
| 956 | mEventQueryPool.push_back(query); |
apatrick@chromium.org | a5ddde9 | 2012-01-10 23:00:07 +0000 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 960 | void Display::getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray) |
| 961 | { |
| 962 | for (int multiSampleIndex = 0; multiSampleIndex <= D3DMULTISAMPLE_16_SAMPLES; multiSampleIndex++) |
| 963 | { |
| 964 | HRESULT result = mD3d9->CheckDeviceMultiSampleType(mAdapter, mDeviceType, format, |
| 965 | TRUE, (D3DMULTISAMPLE_TYPE)multiSampleIndex, NULL); |
| 966 | |
| 967 | multiSampleArray[multiSampleIndex] = SUCCEEDED(result); |
| 968 | } |
| 969 | } |
| 970 | |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 971 | bool Display::getDXT1TextureSupport() |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 972 | { |
| 973 | D3DDISPLAYMODE currentDisplayMode; |
| 974 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 975 | |
| 976 | return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT1)); |
| 977 | } |
| 978 | |
gman@chromium.org | 50c526d | 2011-08-10 05:19:44 +0000 | [diff] [blame] | 979 | bool Display::getDXT3TextureSupport() |
| 980 | { |
| 981 | D3DDISPLAYMODE currentDisplayMode; |
| 982 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 983 | |
| 984 | return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT3)); |
| 985 | } |
| 986 | |
| 987 | bool Display::getDXT5TextureSupport() |
| 988 | { |
| 989 | D3DDISPLAYMODE currentDisplayMode; |
| 990 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 991 | |
| 992 | return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT5)); |
| 993 | } |
| 994 | |
daniel@transgaming.com | 1c49f79 | 2012-05-31 01:14:02 +0000 | [diff] [blame^] | 995 | // we use INTZ for depth textures in Direct3D9 |
| 996 | // we also want NULL texture support to ensure the we can make depth-only FBOs |
| 997 | // see http://aras-p.info/texts/D3D9GPUHacks.html |
| 998 | bool Display::getDepthTextureSupport() const |
| 999 | { |
| 1000 | D3DDISPLAYMODE currentDisplayMode; |
| 1001 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 1002 | |
| 1003 | bool intz = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, |
| 1004 | D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_INTZ)); |
| 1005 | bool null = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, |
| 1006 | D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL)); |
| 1007 | |
| 1008 | return intz && null; |
| 1009 | } |
| 1010 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 1011 | bool Display::getFloat32TextureSupport(bool *filtering, bool *renderable) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1012 | { |
| 1013 | D3DDISPLAYMODE currentDisplayMode; |
| 1014 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 1015 | |
| 1016 | *filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, |
| 1017 | D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && |
| 1018 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, |
| 1019 | D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); |
| 1020 | |
| 1021 | *renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, |
| 1022 | D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F))&& |
| 1023 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, |
| 1024 | D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); |
| 1025 | |
daniel@transgaming.com | bb5223d | 2012-01-24 13:38:10 +0000 | [diff] [blame] | 1026 | if (!*filtering && !*renderable) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1027 | { |
| 1028 | return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, |
| 1029 | D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)) && |
| 1030 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, |
| 1031 | D3DRTYPE_CUBETEXTURE, D3DFMT_A32B32G32R32F)); |
| 1032 | } |
| 1033 | else |
| 1034 | { |
| 1035 | return true; |
| 1036 | } |
| 1037 | } |
| 1038 | |
daniel@transgaming.com | bbeffbb | 2011-11-09 17:46:11 +0000 | [diff] [blame] | 1039 | bool Display::getFloat16TextureSupport(bool *filtering, bool *renderable) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1040 | { |
| 1041 | D3DDISPLAYMODE currentDisplayMode; |
| 1042 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 1043 | |
| 1044 | *filtering = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, |
| 1045 | D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && |
| 1046 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_FILTER, |
| 1047 | D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); |
| 1048 | |
| 1049 | *renderable = SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, |
| 1050 | D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && |
| 1051 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, |
| 1052 | D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); |
| 1053 | |
daniel@transgaming.com | bb5223d | 2012-01-24 13:38:10 +0000 | [diff] [blame] | 1054 | if (!*filtering && !*renderable) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1055 | { |
| 1056 | return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, |
| 1057 | D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) && |
| 1058 | SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, |
| 1059 | D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F)); |
| 1060 | } |
| 1061 | else |
| 1062 | { |
| 1063 | return true; |
| 1064 | } |
| 1065 | } |
| 1066 | |
daniel@transgaming.com | ed828e5 | 2010-10-15 17:57:30 +0000 | [diff] [blame] | 1067 | bool Display::getLuminanceTextureSupport() |
| 1068 | { |
| 1069 | D3DDISPLAYMODE currentDisplayMode; |
| 1070 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 1071 | |
| 1072 | return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_L8)); |
| 1073 | } |
| 1074 | |
| 1075 | bool Display::getLuminanceAlphaTextureSupport() |
| 1076 | { |
| 1077 | D3DDISPLAYMODE currentDisplayMode; |
| 1078 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 1079 | |
| 1080 | return SUCCEEDED(mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8L8)); |
| 1081 | } |
| 1082 | |
daniel@transgaming.com | ee04e45 | 2011-01-08 05:46:27 +0000 | [diff] [blame] | 1083 | D3DPOOL Display::getBufferPool(DWORD usage) const |
daniel@transgaming.com | 37b141e | 2011-01-08 05:46:13 +0000 | [diff] [blame] | 1084 | { |
apatrick@chromium.org | 9e83b59 | 2011-02-10 22:04:34 +0000 | [diff] [blame] | 1085 | if (mD3d9Ex != NULL) |
daniel@transgaming.com | ee04e45 | 2011-01-08 05:46:27 +0000 | [diff] [blame] | 1086 | { |
| 1087 | return D3DPOOL_DEFAULT; |
| 1088 | } |
| 1089 | else |
| 1090 | { |
| 1091 | if (!(usage & D3DUSAGE_DYNAMIC)) |
| 1092 | { |
| 1093 | return D3DPOOL_MANAGED; |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | return D3DPOOL_DEFAULT; |
daniel@transgaming.com | 37b141e | 2011-01-08 05:46:13 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
daniel@transgaming.com | 59580a3 | 2011-11-12 04:23:44 +0000 | [diff] [blame] | 1100 | D3DPOOL Display::getTexturePool(bool renderable) const |
| 1101 | { |
| 1102 | if (mD3d9Ex != NULL) |
| 1103 | { |
| 1104 | return D3DPOOL_DEFAULT; |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | if (!renderable) |
| 1109 | { |
| 1110 | return D3DPOOL_MANAGED; |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | return D3DPOOL_DEFAULT; |
| 1115 | } |
| 1116 | |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1117 | bool Display::getEventQuerySupport() |
| 1118 | { |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 1119 | IDirect3DQuery9 *query = allocateEventQuery(); |
| 1120 | if (query) |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1121 | { |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 1122 | freeEventQuery(query); |
| 1123 | return true; |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1124 | } |
apatrick@chromium.org | f289ee8 | 2012-01-11 20:03:29 +0000 | [diff] [blame] | 1125 | else |
| 1126 | { |
| 1127 | return false; |
| 1128 | } |
daniel@transgaming.com | e979ead | 2010-09-23 18:03:14 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | D3DPRESENT_PARAMETERS Display::getDefaultPresentParameters() |
| 1132 | { |
| 1133 | D3DPRESENT_PARAMETERS presentParameters = {0}; |
| 1134 | |
| 1135 | // The default swap chain is never actually used. Surface will create a new swap chain with the proper parameters. |
| 1136 | presentParameters.AutoDepthStencilFormat = D3DFMT_UNKNOWN; |
| 1137 | presentParameters.BackBufferCount = 1; |
| 1138 | presentParameters.BackBufferFormat = D3DFMT_UNKNOWN; |
| 1139 | presentParameters.BackBufferWidth = 1; |
| 1140 | presentParameters.BackBufferHeight = 1; |
| 1141 | presentParameters.EnableAutoDepthStencil = FALSE; |
| 1142 | presentParameters.Flags = 0; |
| 1143 | presentParameters.hDeviceWindow = mDeviceWindow; |
| 1144 | presentParameters.MultiSampleQuality = 0; |
| 1145 | presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; |
| 1146 | presentParameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; |
| 1147 | presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| 1148 | presentParameters.Windowed = TRUE; |
| 1149 | |
| 1150 | return presentParameters; |
| 1151 | } |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 1152 | |
| 1153 | void Display::initExtensionString() |
| 1154 | { |
jbauman@chromium.org | 84d7cbc | 2011-07-14 22:53:19 +0000 | [diff] [blame] | 1155 | HMODULE swiftShader = GetModuleHandle(TEXT("swiftshader_d3d9.dll")); |
daniel@transgaming.com | 1a1fe24 | 2011-09-26 18:25:45 +0000 | [diff] [blame] | 1156 | |
| 1157 | mExtensionString = ""; |
| 1158 | |
daniel@transgaming.com | 8747f18 | 2011-11-09 17:50:38 +0000 | [diff] [blame] | 1159 | // Multi-vendor (EXT) extensions |
| 1160 | mExtensionString += "EGL_EXT_create_context_robustness "; |
| 1161 | |
| 1162 | // ANGLE-specific extensions |
jbauman@chromium.org | 6c762d0 | 2012-02-03 23:31:53 +0000 | [diff] [blame] | 1163 | if (shareHandleSupported()) |
apatrick@chromium.org | f4490e2 | 2011-12-06 02:05:22 +0000 | [diff] [blame] | 1164 | { |
daniel@transgaming.com | 1a1fe24 | 2011-09-26 18:25:45 +0000 | [diff] [blame] | 1165 | mExtensionString += "EGL_ANGLE_d3d_share_handle_client_buffer "; |
| 1166 | } |
| 1167 | |
| 1168 | mExtensionString += "EGL_ANGLE_query_surface_pointer "; |
jbauman@chromium.org | 84d7cbc | 2011-07-14 22:53:19 +0000 | [diff] [blame] | 1169 | |
| 1170 | if (swiftShader) |
| 1171 | { |
apatrick@chromium.org | f4490e2 | 2011-12-06 02:05:22 +0000 | [diff] [blame] | 1172 | mExtensionString += "EGL_ANGLE_software_display "; |
jbauman@chromium.org | 84d7cbc | 2011-07-14 22:53:19 +0000 | [diff] [blame] | 1173 | } |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 1174 | |
jbauman@chromium.org | 6c762d0 | 2012-02-03 23:31:53 +0000 | [diff] [blame] | 1175 | if (shareHandleSupported()) |
apatrick@chromium.org | f4490e2 | 2011-12-06 02:05:22 +0000 | [diff] [blame] | 1176 | { |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 1177 | mExtensionString += "EGL_ANGLE_surface_d3d_texture_2d_share_handle "; |
| 1178 | } |
| 1179 | |
apatrick@chromium.org | f4490e2 | 2011-12-06 02:05:22 +0000 | [diff] [blame] | 1180 | mExtensionString += "EGL_NV_post_sub_buffer"; |
| 1181 | |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 1182 | std::string::size_type end = mExtensionString.find_last_not_of(' '); |
| 1183 | if (end != std::string::npos) |
| 1184 | { |
| 1185 | mExtensionString.resize(end+1); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | const char *Display::getExtensionString() const |
| 1190 | { |
| 1191 | return mExtensionString.c_str(); |
| 1192 | } |
| 1193 | |
jbauman@chromium.org | 6c762d0 | 2012-02-03 23:31:53 +0000 | [diff] [blame] | 1194 | bool Display::shareHandleSupported() const |
| 1195 | { |
| 1196 | // PIX doesn't seem to support using share handles, so disable them. |
| 1197 | return isD3d9ExDevice() && !gl::perfActive(); |
| 1198 | } |
| 1199 | |
daniel@transgaming.com | 3b1703f | 2011-05-11 15:36:26 +0000 | [diff] [blame] | 1200 | // Only Direct3D 10 ready devices support all the necessary vertex texture formats. |
| 1201 | // We test this using D3D9 by checking support for the R16F format. |
| 1202 | bool Display::getVertexTextureSupport() const |
| 1203 | { |
daniel@transgaming.com | 3b1703f | 2011-05-11 15:36:26 +0000 | [diff] [blame] | 1204 | if (!isInitialized() || mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(3, 0)) |
| 1205 | { |
| 1206 | return false; |
| 1207 | } |
| 1208 | |
| 1209 | D3DDISPLAYMODE currentDisplayMode; |
| 1210 | mD3d9->GetAdapterDisplayMode(mAdapter, ¤tDisplayMode); |
| 1211 | |
| 1212 | HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R16F); |
| 1213 | |
| 1214 | return SUCCEEDED(result); |
| 1215 | } |
| 1216 | |
daniel@transgaming.com | 4f9ef0d | 2011-05-30 23:51:19 +0000 | [diff] [blame] | 1217 | bool Display::getNonPower2TextureSupport() const |
| 1218 | { |
| 1219 | return !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_POW2) && |
| 1220 | !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2) && |
| 1221 | !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL); |
| 1222 | } |
| 1223 | |
daniel@transgaming.com | 86bdb82 | 2012-01-20 18:24:39 +0000 | [diff] [blame] | 1224 | bool Display::getOcclusionQuerySupport() const |
| 1225 | { |
| 1226 | if (!isInitialized()) |
| 1227 | { |
| 1228 | return false; |
| 1229 | } |
| 1230 | |
| 1231 | IDirect3DQuery9 *query = NULL; |
| 1232 | HRESULT result = mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &query); |
| 1233 | |
| 1234 | if (SUCCEEDED(result) && query) |
| 1235 | { |
| 1236 | query->Release(); |
| 1237 | return true; |
| 1238 | } |
| 1239 | else |
| 1240 | { |
| 1241 | return false; |
| 1242 | } |
| 1243 | } |
| 1244 | |
daniel@transgaming.com | c6f7f9d | 2012-01-27 15:40:00 +0000 | [diff] [blame] | 1245 | bool Display::getInstancingSupport() const |
| 1246 | { |
| 1247 | return mDeviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0); |
| 1248 | } |
| 1249 | |
vladimirv@gmail.com | 721b7f2 | 2011-02-11 00:54:47 +0000 | [diff] [blame] | 1250 | } |