Commit a86d5e11 by Nicolas Capens

Fix eglGetDisplay(EGL_DEFAULT_DISPLAY) on Linux.

parent c844fec7
This source diff could not be displayed because it is too large. You can view the blob instead.
// SwiftShader Software Renderer // SwiftShader Software Renderer
// //
// Copyright(c) 2005-2013 TransGaming Inc. // Copyright(c) 2005-2013 TransGaming Inc.
// //
// All rights reserved. No part of this software may be copied, distributed, transmitted, // All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer // transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written // language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you. // or implied, including but not limited to any patent rights, are granted to you.
// //
// Display.cpp: Implements the egl::Display class, representing the abstract // Display.cpp: Implements the egl::Display class, representing the abstract
// display on which graphics are drawn. Implements EGLDisplay. // display on which graphics are drawn. Implements EGLDisplay.
// [EGL 1.4] section 2.1.2 page 3. // [EGL 1.4] section 2.1.2 page 3.
#include "Display.h" #include "Display.h"
#include "main.h" #include "main.h"
#include "libEGL/Surface.h" #include "libEGL/Surface.h"
#include "libEGL/Context.hpp" #include "libEGL/Context.hpp"
#include "common/debug.h" #include "common/debug.h"
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <map> #include <map>
namespace egl namespace egl
{ {
typedef std::map<EGLNativeDisplayType, Display*> DisplayMap; typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
DisplayMap displays; DisplayMap displays;
egl::Display *Display::getDisplay(EGLNativeDisplayType displayId) egl::Display *Display::getDisplay(EGLNativeDisplayType displayId)
{ {
if(displays.find(displayId) != displays.end()) if(displayId == EGL_DEFAULT_DISPLAY)
{ {
return displays[displayId]; #if defined(__unix__)
} displayId = XOpenDisplay(NULL);
#endif
egl::Display *display = NULL; }
if(displayId == EGL_DEFAULT_DISPLAY) if(displays.find(displayId) != displays.end())
{ {
display = new egl::Display(displayId); return displays[displayId];
} }
else
{ // FIXME: Check if displayId is a valid display device context
// FIXME: Check if displayId is a valid display device context
egl::Display *display = new egl::Display(displayId);
display = new egl::Display(displayId);
} displays[displayId] = display;
return display;
displays[displayId] = display; }
return display;
} Display::Display(EGLNativeDisplayType displayId) : displayId(displayId)
{
Display::Display(EGLNativeDisplayType displayId) : displayId(displayId) mMinSwapInterval = 1;
{ mMaxSwapInterval = 1;
mMinSwapInterval = 1; }
mMaxSwapInterval = 1;
} Display::~Display()
{
Display::~Display() terminate();
{
terminate(); displays.erase(displayId);
}
displays.erase(displayId);
} static void cpuid(int registers[4], int info)
{
static void cpuid(int registers[4], int info) #if defined(_WIN32)
{ __cpuid(registers, info);
#if defined(_WIN32) #else
__cpuid(registers, info); __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
#else #endif
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); }
#endif
} static bool detectSSE()
{
static bool detectSSE() #if defined(__APPLE__)
{ int SSE = false;
#if defined(__APPLE__) size_t length = sizeof(SSE);
int SSE = false; sysctlbyname("hw.optional.sse", &SSE, &length, 0, 0);
size_t length = sizeof(SSE); return SSE;
sysctlbyname("hw.optional.sse", &SSE, &length, 0, 0); #else
return SSE; int registers[4];
#else cpuid(registers, 1);
int registers[4]; return (registers[3] & 0x02000000) != 0;
cpuid(registers, 1); #endif
return (registers[3] & 0x02000000) != 0; }
#endif
} bool Display::initialize()
{
bool Display::initialize() if(isInitialized())
{ {
if(isInitialized()) return true;
{ }
return true;
} if(!detectSSE())
{
if(!detectSSE()) return false;
{ }
return false;
} mMinSwapInterval = 0;
mMaxSwapInterval = 4;
mMinSwapInterval = 0;
mMaxSwapInterval = 4; const sw::Format renderTargetFormats[] =
{
const sw::Format renderTargetFormats[] = sw::FORMAT_A1R5G5B5,
{ // sw::FORMAT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value.
sw::FORMAT_A1R5G5B5, sw::FORMAT_A8R8G8B8,
// sw::FORMAT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value. sw::FORMAT_R5G6B5,
sw::FORMAT_A8R8G8B8, // sw::FORMAT_X1R5G5B5, // Has no compatible OpenGL ES renderbuffer format
sw::FORMAT_R5G6B5, sw::FORMAT_X8R8G8B8
// sw::FORMAT_X1R5G5B5, // Has no compatible OpenGL ES renderbuffer format };
sw::FORMAT_X8R8G8B8
}; const sw::Format depthStencilFormats[] =
{
const sw::Format depthStencilFormats[] = sw::FORMAT_NULL,
{ // sw::FORMAT_D16_LOCKABLE,
sw::FORMAT_NULL, sw::FORMAT_D32,
// sw::FORMAT_D16_LOCKABLE, // sw::FORMAT_D15S1,
sw::FORMAT_D32, sw::FORMAT_D24S8,
// sw::FORMAT_D15S1, sw::FORMAT_D24X8,
sw::FORMAT_D24S8, // sw::FORMAT_D24X4S4,
sw::FORMAT_D24X8, sw::FORMAT_D16,
// sw::FORMAT_D24X4S4, // sw::FORMAT_D32F_LOCKABLE,
sw::FORMAT_D16, // sw::FORMAT_D24FS8
// sw::FORMAT_D32F_LOCKABLE, };
// sw::FORMAT_D24FS8
}; DisplayMode currentDisplayMode = getDisplayMode();
ConfigSet configSet;
DisplayMode currentDisplayMode = getDisplayMode();
ConfigSet configSet; for(int formatIndex = 0; formatIndex < sizeof(renderTargetFormats) / sizeof(sw::Format); formatIndex++)
{
for(int formatIndex = 0; formatIndex < sizeof(renderTargetFormats) / sizeof(sw::Format); formatIndex++) sw::Format renderTargetFormat = renderTargetFormats[formatIndex];
{
sw::Format renderTargetFormat = renderTargetFormats[formatIndex]; for(int depthStencilIndex = 0; depthStencilIndex < sizeof(depthStencilFormats) / sizeof(sw::Format); depthStencilIndex++)
{
for(int depthStencilIndex = 0; depthStencilIndex < sizeof(depthStencilFormats) / sizeof(sw::Format); depthStencilIndex++) sw::Format depthStencilFormat = depthStencilFormats[depthStencilIndex];
{
sw::Format depthStencilFormat = depthStencilFormats[depthStencilIndex]; // FIXME: enumerate multi-sampling
// FIXME: enumerate multi-sampling configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0);
}
configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0); }
}
} // Give the sorted configs a unique ID and store them internally
EGLint index = 1;
// Give the sorted configs a unique ID and store them internally for(ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++)
EGLint index = 1; {
for(ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++) Config configuration = *config;
{ configuration.mConfigID = index;
Config configuration = *config; index++;
configuration.mConfigID = index;
index++; mConfigSet.mSet.insert(configuration);
}
mConfigSet.mSet.insert(configuration);
} if(!isInitialized())
{
if(!isInitialized()) terminate();
{
terminate(); return false;
}
return false;
} return true;
}
return true;
} void Display::terminate()
{
void Display::terminate() while(!mSurfaceSet.empty())
{ {
while(!mSurfaceSet.empty()) destroySurface(*mSurfaceSet.begin());
{ }
destroySurface(*mSurfaceSet.begin());
} while(!mContextSet.empty())
{
while(!mContextSet.empty()) destroyContext(*mContextSet.begin());
{ }
destroyContext(*mContextSet.begin()); }
}
} bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig)
{
bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig) return mConfigSet.getConfigs(configs, attribList, configSize, numConfig);
{ }
return mConfigSet.getConfigs(configs, attribList, configSize, numConfig);
} bool Display::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value)
{
bool Display::getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value) const egl::Config *configuration = mConfigSet.get(config);
{
const egl::Config *configuration = mConfigSet.get(config); switch (attribute)
{
switch (attribute) case EGL_BUFFER_SIZE: *value = configuration->mBufferSize; break;
{ case EGL_ALPHA_SIZE: *value = configuration->mAlphaSize; break;
case EGL_BUFFER_SIZE: *value = configuration->mBufferSize; break; case EGL_BLUE_SIZE: *value = configuration->mBlueSize; break;
case EGL_ALPHA_SIZE: *value = configuration->mAlphaSize; break; case EGL_GREEN_SIZE: *value = configuration->mGreenSize; break;
case EGL_BLUE_SIZE: *value = configuration->mBlueSize; break; case EGL_RED_SIZE: *value = configuration->mRedSize; break;
case EGL_GREEN_SIZE: *value = configuration->mGreenSize; break; case EGL_DEPTH_SIZE: *value = configuration->mDepthSize; break;
case EGL_RED_SIZE: *value = configuration->mRedSize; break; case EGL_STENCIL_SIZE: *value = configuration->mStencilSize; break;
case EGL_DEPTH_SIZE: *value = configuration->mDepthSize; break; case EGL_CONFIG_CAVEAT: *value = configuration->mConfigCaveat; break;
case EGL_STENCIL_SIZE: *value = configuration->mStencilSize; break; case EGL_CONFIG_ID: *value = configuration->mConfigID; break;
case EGL_CONFIG_CAVEAT: *value = configuration->mConfigCaveat; break; case EGL_LEVEL: *value = configuration->mLevel; break;
case EGL_CONFIG_ID: *value = configuration->mConfigID; break; case EGL_NATIVE_RENDERABLE: *value = configuration->mNativeRenderable; break;
case EGL_LEVEL: *value = configuration->mLevel; break; case EGL_NATIVE_VISUAL_ID: *value = configuration->mNativeVisualID; break;
case EGL_NATIVE_RENDERABLE: *value = configuration->mNativeRenderable; break; case EGL_NATIVE_VISUAL_TYPE: *value = configuration->mNativeVisualType; break;
case EGL_NATIVE_VISUAL_ID: *value = configuration->mNativeVisualID; break; case EGL_SAMPLES: *value = configuration->mSamples; break;
case EGL_NATIVE_VISUAL_TYPE: *value = configuration->mNativeVisualType; break; case EGL_SAMPLE_BUFFERS: *value = configuration->mSampleBuffers; break;
case EGL_SAMPLES: *value = configuration->mSamples; break; case EGL_SURFACE_TYPE: *value = configuration->mSurfaceType; break;
case EGL_SAMPLE_BUFFERS: *value = configuration->mSampleBuffers; break; case EGL_TRANSPARENT_TYPE: *value = configuration->mTransparentType; break;
case EGL_SURFACE_TYPE: *value = configuration->mSurfaceType; break; case EGL_TRANSPARENT_BLUE_VALUE: *value = configuration->mTransparentBlueValue; break;
case EGL_TRANSPARENT_TYPE: *value = configuration->mTransparentType; break; case EGL_TRANSPARENT_GREEN_VALUE: *value = configuration->mTransparentGreenValue; break;
case EGL_TRANSPARENT_BLUE_VALUE: *value = configuration->mTransparentBlueValue; break; case EGL_TRANSPARENT_RED_VALUE: *value = configuration->mTransparentRedValue; break;
case EGL_TRANSPARENT_GREEN_VALUE: *value = configuration->mTransparentGreenValue; break; case EGL_BIND_TO_TEXTURE_RGB: *value = configuration->mBindToTextureRGB; break;
case EGL_TRANSPARENT_RED_VALUE: *value = configuration->mTransparentRedValue; break; case EGL_BIND_TO_TEXTURE_RGBA: *value = configuration->mBindToTextureRGBA; break;
case EGL_BIND_TO_TEXTURE_RGB: *value = configuration->mBindToTextureRGB; break; case EGL_MIN_SWAP_INTERVAL: *value = configuration->mMinSwapInterval; break;
case EGL_BIND_TO_TEXTURE_RGBA: *value = configuration->mBindToTextureRGBA; break; case EGL_MAX_SWAP_INTERVAL: *value = configuration->mMaxSwapInterval; break;
case EGL_MIN_SWAP_INTERVAL: *value = configuration->mMinSwapInterval; break; case EGL_LUMINANCE_SIZE: *value = configuration->mLuminanceSize; break;
case EGL_MAX_SWAP_INTERVAL: *value = configuration->mMaxSwapInterval; break; case EGL_ALPHA_MASK_SIZE: *value = configuration->mAlphaMaskSize; break;
case EGL_LUMINANCE_SIZE: *value = configuration->mLuminanceSize; break; case EGL_COLOR_BUFFER_TYPE: *value = configuration->mColorBufferType; break;
case EGL_ALPHA_MASK_SIZE: *value = configuration->mAlphaMaskSize; break; case EGL_RENDERABLE_TYPE: *value = configuration->mRenderableType; break;
case EGL_COLOR_BUFFER_TYPE: *value = configuration->mColorBufferType; break; case EGL_MATCH_NATIVE_PIXMAP: *value = false; UNIMPLEMENTED(); break;
case EGL_RENDERABLE_TYPE: *value = configuration->mRenderableType; break; case EGL_CONFORMANT: *value = configuration->mConformant; break;
case EGL_MATCH_NATIVE_PIXMAP: *value = false; UNIMPLEMENTED(); break; case EGL_MAX_PBUFFER_WIDTH: *value = configuration->mMaxPBufferWidth; break;
case EGL_CONFORMANT: *value = configuration->mConformant; break; case EGL_MAX_PBUFFER_HEIGHT: *value = configuration->mMaxPBufferHeight; break;
case EGL_MAX_PBUFFER_WIDTH: *value = configuration->mMaxPBufferWidth; break; case EGL_MAX_PBUFFER_PIXELS: *value = configuration->mMaxPBufferPixels; break;
case EGL_MAX_PBUFFER_HEIGHT: *value = configuration->mMaxPBufferHeight; break; default:
case EGL_MAX_PBUFFER_PIXELS: *value = configuration->mMaxPBufferPixels; break; return false;
default: }
return false;
} return true;
}
return true;
} EGLSurface Display::createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList)
{
EGLSurface Display::createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList) const Config *configuration = mConfigSet.get(config);
{
const Config *configuration = mConfigSet.get(config); if(attribList)
{
if(attribList) while(*attribList != EGL_NONE)
{ {
while(*attribList != EGL_NONE) switch (attribList[0])
{ {
switch (attribList[0]) case EGL_RENDER_BUFFER:
{ switch (attribList[1])
case EGL_RENDER_BUFFER: {
switch (attribList[1]) case EGL_BACK_BUFFER:
{ break;
case EGL_BACK_BUFFER: case EGL_SINGLE_BUFFER:
break; return error(EGL_BAD_MATCH, EGL_NO_SURFACE); // Rendering directly to front buffer not supported
case EGL_SINGLE_BUFFER: default:
return error(EGL_BAD_MATCH, EGL_NO_SURFACE); // Rendering directly to front buffer not supported return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
default: }
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); break;
} case EGL_VG_COLORSPACE:
break; return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
case EGL_VG_COLORSPACE: case EGL_VG_ALPHA_FORMAT:
return error(EGL_BAD_MATCH, EGL_NO_SURFACE); return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
case EGL_VG_ALPHA_FORMAT: default:
return error(EGL_BAD_MATCH, EGL_NO_SURFACE); return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
default: }
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
} attribList += 2;
}
attribList += 2; }
}
} if(hasExistingWindowSurface(window))
{
if(hasExistingWindowSurface(window)) return error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
{ }
return error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
} Surface *surface = new Surface(this, configuration, window);
Surface *surface = new Surface(this, configuration, window); if(!surface->initialize())
{
if(!surface->initialize()) delete surface;
{ return EGL_NO_SURFACE;
delete surface; }
return EGL_NO_SURFACE;
} mSurfaceSet.insert(surface);
mSurfaceSet.insert(surface); return success(surface);
}
return success(surface);
} EGLSurface Display::createOffscreenSurface(EGLConfig config, const EGLint *attribList)
{
EGLSurface Display::createOffscreenSurface(EGLConfig config, const EGLint *attribList) EGLint width = 0, height = 0;
{ EGLenum textureFormat = EGL_NO_TEXTURE;
EGLint width = 0, height = 0; EGLenum textureTarget = EGL_NO_TEXTURE;
EGLenum textureFormat = EGL_NO_TEXTURE; const Config *configuration = mConfigSet.get(config);
EGLenum textureTarget = EGL_NO_TEXTURE;
const Config *configuration = mConfigSet.get(config); if(attribList)
{
if(attribList) while(*attribList != EGL_NONE)
{ {
while(*attribList != EGL_NONE) switch (attribList[0])
{ {
switch (attribList[0]) case EGL_WIDTH:
{ width = attribList[1];
case EGL_WIDTH: break;
width = attribList[1]; case EGL_HEIGHT:
break; height = attribList[1];
case EGL_HEIGHT: break;
height = attribList[1]; case EGL_LARGEST_PBUFFER:
break; if(attribList[1] != EGL_FALSE)
case EGL_LARGEST_PBUFFER: UNIMPLEMENTED(); // FIXME
if(attribList[1] != EGL_FALSE) break;
UNIMPLEMENTED(); // FIXME case EGL_TEXTURE_FORMAT:
break; switch (attribList[1])
case EGL_TEXTURE_FORMAT: {
switch (attribList[1]) case EGL_NO_TEXTURE:
{ case EGL_TEXTURE_RGB:
case EGL_NO_TEXTURE: case EGL_TEXTURE_RGBA:
case EGL_TEXTURE_RGB: textureFormat = attribList[1];
case EGL_TEXTURE_RGBA: break;
textureFormat = attribList[1]; default:
break; return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
default: }
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); break;
} case EGL_TEXTURE_TARGET:
break; switch (attribList[1])
case EGL_TEXTURE_TARGET: {
switch (attribList[1]) case EGL_NO_TEXTURE:
{ case EGL_TEXTURE_2D:
case EGL_NO_TEXTURE: textureTarget = attribList[1];
case EGL_TEXTURE_2D: break;
textureTarget = attribList[1]; default:
break; return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
default: }
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); break;
} case EGL_MIPMAP_TEXTURE:
break; if(attribList[1] != EGL_FALSE)
case EGL_MIPMAP_TEXTURE: return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
if(attribList[1] != EGL_FALSE) break;
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); case EGL_VG_COLORSPACE:
break; return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
case EGL_VG_COLORSPACE: case EGL_VG_ALPHA_FORMAT:
return error(EGL_BAD_MATCH, EGL_NO_SURFACE); return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
case EGL_VG_ALPHA_FORMAT: default:
return error(EGL_BAD_MATCH, EGL_NO_SURFACE); return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
default: }
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
} attribList += 2;
}
attribList += 2; }
}
} if(width < 0 || height < 0)
{
if(width < 0 || height < 0) return error(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
{ }
return error(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
} if(width == 0 || height == 0)
{
if(width == 0 || height == 0) return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
{ }
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
} if((textureFormat != EGL_NO_TEXTURE && textureTarget == EGL_NO_TEXTURE) ||
(textureFormat == EGL_NO_TEXTURE && textureTarget != EGL_NO_TEXTURE))
if((textureFormat != EGL_NO_TEXTURE && textureTarget == EGL_NO_TEXTURE) || {
(textureFormat == EGL_NO_TEXTURE && textureTarget != EGL_NO_TEXTURE)) return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
{ }
return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
} if(!(configuration->mSurfaceType & EGL_PBUFFER_BIT))
{
if(!(configuration->mSurfaceType & EGL_PBUFFER_BIT)) return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
{ }
return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
} if((textureFormat == EGL_TEXTURE_RGB && configuration->mBindToTextureRGB != EGL_TRUE) ||
(textureFormat == EGL_TEXTURE_RGBA && configuration->mBindToTextureRGBA != EGL_TRUE))
if((textureFormat == EGL_TEXTURE_RGB && configuration->mBindToTextureRGB != EGL_TRUE) || {
(textureFormat == EGL_TEXTURE_RGBA && configuration->mBindToTextureRGBA != EGL_TRUE)) return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
{ }
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
} Surface *surface = new Surface(this, configuration, width, height, textureFormat, textureTarget);
Surface *surface = new Surface(this, configuration, width, height, textureFormat, textureTarget); if(!surface->initialize())
{
if(!surface->initialize()) delete surface;
{ return EGL_NO_SURFACE;
delete surface; }
return EGL_NO_SURFACE;
} mSurfaceSet.insert(surface);
mSurfaceSet.insert(surface); return success(surface);
}
return success(surface);
} EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *shareContext, EGLint clientVersion)
{
EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *shareContext, EGLint clientVersion) const egl::Config *config = mConfigSet.get(configHandle);
{ egl::Context *context = 0;
const egl::Config *config = mConfigSet.get(configHandle);
egl::Context *context = 0; if(clientVersion == 1 && config->mRenderableType & EGL_OPENGL_ES_BIT)
{
if(clientVersion == 1 && config->mRenderableType & EGL_OPENGL_ES_BIT) if(es1::createContext != 0)
{ {
if(es1::createContext != 0) context = es1::createContext(config, shareContext);
{ }
context = es1::createContext(config, shareContext); }
} else if(clientVersion == 2 && config->mRenderableType & EGL_OPENGL_ES2_BIT)
} {
else if(clientVersion == 2 && config->mRenderableType & EGL_OPENGL_ES2_BIT) if(es2::createContext != 0)
{ {
if(es2::createContext != 0) context = es2::createContext(config, shareContext);
{ }
context = es2::createContext(config, shareContext); }
} else
} {
else return error(EGL_BAD_CONFIG, EGL_NO_CONTEXT);
{ }
return error(EGL_BAD_CONFIG, EGL_NO_CONTEXT);
} if(!context)
{
if(!context) return error(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
{ }
return error(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
} mContextSet.insert(context);
mContextSet.insert(context); return success(context);;
}
return success(context);;
} void Display::destroySurface(egl::Surface *surface)
{
void Display::destroySurface(egl::Surface *surface) delete surface;
{ mSurfaceSet.erase(surface);
delete surface; }
mSurfaceSet.erase(surface);
} void Display::destroyContext(egl::Context *context)
{
void Display::destroyContext(egl::Context *context) context->destroy();
{ mContextSet.erase(context);
context->destroy(); }
mContextSet.erase(context);
} bool Display::isInitialized() const
{
bool Display::isInitialized() const return mConfigSet.size() > 0;
{ }
return mConfigSet.size() > 0;
} bool Display::isValidConfig(EGLConfig config)
{
bool Display::isValidConfig(EGLConfig config) return mConfigSet.get(config) != NULL;
{ }
return mConfigSet.get(config) != NULL;
} bool Display::isValidContext(egl::Context *context)
{
bool Display::isValidContext(egl::Context *context) return mContextSet.find(context) != mContextSet.end();
{ }
return mContextSet.find(context) != mContextSet.end();
} bool Display::isValidSurface(egl::Surface *surface)
{
bool Display::isValidSurface(egl::Surface *surface) return mSurfaceSet.find(surface) != mSurfaceSet.end();
{ }
return mSurfaceSet.find(surface) != mSurfaceSet.end();
} bool Display::isValidWindow(EGLNativeWindowType window)
{
bool Display::isValidWindow(EGLNativeWindowType window) #if defined(_WIN32)
{ return IsWindow(window) == TRUE;
#if defined(_WIN32) #else
return IsWindow(window) == TRUE; XWindowAttributes windowAttributes;
#else Status status = XGetWindowAttributes(displayId, window, &windowAttributes);
XWindowAttributes windowAttributes;
Status status = XGetWindowAttributes(displayId, window, &windowAttributes); return status == True;
#endif
return status == True; }
#endif
} bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
{
bool Display::hasExistingWindowSurface(EGLNativeWindowType window) for(SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++)
{ {
for(SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) if((*surface)->getWindowHandle() == window)
{ {
if((*surface)->getWindowHandle() == window) return true;
{ }
return true; }
}
} return false;
}
return false;
} EGLint Display::getMinSwapInterval()
{
EGLint Display::getMinSwapInterval() return mMinSwapInterval;
{ }
return mMinSwapInterval;
} EGLint Display::getMaxSwapInterval()
{
EGLint Display::getMaxSwapInterval() return mMaxSwapInterval;
{ }
return mMaxSwapInterval;
} EGLNativeDisplayType Display::getNativeDisplay() const
{
EGLNativeDisplayType Display::getNativeDisplay() const return displayId;
{ }
return displayId;
} DisplayMode Display::getDisplayMode() const
{
DisplayMode Display::getDisplayMode() const DisplayMode displayMode = {0};
{
DisplayMode displayMode = {0}; #if defined(_WIN32)
HDC deviceContext = GetDC(0);
#if defined(_WIN32)
HDC deviceContext = GetDC(0); displayMode.width = ::GetDeviceCaps(deviceContext, HORZRES);
displayMode.height = ::GetDeviceCaps(deviceContext, VERTRES);
displayMode.width = ::GetDeviceCaps(deviceContext, HORZRES); unsigned int bpp = ::GetDeviceCaps(deviceContext, BITSPIXEL);
displayMode.height = ::GetDeviceCaps(deviceContext, VERTRES);
unsigned int bpp = ::GetDeviceCaps(deviceContext, BITSPIXEL); switch(bpp)
{
switch(bpp) case 32: displayMode.format = sw::FORMAT_X8R8G8B8; break;
{ case 24: displayMode.format = sw::FORMAT_R8G8B8; break;
case 32: displayMode.format = sw::FORMAT_X8R8G8B8; break; case 16: displayMode.format = sw::FORMAT_R5G6B5; break;
case 24: displayMode.format = sw::FORMAT_R8G8B8; break; default:
case 16: displayMode.format = sw::FORMAT_R5G6B5; break; ASSERT(false); // Unexpected display mode color depth
default: }
ASSERT(false); // Unexpected display mode color depth
} ReleaseDC(0, deviceContext);
#else
ReleaseDC(0, deviceContext); Screen *screen = XDefaultScreenOfDisplay(displayId);
#else displayMode.width = XWidthOfScreen(screen);
Screen *screen = XDefaultScreenOfDisplay(displayId); displayMode.height = XHeightOfScreen(screen);
displayMode.width = XWidthOfScreen(screen); unsigned int bpp = XPlanesOfScreen(screen);
displayMode.height = XHeightOfScreen(screen);
unsigned int bpp = XPlanesOfScreen(screen); switch(bpp)
{
switch(bpp) case 32: displayMode.format = sw::FORMAT_X8R8G8B8; break;
{ case 24: displayMode.format = sw::FORMAT_R8G8B8; break;
case 32: displayMode.format = sw::FORMAT_X8R8G8B8; break; case 16: displayMode.format = sw::FORMAT_R5G6B5; break;
case 24: displayMode.format = sw::FORMAT_R8G8B8; break; default:
case 16: displayMode.format = sw::FORMAT_R5G6B5; break; ASSERT(false); // Unexpected display mode color depth
default: }
ASSERT(false); // Unexpected display mode color depth #endif
}
#endif return displayMode;
}
return displayMode;
} }
\ No newline at end of file
}
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
</Target> </Target>
</Build> </Build>
<Compiler> <Compiler>
<Add option="-std=c++11" />
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
<Add directory="./../include/" /> <Add directory="./../include/" />
......
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
</Target> </Target>
</Build> </Build>
<Compiler> <Compiler>
<Add option="-std=c++11" />
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
<Add option="-fno-operator-names" /> <Add option="-fno-operator-names" />
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
</Target> </Target>
</Build> </Build>
<Compiler> <Compiler>
<Add option="-std=c++11" />
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
<Add directory="../../../../../Builds/Include" /> <Add directory="../../../../../Builds/Include" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment