//
-// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include <algorithm>
#include <map>
#include <vector>
+#include <sstream>
#include "common/debug.h"
#include "common/mathutil.h"
namespace egl
{
-namespace
+
+typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
+static DisplayMap *GetDisplayMap()
{
- typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
- DisplayMap displays;
+ static DisplayMap displays;
+ return &displays;
}
-egl::Display *Display::getDisplay(EGLNativeDisplayType displayId)
+egl::Display *Display::getDisplay(EGLNativeDisplayType displayId, EGLint displayType)
{
- if (displays.find(displayId) != displays.end())
+ DisplayMap *displays = GetDisplayMap();
+ DisplayMap::const_iterator iter = displays->find(displayId);
+ if (iter != displays->end())
{
- return displays[displayId];
+ return iter->second;
}
// FIXME: Check if displayId is a valid display device context
- egl::Display *display = new egl::Display(displayId, (HDC)displayId);
+ egl::Display *display = new egl::Display(displayId, displayType);
+ displays->insert(std::make_pair(displayId, display));
- displays[displayId] = display;
return display;
}
-Display::Display(EGLNativeDisplayType displayId, HDC deviceContext) : mDc(deviceContext)
+Display::Display(EGLNativeDisplayType displayId, EGLint displayType)
+ : mDisplayId(displayId),
+ mRequestedDisplayType(displayType),
+ mRenderer(NULL)
{
- mDisplayId = displayId;
- mRenderer = NULL;
}
Display::~Display()
{
terminate();
- DisplayMap::iterator thisDisplay = displays.find(mDisplayId);
-
- if (thisDisplay != displays.end())
+ DisplayMap *displays = GetDisplayMap();
+ DisplayMap::iterator iter = displays->find(mDisplayId);
+ if (iter != displays->end())
{
- displays.erase(thisDisplay);
+ displays->erase(iter);
}
}
return true;
}
- mRenderer = glCreateRenderer(this, mDc, mDisplayId);
-
+ mRenderer = glCreateRenderer(this, mDisplayId, mRequestedDisplayType);
+
if (!mRenderer)
{
terminate();
EGLint minSwapInterval = mRenderer->getMinSwapInterval();
EGLint maxSwapInterval = mRenderer->getMaxSwapInterval();
- EGLint maxTextureWidth = mRenderer->getMaxTextureWidth();
- EGLint maxTextureHeight = mRenderer->getMaxTextureHeight();
+ EGLint maxTextureSize = mRenderer->getRendererCaps().max2DTextureSize;
rx::ConfigDesc *descList;
int numConfigs = mRenderer->generateConfigs(&descList);
ConfigSet configSet;
for (int i = 0; i < numConfigs; ++i)
- configSet.add(descList[i], minSwapInterval, maxSwapInterval,
- maxTextureWidth, maxTextureHeight);
+ {
+ configSet.add(descList[i], minSwapInterval, maxSwapInterval, maxTextureSize, maxTextureSize);
+ }
// Give the sorted configs a unique ID and store them internally
EGLint index = 1;
return false;
}
- initExtensionString();
+ initDisplayExtensionString();
initVendorString();
return true;
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
}
- if (textureFormat != EGL_NO_TEXTURE && !mRenderer->getNonPower2TextureSupport() && (!gl::isPow2(width) || !gl::isPow2(height)))
+ if (textureFormat != EGL_NO_TEXTURE && !mRenderer->getRendererExtensions().textureNPOT && (!gl::isPow2(width) || !gl::isPow2(height)))
{
return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
}
return false;
}
-void Display::initExtensionString()
+std::string Display::generateClientExtensionString()
{
- bool shareHandleSupported = mRenderer->getShareHandleSupport();
+ std::vector<std::string> extensions;
- mExtensionString = "";
+ extensions.push_back("EGL_EXT_client_extensions");
- // Multi-vendor (EXT) extensions
- mExtensionString += "EGL_EXT_create_context_robustness ";
+ extensions.push_back("ANGLE_platform_angle");
- // ANGLE-specific extensions
- if (shareHandleSupported)
+ if (supportsPlatformD3D())
{
- mExtensionString += "EGL_ANGLE_d3d_share_handle_client_buffer ";
+ extensions.push_back("ANGLE_platform_angle_d3d");
}
- mExtensionString += "EGL_ANGLE_query_surface_pointer ";
+ if (supportsPlatformOpenGL())
+ {
+ extensions.push_back("ANGLE_platform_angle_opengl");
+ }
- mExtensionString += "EGL_ANGLE_window_fixed_size ";
+ std::ostringstream stream;
+ std::copy(extensions.begin(), extensions.end(), std::ostream_iterator<std::string>(stream, " "));
+ return stream.str();
+}
- if (shareHandleSupported)
+void Display::initDisplayExtensionString()
+{
+ std::vector<std::string> extensions;
+
+ // Multi-vendor (EXT) extensions
+ extensions.push_back("EGL_EXT_create_context_robustness");
+
+ // ANGLE-specific extensions
+ if (mRenderer->getShareHandleSupport())
{
- mExtensionString += "EGL_ANGLE_surface_d3d_texture_2d_share_handle ";
+ extensions.push_back("EGL_ANGLE_d3d_share_handle_client_buffer");
+ extensions.push_back("EGL_ANGLE_surface_d3d_texture_2d_share_handle");
}
+ extensions.push_back("EGL_ANGLE_query_surface_pointer");
+ extensions.push_back("EGL_ANGLE_window_fixed_size");
+
if (mRenderer->getPostSubBufferSupport())
{
- mExtensionString += "EGL_NV_post_sub_buffer ";
+ extensions.push_back("EGL_NV_post_sub_buffer");
}
// TODO: complete support for the EGL_KHR_create_context extension
- mExtensionString += "EGL_KHR_create_context ";
+ extensions.push_back("EGL_KHR_create_context");
- std::string::size_type end = mExtensionString.find_last_not_of(' ');
- if (end != std::string::npos)
+ std::ostringstream stream;
+ std::copy(extensions.begin(), extensions.end(), std::ostream_iterator<std::string>(stream, " "));
+ mDisplayExtensionString = stream.str();
+}
+
+const char *Display::getExtensionString(egl::Display *display)
+{
+ if (display != EGL_NO_DISPLAY)
+ {
+ return display->mDisplayExtensionString.c_str();
+ }
+ else
{
- mExtensionString.resize(end+1);
+ static std::string clientExtensions = generateClientExtensionString();
+ return clientExtensions.c_str();
}
}
-const char *Display::getExtensionString() const
+bool Display::supportsPlatformD3D()
{
- return mExtensionString.c_str();
+#if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool Display::supportsPlatformOpenGL()
+{
+ return false;
}
void Display::initVendorString()