Hash :
ceffd20c
Author :
Date :
2018-01-08T16:39:45
Set colorspace of D3D pbuffers according to DXGI format When a EGL pbuffer is created based on a D3D SRGB texture using EGL_ANGLE_d3d_texture_client_buffer, SRGB conversions are performed as if it was an SRGB surface. The value of EGL_GL_COLORSPACE now reflects that correctly. If the pbuffer is bound to a texture and used as a framebuffer attachment, querying GL_FRAMEBUFFER_COLOR_ATTACHMENT also reflects that correctly. The behavior is the same on both the D3D backend, where there is no native interop involved, and on the GL backend using WGL_NV_DX_interop(2). There are a few limitations on the GL backend that relies on native interop: 1. SRGB conversion for textures created this way can't be disabled using the GL_FRAMEBUFFER_SRGB_EXT toggle that's exposed in ANGLE through EXT_sRGB_write_control. This is now documented in the EGL_ANGLE_d3d_texture_client_buffer spec. On the D3D backend this is not a problem since EXT_sRGB_write_control is not supported either way. 2. Creating a pbuffer out of a D3D11 texture with the format DXGI_FORMAT_B8G8R8A8_UNORM_SRGB does not work, even though it was listed as one of the supported formats in the EGL_ANGLE_d3d_texture_client_buffer spec. It's now mentioned that support for this format is optional. BUG=angleproject:2300 TEST=angle_white_box_tests Change-Id: I70ee0646680805e4469291a5b2ce59e92fda009e Reviewed-on: https://chromium-review.googlesource.com/866743 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.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
//
// 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.
//
// Surface.cpp: Implements the egl::Surface class, representing a drawing surface
// such as the client area of a window, including any back buffers.
// Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3.
#include "libANGLE/Surface.h"
#include <EGL/eglext.h>
#include "libANGLE/Config.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/Texture.h"
#include "libANGLE/Thread.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/EGLImplFactory.h"
namespace egl
{
SurfaceState::SurfaceState(const egl::Config *configIn, const AttributeMap &attributesIn)
: defaultFramebuffer(nullptr), config(configIn), attributes(attributesIn)
{
}
Surface::Surface(EGLint surfaceType,
const egl::Config *config,
const AttributeMap &attributes,
EGLenum buftype)
: FramebufferAttachmentObject(),
mState(config, attributes),
mImplementation(nullptr),
mCurrentCount(0),
mDestroyed(false),
mType(surfaceType),
mBuftype(buftype),
mPostSubBufferRequested(false),
mLargestPbuffer(false),
mGLColorspace(EGL_GL_COLORSPACE_LINEAR),
mVGAlphaFormat(EGL_VG_ALPHA_FORMAT_NONPRE),
mVGColorspace(EGL_VG_COLORSPACE_sRGB),
mMipmapTexture(false),
mMipmapLevel(0),
mHorizontalResolution(EGL_UNKNOWN),
mVerticalResolution(EGL_UNKNOWN),
mMultisampleResolve(EGL_MULTISAMPLE_RESOLVE_DEFAULT),
mFixedSize(false),
mFixedWidth(0),
mFixedHeight(0),
mTextureFormat(EGL_NO_TEXTURE),
mTextureTarget(EGL_NO_TEXTURE),
// FIXME: Determine actual pixel aspect ratio
mPixelAspectRatio(static_cast<EGLint>(1.0 * EGL_DISPLAY_SCALING)),
mRenderBuffer(EGL_BACK_BUFFER),
mSwapBehavior(EGL_NONE),
mOrientation(0),
mTexture(),
mColorFormat(config->renderTargetFormat),
mDSFormat(config->depthStencilFormat)
{
mPostSubBufferRequested = (attributes.get(EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_FALSE) == EGL_TRUE);
mFlexibleSurfaceCompatibilityRequested =
(attributes.get(EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE, EGL_FALSE) == EGL_TRUE);
if (mType == EGL_PBUFFER_BIT)
{
mLargestPbuffer = (attributes.get(EGL_LARGEST_PBUFFER, EGL_FALSE) == EGL_TRUE);
}
mGLColorspace =
static_cast<EGLenum>(attributes.get(EGL_GL_COLORSPACE, EGL_GL_COLORSPACE_LINEAR));
mVGAlphaFormat =
static_cast<EGLenum>(attributes.get(EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_NONPRE));
mVGColorspace = static_cast<EGLenum>(attributes.get(EGL_VG_COLORSPACE, EGL_VG_COLORSPACE_sRGB));
mMipmapTexture = (attributes.get(EGL_MIPMAP_TEXTURE, EGL_FALSE) == EGL_TRUE);
mDirectComposition = (attributes.get(EGL_DIRECT_COMPOSITION_ANGLE, EGL_FALSE) == EGL_TRUE);
mRobustResourceInitialization =
(attributes.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
mFixedSize = (attributes.get(EGL_FIXED_SIZE_ANGLE, EGL_FALSE) == EGL_TRUE);
if (mFixedSize)
{
mFixedWidth = static_cast<size_t>(attributes.get(EGL_WIDTH, 0));
mFixedHeight = static_cast<size_t>(attributes.get(EGL_HEIGHT, 0));
}
if (mType != EGL_WINDOW_BIT)
{
mTextureFormat = static_cast<EGLenum>(attributes.get(EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE));
mTextureTarget = static_cast<EGLenum>(attributes.get(EGL_TEXTURE_TARGET, EGL_NO_TEXTURE));
}
mOrientation = static_cast<EGLint>(attributes.get(EGL_SURFACE_ORIENTATION_ANGLE, 0));
}
Surface::~Surface()
{
}
rx::FramebufferAttachmentObjectImpl *Surface::getAttachmentImpl() const
{
return mImplementation;
}
Error Surface::destroyImpl(const Display *display)
{
if (mState.defaultFramebuffer)
{
mState.defaultFramebuffer->destroyDefault(display);
}
if (mImplementation)
{
mImplementation->destroy(display);
}
if (mTexture.get())
{
if (mImplementation)
{
ANGLE_TRY(mImplementation->releaseTexImage(EGL_BACK_BUFFER));
}
auto glErr = mTexture->releaseTexImageFromSurface(display->getProxyContext());
if (glErr.isError())
{
return Error(EGL_BAD_SURFACE);
}
mTexture.set(nullptr, nullptr);
}
if (mState.defaultFramebuffer)
{
mState.defaultFramebuffer->onDestroy(display->getProxyContext());
}
SafeDelete(mState.defaultFramebuffer);
SafeDelete(mImplementation);
delete this;
return NoError();
}
Error Surface::initialize(const Display *display)
{
ANGLE_TRY(mImplementation->initialize(display));
// Initialized here since impl is nullptr in the constructor.
// Must happen after implementation initialize for Android.
mSwapBehavior = mImplementation->getSwapBehavior();
// Must happen after implementation initialize for OSX.
mState.defaultFramebuffer = createDefaultFramebuffer(display);
ASSERT(mState.defaultFramebuffer != nullptr);
if (mBuftype == EGL_IOSURFACE_ANGLE)
{
GLenum internalFormat =
static_cast<GLenum>(mState.attributes.get(EGL_TEXTURE_INTERNAL_FORMAT_ANGLE));
GLenum type = static_cast<GLenum>(mState.attributes.get(EGL_TEXTURE_TYPE_ANGLE));
mColorFormat = gl::Format(internalFormat, type);
}
if (mBuftype == EGL_D3D_TEXTURE_ANGLE)
{
const angle::Format *colorFormat = mImplementation->getD3DTextureColorFormat();
ASSERT(colorFormat != nullptr);
GLenum internalFormat = colorFormat->fboImplementationInternalFormat;
mColorFormat = gl::Format(internalFormat, colorFormat->componentType);
mGLColorspace = EGL_GL_COLORSPACE_LINEAR;
if (mColorFormat.info->colorEncoding == GL_SRGB)
{
mGLColorspace = EGL_GL_COLORSPACE_SRGB;
}
}
return NoError();
}
Error Surface::setIsCurrent(const gl::Context *context, bool isCurrent)
{
if (isCurrent)
{
mCurrentCount++;
return NoError();
}
ASSERT(mCurrentCount > 0);
mCurrentCount--;
if (mCurrentCount == 0 && mDestroyed)
{
ASSERT(context);
return destroyImpl(context->getCurrentDisplay());
}
return NoError();
}
Error Surface::onDestroy(const Display *display)
{
mDestroyed = true;
if (mCurrentCount == 0)
{
return destroyImpl(display);
}
return NoError();
}
EGLint Surface::getType() const
{
return mType;
}
Error Surface::swap(const gl::Context *context)
{
return mImplementation->swap(context);
}
Error Surface::swapWithDamage(const gl::Context *context, EGLint *rects, EGLint n_rects)
{
return mImplementation->swapWithDamage(context, rects, n_rects);
}
Error Surface::postSubBuffer(const gl::Context *context,
EGLint x,
EGLint y,
EGLint width,
EGLint height)
{
return mImplementation->postSubBuffer(context, x, y, width, height);
}
Error Surface::querySurfacePointerANGLE(EGLint attribute, void **value)
{
return mImplementation->querySurfacePointerANGLE(attribute, value);
}
EGLint Surface::isPostSubBufferSupported() const
{
return mPostSubBufferRequested && mImplementation->isPostSubBufferSupported();
}
void Surface::setSwapInterval(EGLint interval)
{
mImplementation->setSwapInterval(interval);
}
void Surface::setMipmapLevel(EGLint level)
{
// Level is set but ignored
UNIMPLEMENTED();
mMipmapLevel = level;
}
void Surface::setMultisampleResolve(EGLenum resolve)
{
// Behaviour is set but ignored
UNIMPLEMENTED();
mMultisampleResolve = resolve;
}
void Surface::setSwapBehavior(EGLenum behavior)
{
// Behaviour is set but ignored
UNIMPLEMENTED();
mSwapBehavior = behavior;
}
const Config *Surface::getConfig() const
{
return mState.config;
}
EGLint Surface::getPixelAspectRatio() const
{
return mPixelAspectRatio;
}
EGLenum Surface::getRenderBuffer() const
{
return mRenderBuffer;
}
EGLenum Surface::getSwapBehavior() const
{
return mSwapBehavior;
}
EGLenum Surface::getTextureFormat() const
{
return mTextureFormat;
}
EGLenum Surface::getTextureTarget() const
{
return mTextureTarget;
}
bool Surface::getLargestPbuffer() const
{
return mLargestPbuffer;
}
EGLenum Surface::getGLColorspace() const
{
return mGLColorspace;
}
EGLenum Surface::getVGAlphaFormat() const
{
return mVGAlphaFormat;
}
EGLenum Surface::getVGColorspace() const
{
return mVGColorspace;
}
bool Surface::getMipmapTexture() const
{
return mMipmapTexture;
}
EGLint Surface::getMipmapLevel() const
{
return mMipmapLevel;
}
EGLint Surface::getHorizontalResolution() const
{
return mHorizontalResolution;
}
EGLint Surface::getVerticalResolution() const
{
return mVerticalResolution;
}
EGLenum Surface::getMultisampleResolve() const
{
return mMultisampleResolve;
}
EGLint Surface::isFixedSize() const
{
return mFixedSize;
}
EGLint Surface::getWidth() const
{
return mFixedSize ? static_cast<EGLint>(mFixedWidth) : mImplementation->getWidth();
}
EGLint Surface::getHeight() const
{
return mFixedSize ? static_cast<EGLint>(mFixedHeight) : mImplementation->getHeight();
}
Error Surface::bindTexImage(const gl::Context *context, gl::Texture *texture, EGLint buffer)
{
ASSERT(!mTexture.get());
ANGLE_TRY(mImplementation->bindTexImage(texture, buffer));
auto glErr = texture->bindTexImageFromSurface(context, this);
if (glErr.isError())
{
return Error(EGL_BAD_SURFACE);
}
mTexture.set(context, texture);
return NoError();
}
Error Surface::releaseTexImage(const gl::Context *context, EGLint buffer)
{
ASSERT(context);
ANGLE_TRY(mImplementation->releaseTexImage(buffer));
ASSERT(mTexture.get());
auto glErr = mTexture->releaseTexImageFromSurface(context);
if (glErr.isError())
{
return Error(EGL_BAD_SURFACE);
}
mTexture.set(context, nullptr);
return NoError();
}
Error Surface::getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc)
{
return mImplementation->getSyncValues(ust, msc, sbc);
}
void Surface::releaseTexImageFromTexture(const gl::Context *context)
{
ASSERT(mTexture.get());
mTexture.set(context, nullptr);
}
gl::Extents Surface::getAttachmentSize(const gl::ImageIndex & /*target*/) const
{
return gl::Extents(getWidth(), getHeight(), 1);
}
const gl::Format &Surface::getAttachmentFormat(GLenum binding, const gl::ImageIndex &target) const
{
return (binding == GL_BACK ? mColorFormat : mDSFormat);
}
GLsizei Surface::getAttachmentSamples(const gl::ImageIndex &target) const
{
return getConfig()->samples;
}
GLuint Surface::getId() const
{
UNREACHABLE();
return 0;
}
gl::Framebuffer *Surface::createDefaultFramebuffer(const Display *display)
{
return new gl::Framebuffer(display, this);
}
gl::InitState Surface::initState(const gl::ImageIndex & /*imageIndex*/) const
{
// TODO(jmadill): Lazy surface init.
return gl::InitState::Initialized;
}
void Surface::setInitState(const gl::ImageIndex & /*imageIndex*/, gl::InitState /*initState*/)
{
// No-op.
}
WindowSurface::WindowSurface(rx::EGLImplFactory *implFactory,
const egl::Config *config,
EGLNativeWindowType window,
const AttributeMap &attribs)
: Surface(EGL_WINDOW_BIT, config, attribs)
{
mImplementation = implFactory->createWindowSurface(mState, window, attribs);
}
WindowSurface::~WindowSurface()
{
}
PbufferSurface::PbufferSurface(rx::EGLImplFactory *implFactory,
const Config *config,
const AttributeMap &attribs)
: Surface(EGL_PBUFFER_BIT, config, attribs)
{
mImplementation = implFactory->createPbufferSurface(mState, attribs);
}
PbufferSurface::PbufferSurface(rx::EGLImplFactory *implFactory,
const Config *config,
EGLenum buftype,
EGLClientBuffer clientBuffer,
const AttributeMap &attribs)
: Surface(EGL_PBUFFER_BIT, config, attribs, buftype)
{
mImplementation =
implFactory->createPbufferFromClientBuffer(mState, buftype, clientBuffer, attribs);
}
PbufferSurface::~PbufferSurface()
{
}
PixmapSurface::PixmapSurface(rx::EGLImplFactory *implFactory,
const Config *config,
NativePixmapType nativePixmap,
const AttributeMap &attribs)
: Surface(EGL_PIXMAP_BIT, config, attribs)
{
mImplementation = implFactory->createPixmapSurface(mState, nativePixmap, attribs);
}
PixmapSurface::~PixmapSurface()
{
}
// SurfaceDeleter implementation.
SurfaceDeleter::SurfaceDeleter(const Display *display) : mDisplay(display)
{
}
SurfaceDeleter::~SurfaceDeleter()
{
}
void SurfaceDeleter::operator()(Surface *surface)
{
ANGLE_SWALLOW_ERR(surface->onDestroy(mDisplay));
}
} // namespace egl