Hash :
063d9e78
Author :
Date :
2015-11-19T17:24:47
Add support for EGL_EXT_platform_device This allows an application to use EGLDeviceEXT to initialize EGL. For example, if an application wants to initialize EGL using an existing D3D11 device (instead of ANGLE creating its D3D device), then the app may create an EGLDeviceEXT using EGL_ANGLE_device_creation_d3d11, and use this device to initialize EGL via EGL_EXT_platform_device. BUG=angleproject:1190 Change-Id: Ife91ce95a63e29eb2b3f05aedfb668e4cac8f5ce Reviewed-on: https://chromium-review.googlesource.com/313444 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Austin Kinross <aukinros@microsoft.com>
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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
//
// Copyright(c) 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.
//
// entry_points_ext.cpp : Implements the EGL extension entry points.
#include "libGLESv2/entry_points_egl_ext.h"
#include "libGLESv2/global_state.h"
#include "libANGLE/Display.h"
#include "libANGLE/Device.h"
#include "libANGLE/Surface.h"
#include "libANGLE/validationEGL.h"
#include "common/debug.h"
namespace egl
{
// EGL_ANGLE_query_surface_pointer
EGLBoolean EGLAPIENTRY QuerySurfacePointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, void **value = 0x%0.8p)",
dpy, surface, attribute, value);
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = static_cast<Surface*>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (!display->getExtensions().querySurfacePointer)
{
SetGlobalError(Error(EGL_SUCCESS));
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE)
{
SetGlobalError(Error(EGL_BAD_SURFACE));
return EGL_FALSE;
}
// validate the attribute parameter
switch (attribute)
{
case EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE:
if (!display->getExtensions().surfaceD3DTexture2DShareHandle)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
break;
case EGL_DXGI_KEYED_MUTEX_ANGLE:
if (!display->getExtensions().keyedMutex)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
break;
default:
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
error = eglSurface->querySurfacePointerANGLE(attribute, value);
SetGlobalError(error);
return (error.isError() ? EGL_FALSE : EGL_TRUE);
}
// EGL_NV_post_sub_buffer
EGLBoolean EGLAPIENTRY PostSubBufferNV(EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint x = %d, EGLint y = %d, EGLint width = %d, EGLint height = %d)", dpy, surface, x, y, width, height);
if (x < 0 || y < 0 || width < 0 || height < 0)
{
SetGlobalError(Error(EGL_BAD_PARAMETER));
return EGL_FALSE;
}
Display *display = static_cast<Display*>(dpy);
Surface *eglSurface = static_cast<Surface*>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
if (display->isDeviceLost())
{
SetGlobalError(Error(EGL_CONTEXT_LOST));
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE)
{
SetGlobalError(Error(EGL_BAD_SURFACE));
return EGL_FALSE;
}
if (!display->getExtensions().postSubBuffer)
{
// Spec is not clear about how this should be handled.
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
error = eglSurface->postSubBuffer(x, y, width, height);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
SetGlobalError(Error(EGL_SUCCESS));
return EGL_TRUE;
}
// EGL_EXT_platform_base
EGLDisplay EGLAPIENTRY GetPlatformDisplayEXT(EGLenum platform, void *native_display, const EGLint *attrib_list)
{
EVENT("(EGLenum platform = %d, void* native_display = 0x%0.8p, const EGLint* attrib_list = 0x%0.8p)",
platform, native_display, attrib_list);
const ClientExtensions &clientExtensions = Display::getClientExtensions();
switch (platform)
{
case EGL_PLATFORM_ANGLE_ANGLE:
if (!clientExtensions.platformANGLE)
{
SetGlobalError(Error(EGL_BAD_PARAMETER));
return EGL_NO_DISPLAY;
}
break;
case EGL_PLATFORM_DEVICE_EXT:
if (!clientExtensions.platformDevice)
{
SetGlobalError(Error(EGL_BAD_PARAMETER, "Platform Device extension is not active"));
return EGL_NO_DISPLAY;
}
break;
default:
SetGlobalError(Error(EGL_BAD_CONFIG));
return EGL_NO_DISPLAY;
}
if (platform == EGL_PLATFORM_ANGLE_ANGLE)
{
EGLint platformType = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
EGLint deviceType = EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE;
bool majorVersionSpecified = false;
bool minorVersionSpecified = false;
bool enableAutoTrimSpecified = false;
bool deviceTypeSpecified = false;
if (attrib_list)
{
for (const EGLint *curAttrib = attrib_list; curAttrib[0] != EGL_NONE; curAttrib += 2)
{
switch (curAttrib[0])
{
case EGL_PLATFORM_ANGLE_TYPE_ANGLE:
switch (curAttrib[1])
{
case EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE:
break;
case EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE:
case EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE:
if (!clientExtensions.platformANGLED3D)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_NO_DISPLAY;
}
break;
case EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE:
case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE:
if (!clientExtensions.platformANGLEOpenGL)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_NO_DISPLAY;
}
break;
default:
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_NO_DISPLAY;
}
platformType = curAttrib[1];
break;
case EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE:
if (curAttrib[1] != EGL_DONT_CARE)
{
majorVersionSpecified = true;
}
break;
case EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE:
if (curAttrib[1] != EGL_DONT_CARE)
{
minorVersionSpecified = true;
}
break;
case EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE:
switch (curAttrib[1])
{
case EGL_TRUE:
case EGL_FALSE:
break;
default:
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_NO_DISPLAY;
}
enableAutoTrimSpecified = true;
break;
case EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE:
switch (curAttrib[1])
{
case EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE:
case EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE:
case EGL_PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE:
deviceTypeSpecified = true;
break;
case EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE:
// This is a hidden option, accepted by the OpenGL back-end.
break;
default:
SetGlobalError(Error(EGL_BAD_ATTRIBUTE,
"Invalid value for "
"EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE "
"attrib"));
return EGL_NO_DISPLAY;
}
deviceType = curAttrib[1];
break;
default:
break;
}
}
}
if (!majorVersionSpecified && minorVersionSpecified)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_NO_DISPLAY;
}
if (deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE &&
platformType != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
{
SetGlobalError(
Error(EGL_BAD_ATTRIBUTE,
"EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE requires a device type of "
"EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE."));
return EGL_NO_DISPLAY;
}
if (enableAutoTrimSpecified && platformType != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
{
SetGlobalError(
Error(EGL_BAD_ATTRIBUTE,
"EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE requires a device type of "
"EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE."));
return EGL_NO_DISPLAY;
}
if (deviceTypeSpecified && platformType != EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE &&
platformType != EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
{
SetGlobalError(
Error(EGL_BAD_ATTRIBUTE,
"EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE requires a device type of "
"EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE or EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE."));
return EGL_NO_DISPLAY;
}
SetGlobalError(Error(EGL_SUCCESS));
return Display::GetDisplayFromAttribs(native_display, AttributeMap(attrib_list));
}
else if (platform == EGL_PLATFORM_DEVICE_EXT)
{
Device *eglDevice = reinterpret_cast<Device *>(native_display);
if (eglDevice == nullptr || !Device::IsValidDevice(eglDevice))
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE,
"native_display should be a valid EGL device if platform equals "
"EGL_PLATFORM_DEVICE_EXT"));
return EGL_NO_DISPLAY;
}
SetGlobalError(Error(EGL_SUCCESS));
return Display::GetDisplayFromDevice(native_display);
}
else
{
UNREACHABLE();
return EGL_NO_DISPLAY;
}
}
// EGL_EXT_device_query
EGLBoolean EGLAPIENTRY QueryDeviceAttribEXT(EGLDeviceEXT device, EGLint attribute, EGLAttrib *value)
{
EVENT("(EGLDeviceEXT device = 0x%0.8p, EGLint attribute = %d, EGLAttrib *value = 0x%0.8p)",
device, attribute, value);
Device *dev = static_cast<Device*>(device);
if (dev == EGL_NO_DEVICE_EXT || !Device::IsValidDevice(dev))
{
SetGlobalError(Error(EGL_BAD_ACCESS));
return EGL_FALSE;
}
// If the device was created by (and is owned by) a display, and that display doesn't support
// device querying, then this call should fail
Display *owningDisplay = dev->getOwningDisplay();
if (owningDisplay != nullptr && !owningDisplay->getExtensions().deviceQuery)
{
SetGlobalError(Error(EGL_BAD_ACCESS,
"Device wasn't created using eglCreateDeviceANGLE, and the Display "
"that created it doesn't support device querying"));
return EGL_FALSE;
}
Error error(EGL_SUCCESS);
// validate the attribute parameter
switch (attribute)
{
case EGL_D3D11_DEVICE_ANGLE:
case EGL_D3D9_DEVICE_ANGLE:
if (!dev->getExtensions().deviceD3D || dev->getType() != attribute)
{
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
error = dev->getDevice(value);
break;
default:
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
SetGlobalError(error);
return (error.isError() ? EGL_FALSE : EGL_TRUE);
}
// EGL_EXT_device_query
const char * EGLAPIENTRY QueryDeviceStringEXT(EGLDeviceEXT device, EGLint name)
{
EVENT("(EGLDeviceEXT device = 0x%0.8p, EGLint name = %d)",
device, name);
Device *dev = static_cast<Device*>(device);
if (dev == EGL_NO_DEVICE_EXT || !Device::IsValidDevice(dev))
{
SetGlobalError(Error(EGL_BAD_DEVICE_EXT));
return nullptr;
}
const char *result;
switch (name)
{
case EGL_EXTENSIONS:
result = dev->getExtensionString().c_str();
break;
default:
SetGlobalError(Error(EGL_BAD_DEVICE_EXT));
return nullptr;
}
SetGlobalError(Error(EGL_SUCCESS));
return result;
}
// EGL_EXT_device_query
EGLBoolean EGLAPIENTRY QueryDisplayAttribEXT(EGLDisplay dpy, EGLint attribute, EGLAttrib *value)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint attribute = %d, EGLAttrib *value = 0x%0.8p)",
dpy, attribute, value);
Display *display = static_cast<Display*>(dpy);
Error error(EGL_SUCCESS);
if (!display->getExtensions().deviceQuery)
{
SetGlobalError(Error(EGL_BAD_ACCESS));
return EGL_FALSE;
}
// validate the attribute parameter
switch (attribute)
{
case EGL_DEVICE_EXT:
*value = reinterpret_cast<EGLAttrib>(display->getDevice());
break;
default:
SetGlobalError(Error(EGL_BAD_ATTRIBUTE));
return EGL_FALSE;
}
SetGlobalError(error);
return (error.isError() ? EGL_FALSE : EGL_TRUE);
}
ANGLE_EXPORT EGLImageKHR EGLAPIENTRY CreateImageKHR(EGLDisplay dpy,
EGLContext ctx,
EGLenum target,
EGLClientBuffer buffer,
const EGLint *attrib_list)
{
EVENT(
"(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p, EGLenum target = 0x%X, "
"EGLClientBuffer buffer = 0x%0.8p, const EGLAttrib *attrib_list = 0x%0.8p)",
dpy, ctx, target, buffer, attrib_list);
Display *display = static_cast<Display *>(dpy);
gl::Context *context = static_cast<gl::Context *>(ctx);
AttributeMap attributes(attrib_list);
Error error = ValidateCreateImageKHR(display, context, target, buffer, attributes);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_IMAGE;
}
Image *image = nullptr;
error = display->createImage(context, target, buffer, attributes, &image);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_IMAGE;
}
return static_cast<EGLImage>(image);
}
ANGLE_EXPORT EGLBoolean EGLAPIENTRY DestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
{
EVENT("(EGLDisplay dpy = 0x%0.8p, EGLImage image = 0x%0.8p)", dpy, image);
Display *display = static_cast<Display *>(dpy);
Image *img = static_cast<Image *>(image);
Error error = ValidateDestroyImageKHR(display, img);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
display->destroyImage(img);
return EGL_TRUE;
}
ANGLE_EXPORT EGLDeviceEXT EGLAPIENTRY CreateDeviceANGLE(EGLint device_type,
void *native_device,
const EGLAttrib *attrib_list)
{
EVENT(
"(EGLint device_type = %d, void* native_device = 0x%0.8p, const EGLAttrib* attrib_list = "
"0x%0.8p)",
device_type, native_device, attrib_list);
Error error = ValidateCreateDeviceANGLE(device_type, native_device, attrib_list);
if (error.isError())
{
SetGlobalError(error);
return EGL_NO_DEVICE_EXT;
}
Device *device = nullptr;
error = Device::CreateDevice(native_device, device_type, &device);
if (error.isError())
{
ASSERT(device == nullptr);
SetGlobalError(error);
return EGL_NO_DEVICE_EXT;
}
return device;
}
ANGLE_EXPORT EGLBoolean EGLAPIENTRY ReleaseDeviceANGLE(EGLDeviceEXT device)
{
EVENT("(EGLDeviceEXT device = 0x%0.8p)", device);
Device *dev = static_cast<Device *>(device);
Error error = ValidateReleaseDeviceANGLE(dev);
if (error.isError())
{
SetGlobalError(error);
return EGL_FALSE;
}
SafeDelete(dev);
return EGL_TRUE;
}
}