Hash :
5ade8459
Author :
Date :
2015-09-02T11:00:30
Properly check for EGL_KHR_create_context before creating ES3 context. Mark EGL_KHR_create_context as supported in the DisplayGLs. BUG=angleproject:1149 Change-Id: I20671535680eb2c3b9c08205cee243b3aa5c5821 Reviewed-on: https://chromium-review.googlesource.com/297080 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Tested-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
//
// Copyright (c) 2015 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.
//
// DisplayGLX.cpp: GLX implementation of egl::Display
#include "libANGLE/renderer/gl/glx/DisplayGLX.h"
#include <EGL/eglext.h>
#include <algorithm>
#include "common/debug.h"
#include "libANGLE/Config.h"
#include "libANGLE/Display.h"
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/gl/glx/PbufferSurfaceGLX.h"
#include "libANGLE/renderer/gl/glx/WindowSurfaceGLX.h"
namespace rx
{
class FunctionsGLGLX : public FunctionsGL
{
public:
FunctionsGLGLX(PFNGETPROCPROC getProc)
: mGetProc(getProc)
{
}
virtual ~FunctionsGLGLX()
{
}
private:
void *loadProcAddress(const std::string &function) override
{
return reinterpret_cast<void*>(mGetProc(function.c_str()));
}
PFNGETPROCPROC mGetProc;
};
DisplayGLX::DisplayGLX()
: DisplayGL(),
mFunctionsGL(nullptr),
mContextConfig(nullptr),
mContext(nullptr),
mDummyPbuffer(0),
mUsesNewXDisplay(false),
mEGLDisplay(nullptr)
{
}
DisplayGLX::~DisplayGLX()
{
}
egl::Error DisplayGLX::initialize(egl::Display *display)
{
mEGLDisplay = display;
Display *xDisplay = display->getNativeDisplayId();
// ANGLE_platform_angle allows the creation of a default display
// using EGL_DEFAULT_DISPLAY (= nullptr). In this case just open
// the display specified by the DISPLAY environment variable.
if (xDisplay == EGL_DEFAULT_DISPLAY)
{
mUsesNewXDisplay = true;
xDisplay = XOpenDisplay(NULL);
if (!xDisplay)
{
return egl::Error(EGL_NOT_INITIALIZED, "Could not open the default X display.");
}
}
std::string glxInitError;
if (!mGLX.initialize(xDisplay, DefaultScreen(xDisplay), &glxInitError))
{
return egl::Error(EGL_NOT_INITIALIZED, glxInitError.c_str());
}
// Check we have the needed extensions
{
if (mGLX.minorVersion == 3 && !mGLX.hasExtension("GLX_ARB_multisample"))
{
return egl::Error(EGL_NOT_INITIALIZED, "GLX doesn't support ARB_multisample.");
}
// Require ARB_create_context which has been supported since Mesa 9 unconditionnaly
// and is present in Mesa 8 in an almost always on compile flag. Also assume proprietary
// drivers have it.
if (!mGLX.hasExtension("GLX_ARB_create_context"))
{
return egl::Error(EGL_NOT_INITIALIZED, "GLX doesn't support ARB_create_context.");
}
}
// When glXMakeCurrent is called, the context and the surface must be
// compatible which in glX-speak means that their config have the same
// color buffer type, are both RGBA or ColorIndex, and their buffers have
// the same depth, if they exist.
// Since our whole EGL implementation is backed by only one GL context, this
// context must be compatible with all the GLXFBConfig corresponding to the
// EGLconfigs that we will be exposing.
{
int nConfigs;
int attribList[] =
{
// We want RGBA8 and DEPTH24_STENCIL8
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_ALPHA_SIZE, 8,
GLX_DEPTH_SIZE, 24,
GLX_STENCIL_SIZE, 8,
// We want RGBA rendering (vs COLOR_INDEX) and doublebuffer
GLX_RENDER_TYPE, GLX_RGBA_BIT,
// Double buffer is not strictly required as a non-doublebuffer
// context can work with a doublebuffered surface, but it still
// flickers and all applications want doublebuffer anyway.
GLX_DOUBLEBUFFER, True,
// All of these must be supported for full EGL support
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PBUFFER_BIT | GLX_PIXMAP_BIT,
// This makes sure the config have an associated visual Id
GLX_X_RENDERABLE, True,
GLX_CONFIG_CAVEAT, GLX_NONE,
None
};
glx::FBConfig* candidates = mGLX.chooseFBConfig(attribList, &nConfigs);
if (nConfigs == 0)
{
XFree(candidates);
return egl::Error(EGL_NOT_INITIALIZED, "Could not find a decent GLX FBConfig to create the context.");
}
mContextConfig = candidates[0];
XFree(candidates);
}
mContext = mGLX.createContextAttribsARB(mContextConfig, nullptr, True, nullptr);
if (!mContext)
{
return egl::Error(EGL_NOT_INITIALIZED, "Could not create GL context.");
}
// FunctionsGL and DisplayGL need to make a few GL calls, for example to
// query the version of the context so we need to make the context current.
// glXMakeCurrent requires a GLXDrawable so we create a temporary Pbuffer
// (of size 0, 0) for the duration of these calls.
// to query things like limits. Ideally we would want to unset the current context
// and destroy the pbuffer before going back to the application but this is TODO
mDummyPbuffer = mGLX.createPbuffer(mContextConfig, nullptr);
if (!mDummyPbuffer)
{
return egl::Error(EGL_NOT_INITIALIZED, "Could not create the dummy pbuffer.");
}
if (!mGLX.makeCurrent(mDummyPbuffer, mContext))
{
return egl::Error(EGL_NOT_INITIALIZED, "Could not make the dummy pbuffer current.");
}
mFunctionsGL = new FunctionsGLGLX(mGLX.getProc);
mFunctionsGL->initialize();
syncXCommands();
return DisplayGL::initialize(display);
}
void DisplayGLX::terminate()
{
DisplayGL::terminate();
if (mDummyPbuffer)
{
mGLX.destroyPbuffer(mDummyPbuffer);
mDummyPbuffer = 0;
}
if (mContext)
{
mGLX.destroyContext(mContext);
mContext = nullptr;
}
mGLX.terminate();
SafeDelete(mFunctionsGL);
}
SurfaceImpl *DisplayGLX::createWindowSurface(const egl::Config *configuration,
EGLNativeWindowType window,
const egl::AttributeMap &attribs)
{
ASSERT(configIdToGLXConfig.count(configuration->configID) > 0);
glx::FBConfig fbConfig = configIdToGLXConfig[configuration->configID];
return new WindowSurfaceGLX(mGLX, this, this->getRenderer(), window, mGLX.getDisplay(),
mContext, fbConfig);
}
SurfaceImpl *DisplayGLX::createPbufferSurface(const egl::Config *configuration,
const egl::AttributeMap &attribs)
{
ASSERT(configIdToGLXConfig.count(configuration->configID) > 0);
glx::FBConfig fbConfig = configIdToGLXConfig[configuration->configID];
EGLint width = attribs.get(EGL_WIDTH, 0);
EGLint height = attribs.get(EGL_HEIGHT, 0);
bool largest = (attribs.get(EGL_LARGEST_PBUFFER, EGL_FALSE) == EGL_TRUE);
return new PbufferSurfaceGLX(this->getRenderer(), width, height, largest, mGLX, mContext,
fbConfig);
}
SurfaceImpl* DisplayGLX::createPbufferFromClientBuffer(const egl::Config *configuration,
EGLClientBuffer shareHandle,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return nullptr;
}
SurfaceImpl *DisplayGLX::createPixmapSurface(const egl::Config *configuration,
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs)
{
UNIMPLEMENTED();
return nullptr;
}
egl::Error DisplayGLX::getDevice(DeviceImpl **device)
{
UNIMPLEMENTED();
return egl::Error(EGL_BAD_DISPLAY);
}
egl::ConfigSet DisplayGLX::generateConfigs() const
{
egl::ConfigSet configs;
configIdToGLXConfig.clear();
bool hasSwapControl = mGLX.hasExtension("GLX_EXT_swap_control");
int contextSamples = getGLXFBConfigAttrib(mContextConfig, GLX_SAMPLES);
int contextSampleBuffers = getGLXFBConfigAttrib(mContextConfig, GLX_SAMPLE_BUFFERS);
int contextAccumRedSize = getGLXFBConfigAttrib(mContextConfig, GLX_ACCUM_RED_SIZE);
int contextAccumGreenSize = getGLXFBConfigAttrib(mContextConfig, GLX_ACCUM_GREEN_SIZE);
int contextAccumBlueSize = getGLXFBConfigAttrib(mContextConfig, GLX_ACCUM_BLUE_SIZE);
int contextAccumAlphaSize = getGLXFBConfigAttrib(mContextConfig, GLX_ACCUM_ALPHA_SIZE);
int attribList[] =
{
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_X_RENDERABLE, True,
GLX_DOUBLEBUFFER, True,
None,
};
int glxConfigCount;
glx::FBConfig *glxConfigs = mGLX.chooseFBConfig(attribList, &glxConfigCount);
for (int i = 0; i < glxConfigCount; i++)
{
glx::FBConfig glxConfig = glxConfigs[i];
egl::Config config;
// Native stuff
config.nativeVisualID = getGLXFBConfigAttrib(glxConfig, GLX_VISUAL_ID);
config.nativeVisualType = getGLXFBConfigAttrib(glxConfig, GLX_X_VISUAL_TYPE);
config.nativeRenderable = EGL_TRUE;
// Buffer sizes
config.redSize = getGLXFBConfigAttrib(glxConfig, GLX_RED_SIZE);
config.greenSize = getGLXFBConfigAttrib(glxConfig, GLX_GREEN_SIZE);
config.blueSize = getGLXFBConfigAttrib(glxConfig, GLX_BLUE_SIZE);
config.alphaSize = getGLXFBConfigAttrib(glxConfig, GLX_ALPHA_SIZE);
config.depthSize = getGLXFBConfigAttrib(glxConfig, GLX_DEPTH_SIZE);
config.stencilSize = getGLXFBConfigAttrib(glxConfig, GLX_STENCIL_SIZE);
// We require RGBA8 and the D24S8 (or no DS buffer)
if (config.redSize != 8 || config.greenSize != 8 || config.blueSize != 8 || config.alphaSize != 8)
{
continue;
}
if (!(config.depthSize == 24 && config.stencilSize == 8) && !(config.depthSize == 0 && config.stencilSize == 0))
{
continue;
}
config.colorBufferType = EGL_RGB_BUFFER;
config.luminanceSize = 0;
config.alphaMaskSize = 0;
config.bufferSize = config.redSize + config.greenSize + config.blueSize + config.alphaSize;
// Multisample and accumulation buffers
int samples = getGLXFBConfigAttrib(glxConfig, GLX_SAMPLES);
int sampleBuffers = getGLXFBConfigAttrib(glxConfig, GLX_SAMPLE_BUFFERS);
int accumRedSize = getGLXFBConfigAttrib(glxConfig, GLX_ACCUM_RED_SIZE);
int accumGreenSize = getGLXFBConfigAttrib(glxConfig, GLX_ACCUM_GREEN_SIZE);
int accumBlueSize = getGLXFBConfigAttrib(glxConfig, GLX_ACCUM_BLUE_SIZE);
int accumAlphaSize = getGLXFBConfigAttrib(glxConfig, GLX_ACCUM_ALPHA_SIZE);
if (samples != contextSamples ||
sampleBuffers != contextSampleBuffers ||
accumRedSize != contextAccumRedSize ||
accumGreenSize != contextAccumGreenSize ||
accumBlueSize != contextAccumBlueSize ||
accumAlphaSize != contextAccumAlphaSize)
{
continue;
}
config.samples = samples;
config.sampleBuffers = sampleBuffers;
// Transparency
if (getGLXFBConfigAttrib(glxConfig, GLX_TRANSPARENT_TYPE) == GLX_TRANSPARENT_RGB)
{
config.transparentType = EGL_TRANSPARENT_RGB;
config.transparentRedValue = getGLXFBConfigAttrib(glxConfig, GLX_TRANSPARENT_RED_VALUE);
config.transparentGreenValue = getGLXFBConfigAttrib(glxConfig, GLX_TRANSPARENT_GREEN_VALUE);
config.transparentBlueValue = getGLXFBConfigAttrib(glxConfig, GLX_TRANSPARENT_BLUE_VALUE);
}
else
{
config.transparentType = EGL_NONE;
}
// Pbuffer
config.maxPBufferWidth = getGLXFBConfigAttrib(glxConfig, GLX_MAX_PBUFFER_WIDTH);
config.maxPBufferHeight = getGLXFBConfigAttrib(glxConfig, GLX_MAX_PBUFFER_HEIGHT);
config.maxPBufferPixels = getGLXFBConfigAttrib(glxConfig, GLX_MAX_PBUFFER_PIXELS);
// Caveat
config.configCaveat = EGL_NONE;
int caveat = getGLXFBConfigAttrib(glxConfig, GLX_CONFIG_CAVEAT);
if (caveat == GLX_SLOW_CONFIG)
{
config.configCaveat = EGL_SLOW_CONFIG;
}
else if (caveat == GLX_NON_CONFORMANT_CONFIG)
{
continue;
}
// Misc
config.level = getGLXFBConfigAttrib(glxConfig, GLX_LEVEL);
config.bindToTextureRGB = EGL_FALSE;
config.bindToTextureRGBA = EGL_FALSE;
int glxDrawable = getGLXFBConfigAttrib(glxConfig, GLX_DRAWABLE_TYPE);
config.surfaceType = 0 |
(glxDrawable & GLX_WINDOW_BIT ? EGL_WINDOW_BIT : 0) |
(glxDrawable & GLX_PBUFFER_BIT ? EGL_PBUFFER_BIT : 0) |
(glxDrawable & GLX_PIXMAP_BIT ? EGL_PIXMAP_BIT : 0);
if (hasSwapControl)
{
// In GLX_EXT_swap_control querying these is done on a GLXWindow so we just set a default value.
config.minSwapInterval = 0;
config.maxSwapInterval = 4;
}
else
{
config.minSwapInterval = 1;
config.maxSwapInterval = 1;
}
// TODO(cwallez) wildly guessing these formats, another TODO says they should be removed anyway
config.renderTargetFormat = GL_RGBA8;
config.depthStencilFormat = GL_DEPTH24_STENCIL8;
// TODO(cwallez) Fill after determining the GL version we are using and what ES version it supports
config.conformant = EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR;
config.renderableType = EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR;
// TODO(cwallez) I have no idea what this is
config.matchNativePixmap = EGL_NONE;
int id = configs.add(config);
configIdToGLXConfig[id] = glxConfig;
}
XFree(glxConfigs);
return configs;
}
bool DisplayGLX::isDeviceLost() const
{
// UNIMPLEMENTED();
return false;
}
bool DisplayGLX::testDeviceLost()
{
// UNIMPLEMENTED();
return false;
}
egl::Error DisplayGLX::restoreLostDevice()
{
UNIMPLEMENTED();
return egl::Error(EGL_BAD_DISPLAY);
}
bool DisplayGLX::isValidNativeWindow(EGLNativeWindowType window) const
{
// There is no function in Xlib to check the validity of a Window directly.
// However a small number of functions used to obtain window information
// return a status code (0 meaning failure) and guarantee that they will
// fail if the window doesn't exist (the rational is that these function
// are used by window managers). Out of these function we use XQueryTree
// as it seems to be the simplest; a drawback is that it will allocate
// memory for the list of children, becasue we use a child window for
// WindowSurface.
Window root;
Window parent;
Window *children = nullptr;
unsigned nChildren;
int status = XQueryTree(mGLX.getDisplay(), window, &root, &parent, &children, &nChildren);
if (children)
{
XFree(children);
}
return status != 0;
}
std::string DisplayGLX::getVendorString() const
{
// UNIMPLEMENTED();
return "";
}
void DisplayGLX::syncXCommands() const
{
if (mUsesNewXDisplay)
{
XSync(mGLX.getDisplay(), False);
}
}
const FunctionsGL *DisplayGLX::getFunctionsGL() const
{
return mFunctionsGL;
}
void DisplayGLX::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
outExtensions->createContext = true;
}
void DisplayGLX::generateCaps(egl::Caps *outCaps) const
{
// UNIMPLEMENTED();
outCaps->textureNPOT = true;
}
int DisplayGLX::getGLXFBConfigAttrib(glx::FBConfig config, int attrib) const
{
int result;
mGLX.getFBConfigAttrib(config, attrib, &result);
return result;
}
}