Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // |
michael@0 | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
michael@0 | 3 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | // found in the LICENSE file. |
michael@0 | 5 | // |
michael@0 | 6 | |
michael@0 | 7 | // Display.cpp: Implements the egl::Display class, representing the abstract |
michael@0 | 8 | // display on which graphics are drawn. Implements EGLDisplay. |
michael@0 | 9 | // [EGL 1.4] section 2.1.2 page 3. |
michael@0 | 10 | |
michael@0 | 11 | #include "libEGL/Display.h" |
michael@0 | 12 | |
michael@0 | 13 | #include <algorithm> |
michael@0 | 14 | #include <map> |
michael@0 | 15 | #include <vector> |
michael@0 | 16 | |
michael@0 | 17 | #include "common/debug.h" |
michael@0 | 18 | #include "libGLESv2/mathutil.h" |
michael@0 | 19 | #include "libGLESv2/main.h" |
michael@0 | 20 | #include "libGLESv2/Context.h" |
michael@0 | 21 | #include "libGLESv2/renderer/SwapChain.h" |
michael@0 | 22 | |
michael@0 | 23 | #include "libEGL/main.h" |
michael@0 | 24 | #include "libEGL/Surface.h" |
michael@0 | 25 | |
michael@0 | 26 | namespace egl |
michael@0 | 27 | { |
michael@0 | 28 | namespace |
michael@0 | 29 | { |
michael@0 | 30 | typedef std::map<EGLNativeDisplayType, Display*> DisplayMap; |
michael@0 | 31 | DisplayMap displays; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | egl::Display *Display::getDisplay(EGLNativeDisplayType displayId) |
michael@0 | 35 | { |
michael@0 | 36 | if (displays.find(displayId) != displays.end()) |
michael@0 | 37 | { |
michael@0 | 38 | return displays[displayId]; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | // FIXME: Check if displayId is a valid display device context |
michael@0 | 42 | |
michael@0 | 43 | egl::Display *display = new egl::Display(displayId, (HDC)displayId); |
michael@0 | 44 | |
michael@0 | 45 | displays[displayId] = display; |
michael@0 | 46 | return display; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | Display::Display(EGLNativeDisplayType displayId, HDC deviceContext) : mDc(deviceContext) |
michael@0 | 50 | { |
michael@0 | 51 | mDisplayId = displayId; |
michael@0 | 52 | mRenderer = NULL; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | Display::~Display() |
michael@0 | 56 | { |
michael@0 | 57 | terminate(); |
michael@0 | 58 | |
michael@0 | 59 | DisplayMap::iterator thisDisplay = displays.find(mDisplayId); |
michael@0 | 60 | |
michael@0 | 61 | if (thisDisplay != displays.end()) |
michael@0 | 62 | { |
michael@0 | 63 | displays.erase(thisDisplay); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | bool Display::initialize() |
michael@0 | 68 | { |
michael@0 | 69 | if (isInitialized()) |
michael@0 | 70 | { |
michael@0 | 71 | return true; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | mRenderer = glCreateRenderer(this, mDc, mDisplayId); |
michael@0 | 75 | |
michael@0 | 76 | if (!mRenderer) |
michael@0 | 77 | { |
michael@0 | 78 | terminate(); |
michael@0 | 79 | return error(EGL_NOT_INITIALIZED, false); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | EGLint minSwapInterval = mRenderer->getMinSwapInterval(); |
michael@0 | 83 | EGLint maxSwapInterval = mRenderer->getMaxSwapInterval(); |
michael@0 | 84 | EGLint maxTextureWidth = mRenderer->getMaxTextureWidth(); |
michael@0 | 85 | EGLint maxTextureHeight = mRenderer->getMaxTextureHeight(); |
michael@0 | 86 | |
michael@0 | 87 | rx::ConfigDesc *descList; |
michael@0 | 88 | int numConfigs = mRenderer->generateConfigs(&descList); |
michael@0 | 89 | ConfigSet configSet; |
michael@0 | 90 | |
michael@0 | 91 | for (int i = 0; i < numConfigs; ++i) |
michael@0 | 92 | configSet.add(descList[i], minSwapInterval, maxSwapInterval, |
michael@0 | 93 | maxTextureWidth, maxTextureHeight); |
michael@0 | 94 | |
michael@0 | 95 | // Give the sorted configs a unique ID and store them internally |
michael@0 | 96 | EGLint index = 1; |
michael@0 | 97 | for (ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++) |
michael@0 | 98 | { |
michael@0 | 99 | Config configuration = *config; |
michael@0 | 100 | configuration.mConfigID = index; |
michael@0 | 101 | index++; |
michael@0 | 102 | |
michael@0 | 103 | mConfigSet.mSet.insert(configuration); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | mRenderer->deleteConfigs(descList); |
michael@0 | 107 | descList = NULL; |
michael@0 | 108 | |
michael@0 | 109 | if (!isInitialized()) |
michael@0 | 110 | { |
michael@0 | 111 | terminate(); |
michael@0 | 112 | return false; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | initExtensionString(); |
michael@0 | 116 | initVendorString(); |
michael@0 | 117 | |
michael@0 | 118 | return true; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | void Display::terminate() |
michael@0 | 122 | { |
michael@0 | 123 | while (!mSurfaceSet.empty()) |
michael@0 | 124 | { |
michael@0 | 125 | destroySurface(*mSurfaceSet.begin()); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | while (!mContextSet.empty()) |
michael@0 | 129 | { |
michael@0 | 130 | destroyContext(*mContextSet.begin()); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | glDestroyRenderer(mRenderer); |
michael@0 | 134 | mRenderer = NULL; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig) |
michael@0 | 138 | { |
michael@0 | 139 | return mConfigSet.getConfigs(configs, attribList, configSize, numConfig); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | bool Display::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value) |
michael@0 | 143 | { |
michael@0 | 144 | const egl::Config *configuration = mConfigSet.get(config); |
michael@0 | 145 | |
michael@0 | 146 | switch (attribute) |
michael@0 | 147 | { |
michael@0 | 148 | case EGL_BUFFER_SIZE: *value = configuration->mBufferSize; break; |
michael@0 | 149 | case EGL_ALPHA_SIZE: *value = configuration->mAlphaSize; break; |
michael@0 | 150 | case EGL_BLUE_SIZE: *value = configuration->mBlueSize; break; |
michael@0 | 151 | case EGL_GREEN_SIZE: *value = configuration->mGreenSize; break; |
michael@0 | 152 | case EGL_RED_SIZE: *value = configuration->mRedSize; break; |
michael@0 | 153 | case EGL_DEPTH_SIZE: *value = configuration->mDepthSize; break; |
michael@0 | 154 | case EGL_STENCIL_SIZE: *value = configuration->mStencilSize; break; |
michael@0 | 155 | case EGL_CONFIG_CAVEAT: *value = configuration->mConfigCaveat; break; |
michael@0 | 156 | case EGL_CONFIG_ID: *value = configuration->mConfigID; break; |
michael@0 | 157 | case EGL_LEVEL: *value = configuration->mLevel; break; |
michael@0 | 158 | case EGL_NATIVE_RENDERABLE: *value = configuration->mNativeRenderable; break; |
michael@0 | 159 | case EGL_NATIVE_VISUAL_TYPE: *value = configuration->mNativeVisualType; break; |
michael@0 | 160 | case EGL_SAMPLES: *value = configuration->mSamples; break; |
michael@0 | 161 | case EGL_SAMPLE_BUFFERS: *value = configuration->mSampleBuffers; break; |
michael@0 | 162 | case EGL_SURFACE_TYPE: *value = configuration->mSurfaceType; break; |
michael@0 | 163 | case EGL_TRANSPARENT_TYPE: *value = configuration->mTransparentType; break; |
michael@0 | 164 | case EGL_TRANSPARENT_BLUE_VALUE: *value = configuration->mTransparentBlueValue; break; |
michael@0 | 165 | case EGL_TRANSPARENT_GREEN_VALUE: *value = configuration->mTransparentGreenValue; break; |
michael@0 | 166 | case EGL_TRANSPARENT_RED_VALUE: *value = configuration->mTransparentRedValue; break; |
michael@0 | 167 | case EGL_BIND_TO_TEXTURE_RGB: *value = configuration->mBindToTextureRGB; break; |
michael@0 | 168 | case EGL_BIND_TO_TEXTURE_RGBA: *value = configuration->mBindToTextureRGBA; break; |
michael@0 | 169 | case EGL_MIN_SWAP_INTERVAL: *value = configuration->mMinSwapInterval; break; |
michael@0 | 170 | case EGL_MAX_SWAP_INTERVAL: *value = configuration->mMaxSwapInterval; break; |
michael@0 | 171 | case EGL_LUMINANCE_SIZE: *value = configuration->mLuminanceSize; break; |
michael@0 | 172 | case EGL_ALPHA_MASK_SIZE: *value = configuration->mAlphaMaskSize; break; |
michael@0 | 173 | case EGL_COLOR_BUFFER_TYPE: *value = configuration->mColorBufferType; break; |
michael@0 | 174 | case EGL_RENDERABLE_TYPE: *value = configuration->mRenderableType; break; |
michael@0 | 175 | case EGL_MATCH_NATIVE_PIXMAP: *value = false; UNIMPLEMENTED(); break; |
michael@0 | 176 | case EGL_CONFORMANT: *value = configuration->mConformant; break; |
michael@0 | 177 | case EGL_MAX_PBUFFER_WIDTH: *value = configuration->mMaxPBufferWidth; break; |
michael@0 | 178 | case EGL_MAX_PBUFFER_HEIGHT: *value = configuration->mMaxPBufferHeight; break; |
michael@0 | 179 | case EGL_MAX_PBUFFER_PIXELS: *value = configuration->mMaxPBufferPixels; break; |
michael@0 | 180 | default: |
michael@0 | 181 | return false; |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | return true; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | |
michael@0 | 188 | |
michael@0 | 189 | EGLSurface Display::createWindowSurface(HWND window, EGLConfig config, const EGLint *attribList) |
michael@0 | 190 | { |
michael@0 | 191 | const Config *configuration = mConfigSet.get(config); |
michael@0 | 192 | EGLint postSubBufferSupported = EGL_FALSE; |
michael@0 | 193 | |
michael@0 | 194 | if (attribList) |
michael@0 | 195 | { |
michael@0 | 196 | while (*attribList != EGL_NONE) |
michael@0 | 197 | { |
michael@0 | 198 | switch (attribList[0]) |
michael@0 | 199 | { |
michael@0 | 200 | case EGL_RENDER_BUFFER: |
michael@0 | 201 | switch (attribList[1]) |
michael@0 | 202 | { |
michael@0 | 203 | case EGL_BACK_BUFFER: |
michael@0 | 204 | break; |
michael@0 | 205 | case EGL_SINGLE_BUFFER: |
michael@0 | 206 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); // Rendering directly to front buffer not supported |
michael@0 | 207 | default: |
michael@0 | 208 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
michael@0 | 209 | } |
michael@0 | 210 | break; |
michael@0 | 211 | case EGL_POST_SUB_BUFFER_SUPPORTED_NV: |
michael@0 | 212 | postSubBufferSupported = attribList[1]; |
michael@0 | 213 | break; |
michael@0 | 214 | case EGL_VG_COLORSPACE: |
michael@0 | 215 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
michael@0 | 216 | case EGL_VG_ALPHA_FORMAT: |
michael@0 | 217 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
michael@0 | 218 | default: |
michael@0 | 219 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | attribList += 2; |
michael@0 | 223 | } |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | if (hasExistingWindowSurface(window)) |
michael@0 | 227 | { |
michael@0 | 228 | return error(EGL_BAD_ALLOC, EGL_NO_SURFACE); |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | if (mRenderer->testDeviceLost(false)) |
michael@0 | 232 | { |
michael@0 | 233 | if (!restoreLostDevice()) |
michael@0 | 234 | return EGL_NO_SURFACE; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | Surface *surface = new Surface(this, configuration, window, postSubBufferSupported); |
michael@0 | 238 | |
michael@0 | 239 | if (!surface->initialize()) |
michael@0 | 240 | { |
michael@0 | 241 | delete surface; |
michael@0 | 242 | return EGL_NO_SURFACE; |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | mSurfaceSet.insert(surface); |
michael@0 | 246 | |
michael@0 | 247 | return success(surface); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | EGLSurface Display::createOffscreenSurface(EGLConfig config, HANDLE shareHandle, const EGLint *attribList) |
michael@0 | 251 | { |
michael@0 | 252 | EGLint width = 0, height = 0; |
michael@0 | 253 | EGLenum textureFormat = EGL_NO_TEXTURE; |
michael@0 | 254 | EGLenum textureTarget = EGL_NO_TEXTURE; |
michael@0 | 255 | const Config *configuration = mConfigSet.get(config); |
michael@0 | 256 | |
michael@0 | 257 | if (attribList) |
michael@0 | 258 | { |
michael@0 | 259 | while (*attribList != EGL_NONE) |
michael@0 | 260 | { |
michael@0 | 261 | switch (attribList[0]) |
michael@0 | 262 | { |
michael@0 | 263 | case EGL_WIDTH: |
michael@0 | 264 | width = attribList[1]; |
michael@0 | 265 | break; |
michael@0 | 266 | case EGL_HEIGHT: |
michael@0 | 267 | height = attribList[1]; |
michael@0 | 268 | break; |
michael@0 | 269 | case EGL_LARGEST_PBUFFER: |
michael@0 | 270 | if (attribList[1] != EGL_FALSE) |
michael@0 | 271 | UNIMPLEMENTED(); // FIXME |
michael@0 | 272 | break; |
michael@0 | 273 | case EGL_TEXTURE_FORMAT: |
michael@0 | 274 | switch (attribList[1]) |
michael@0 | 275 | { |
michael@0 | 276 | case EGL_NO_TEXTURE: |
michael@0 | 277 | case EGL_TEXTURE_RGB: |
michael@0 | 278 | case EGL_TEXTURE_RGBA: |
michael@0 | 279 | textureFormat = attribList[1]; |
michael@0 | 280 | break; |
michael@0 | 281 | default: |
michael@0 | 282 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
michael@0 | 283 | } |
michael@0 | 284 | break; |
michael@0 | 285 | case EGL_TEXTURE_TARGET: |
michael@0 | 286 | switch (attribList[1]) |
michael@0 | 287 | { |
michael@0 | 288 | case EGL_NO_TEXTURE: |
michael@0 | 289 | case EGL_TEXTURE_2D: |
michael@0 | 290 | textureTarget = attribList[1]; |
michael@0 | 291 | break; |
michael@0 | 292 | default: |
michael@0 | 293 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
michael@0 | 294 | } |
michael@0 | 295 | break; |
michael@0 | 296 | case EGL_MIPMAP_TEXTURE: |
michael@0 | 297 | if (attribList[1] != EGL_FALSE) |
michael@0 | 298 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
michael@0 | 299 | break; |
michael@0 | 300 | case EGL_VG_COLORSPACE: |
michael@0 | 301 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
michael@0 | 302 | case EGL_VG_ALPHA_FORMAT: |
michael@0 | 303 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
michael@0 | 304 | default: |
michael@0 | 305 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | attribList += 2; |
michael@0 | 309 | } |
michael@0 | 310 | } |
michael@0 | 311 | |
michael@0 | 312 | if (width < 0 || height < 0) |
michael@0 | 313 | { |
michael@0 | 314 | return error(EGL_BAD_PARAMETER, EGL_NO_SURFACE); |
michael@0 | 315 | } |
michael@0 | 316 | |
michael@0 | 317 | if (width == 0 || height == 0) |
michael@0 | 318 | { |
michael@0 | 319 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
michael@0 | 320 | } |
michael@0 | 321 | |
michael@0 | 322 | if (textureFormat != EGL_NO_TEXTURE && !mRenderer->getNonPower2TextureSupport() && (!gl::isPow2(width) || !gl::isPow2(height))) |
michael@0 | 323 | { |
michael@0 | 324 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | if ((textureFormat != EGL_NO_TEXTURE && textureTarget == EGL_NO_TEXTURE) || |
michael@0 | 328 | (textureFormat == EGL_NO_TEXTURE && textureTarget != EGL_NO_TEXTURE)) |
michael@0 | 329 | { |
michael@0 | 330 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
michael@0 | 331 | } |
michael@0 | 332 | |
michael@0 | 333 | if (!(configuration->mSurfaceType & EGL_PBUFFER_BIT)) |
michael@0 | 334 | { |
michael@0 | 335 | return error(EGL_BAD_MATCH, EGL_NO_SURFACE); |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | if ((textureFormat == EGL_TEXTURE_RGB && configuration->mBindToTextureRGB != EGL_TRUE) || |
michael@0 | 339 | (textureFormat == EGL_TEXTURE_RGBA && configuration->mBindToTextureRGBA != EGL_TRUE)) |
michael@0 | 340 | { |
michael@0 | 341 | return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
michael@0 | 342 | } |
michael@0 | 343 | |
michael@0 | 344 | if (mRenderer->testDeviceLost(false)) |
michael@0 | 345 | { |
michael@0 | 346 | if (!restoreLostDevice()) |
michael@0 | 347 | return EGL_NO_SURFACE; |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | Surface *surface = new Surface(this, configuration, shareHandle, width, height, textureFormat, textureTarget); |
michael@0 | 351 | |
michael@0 | 352 | if (!surface->initialize()) |
michael@0 | 353 | { |
michael@0 | 354 | delete surface; |
michael@0 | 355 | return EGL_NO_SURFACE; |
michael@0 | 356 | } |
michael@0 | 357 | |
michael@0 | 358 | mSurfaceSet.insert(surface); |
michael@0 | 359 | |
michael@0 | 360 | return success(surface); |
michael@0 | 361 | } |
michael@0 | 362 | |
michael@0 | 363 | EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *shareContext, bool notifyResets, bool robustAccess) |
michael@0 | 364 | { |
michael@0 | 365 | if (!mRenderer) |
michael@0 | 366 | { |
michael@0 | 367 | return NULL; |
michael@0 | 368 | } |
michael@0 | 369 | else if (mRenderer->testDeviceLost(false)) // Lost device |
michael@0 | 370 | { |
michael@0 | 371 | if (!restoreLostDevice()) |
michael@0 | 372 | return NULL; |
michael@0 | 373 | } |
michael@0 | 374 | |
michael@0 | 375 | gl::Context *context = glCreateContext(shareContext, mRenderer, notifyResets, robustAccess); |
michael@0 | 376 | mContextSet.insert(context); |
michael@0 | 377 | |
michael@0 | 378 | return context; |
michael@0 | 379 | } |
michael@0 | 380 | |
michael@0 | 381 | bool Display::restoreLostDevice() |
michael@0 | 382 | { |
michael@0 | 383 | for (ContextSet::iterator ctx = mContextSet.begin(); ctx != mContextSet.end(); ctx++) |
michael@0 | 384 | { |
michael@0 | 385 | if ((*ctx)->isResetNotificationEnabled()) |
michael@0 | 386 | return false; // If reset notifications have been requested, application must delete all contexts first |
michael@0 | 387 | } |
michael@0 | 388 | |
michael@0 | 389 | // Release surface resources to make the Reset() succeed |
michael@0 | 390 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
michael@0 | 391 | { |
michael@0 | 392 | (*surface)->release(); |
michael@0 | 393 | } |
michael@0 | 394 | |
michael@0 | 395 | if (!mRenderer->resetDevice()) |
michael@0 | 396 | { |
michael@0 | 397 | return error(EGL_BAD_ALLOC, false); |
michael@0 | 398 | } |
michael@0 | 399 | |
michael@0 | 400 | // Restore any surfaces that may have been lost |
michael@0 | 401 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
michael@0 | 402 | { |
michael@0 | 403 | (*surface)->resetSwapChain(); |
michael@0 | 404 | } |
michael@0 | 405 | |
michael@0 | 406 | return true; |
michael@0 | 407 | } |
michael@0 | 408 | |
michael@0 | 409 | |
michael@0 | 410 | void Display::destroySurface(egl::Surface *surface) |
michael@0 | 411 | { |
michael@0 | 412 | delete surface; |
michael@0 | 413 | mSurfaceSet.erase(surface); |
michael@0 | 414 | } |
michael@0 | 415 | |
michael@0 | 416 | void Display::destroyContext(gl::Context *context) |
michael@0 | 417 | { |
michael@0 | 418 | glDestroyContext(context); |
michael@0 | 419 | mContextSet.erase(context); |
michael@0 | 420 | } |
michael@0 | 421 | |
michael@0 | 422 | void Display::notifyDeviceLost() |
michael@0 | 423 | { |
michael@0 | 424 | for (ContextSet::iterator context = mContextSet.begin(); context != mContextSet.end(); context++) |
michael@0 | 425 | { |
michael@0 | 426 | (*context)->markContextLost(); |
michael@0 | 427 | } |
michael@0 | 428 | egl::error(EGL_CONTEXT_LOST); |
michael@0 | 429 | } |
michael@0 | 430 | |
michael@0 | 431 | void Display::recreateSwapChains() |
michael@0 | 432 | { |
michael@0 | 433 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
michael@0 | 434 | { |
michael@0 | 435 | (*surface)->getSwapChain()->recreate(); |
michael@0 | 436 | } |
michael@0 | 437 | } |
michael@0 | 438 | |
michael@0 | 439 | bool Display::isInitialized() const |
michael@0 | 440 | { |
michael@0 | 441 | return mRenderer != NULL && mConfigSet.size() > 0; |
michael@0 | 442 | } |
michael@0 | 443 | |
michael@0 | 444 | bool Display::isValidConfig(EGLConfig config) |
michael@0 | 445 | { |
michael@0 | 446 | return mConfigSet.get(config) != NULL; |
michael@0 | 447 | } |
michael@0 | 448 | |
michael@0 | 449 | bool Display::isValidContext(gl::Context *context) |
michael@0 | 450 | { |
michael@0 | 451 | return mContextSet.find(context) != mContextSet.end(); |
michael@0 | 452 | } |
michael@0 | 453 | |
michael@0 | 454 | bool Display::isValidSurface(egl::Surface *surface) |
michael@0 | 455 | { |
michael@0 | 456 | return mSurfaceSet.find(surface) != mSurfaceSet.end(); |
michael@0 | 457 | } |
michael@0 | 458 | |
michael@0 | 459 | bool Display::hasExistingWindowSurface(HWND window) |
michael@0 | 460 | { |
michael@0 | 461 | for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) |
michael@0 | 462 | { |
michael@0 | 463 | if ((*surface)->getWindowHandle() == window) |
michael@0 | 464 | { |
michael@0 | 465 | return true; |
michael@0 | 466 | } |
michael@0 | 467 | } |
michael@0 | 468 | |
michael@0 | 469 | return false; |
michael@0 | 470 | } |
michael@0 | 471 | |
michael@0 | 472 | void Display::initExtensionString() |
michael@0 | 473 | { |
michael@0 | 474 | HMODULE swiftShader = GetModuleHandle(TEXT("swiftshader_d3d9.dll")); |
michael@0 | 475 | bool shareHandleSupported = mRenderer->getShareHandleSupport(); |
michael@0 | 476 | |
michael@0 | 477 | mExtensionString = ""; |
michael@0 | 478 | |
michael@0 | 479 | // Multi-vendor (EXT) extensions |
michael@0 | 480 | mExtensionString += "EGL_EXT_create_context_robustness "; |
michael@0 | 481 | |
michael@0 | 482 | // ANGLE-specific extensions |
michael@0 | 483 | if (shareHandleSupported) |
michael@0 | 484 | { |
michael@0 | 485 | mExtensionString += "EGL_ANGLE_d3d_share_handle_client_buffer "; |
michael@0 | 486 | } |
michael@0 | 487 | |
michael@0 | 488 | mExtensionString += "EGL_ANGLE_query_surface_pointer "; |
michael@0 | 489 | |
michael@0 | 490 | if (swiftShader) |
michael@0 | 491 | { |
michael@0 | 492 | mExtensionString += "EGL_ANGLE_software_display "; |
michael@0 | 493 | } |
michael@0 | 494 | |
michael@0 | 495 | if (shareHandleSupported) |
michael@0 | 496 | { |
michael@0 | 497 | mExtensionString += "EGL_ANGLE_surface_d3d_texture_2d_share_handle "; |
michael@0 | 498 | } |
michael@0 | 499 | |
michael@0 | 500 | if (mRenderer->getPostSubBufferSupport()) |
michael@0 | 501 | { |
michael@0 | 502 | mExtensionString += "EGL_NV_post_sub_buffer"; |
michael@0 | 503 | } |
michael@0 | 504 | |
michael@0 | 505 | std::string::size_type end = mExtensionString.find_last_not_of(' '); |
michael@0 | 506 | if (end != std::string::npos) |
michael@0 | 507 | { |
michael@0 | 508 | mExtensionString.resize(end+1); |
michael@0 | 509 | } |
michael@0 | 510 | } |
michael@0 | 511 | |
michael@0 | 512 | const char *Display::getExtensionString() const |
michael@0 | 513 | { |
michael@0 | 514 | return mExtensionString.c_str(); |
michael@0 | 515 | } |
michael@0 | 516 | |
michael@0 | 517 | void Display::initVendorString() |
michael@0 | 518 | { |
michael@0 | 519 | mVendorString = "Google Inc."; |
michael@0 | 520 | |
michael@0 | 521 | LUID adapterLuid = {0}; |
michael@0 | 522 | |
michael@0 | 523 | if (mRenderer && mRenderer->getLUID(&adapterLuid)) |
michael@0 | 524 | { |
michael@0 | 525 | char adapterLuidString[64]; |
michael@0 | 526 | sprintf_s(adapterLuidString, sizeof(adapterLuidString), " (adapter LUID: %08x%08x)", adapterLuid.HighPart, adapterLuid.LowPart); |
michael@0 | 527 | |
michael@0 | 528 | mVendorString += adapterLuidString; |
michael@0 | 529 | } |
michael@0 | 530 | } |
michael@0 | 531 | |
michael@0 | 532 | const char *Display::getVendorString() const |
michael@0 | 533 | { |
michael@0 | 534 | return mVendorString.c_str(); |
michael@0 | 535 | } |
michael@0 | 536 | |
michael@0 | 537 | } |