Commit d756145d by Cooper Partin Committed by Geoff Lang

Re-land "Added support for premultiplied alpha mode for composition swapchains"

Change-Id: Ic0c863c3d4936947fc520a5394e38e458659df46 Reviewed-on: https://chromium-review.googlesource.com/298880Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 62d31cb6
......@@ -33,8 +33,14 @@ SurfaceD3D *SurfaceD3D::createFromWindow(RendererD3D *renderer, egl::Display *di
return new SurfaceD3D(renderer, display, config, width, height, fixedSize, static_cast<EGLClientBuffer>(0), window);
}
SurfaceD3D::SurfaceD3D(RendererD3D *renderer, egl::Display *display, const egl::Config *config, EGLint width, EGLint height, EGLint fixedSize,
EGLClientBuffer shareHandle, EGLNativeWindowType window)
SurfaceD3D::SurfaceD3D(RendererD3D *renderer,
egl::Display *display,
const egl::Config *config,
EGLint width,
EGLint height,
EGLint fixedSize,
EGLClientBuffer shareHandle,
EGLNativeWindowType window)
: SurfaceImpl(),
mRenderer(renderer),
mDisplay(display),
......@@ -43,11 +49,11 @@ SurfaceD3D::SurfaceD3D(RendererD3D *renderer, egl::Display *display, const egl::
mDepthStencilFormat(config->depthStencilFormat),
mSwapChain(nullptr),
mSwapIntervalDirty(true),
mNativeWindow(window),
mNativeWindow(window, config),
mWidth(width),
mHeight(height),
mSwapInterval(1),
mShareHandle(reinterpret_cast<HANDLE*>(shareHandle))
mShareHandle(reinterpret_cast<HANDLE *>(shareHandle))
{
}
......
......@@ -16,6 +16,7 @@
#include "common/platform.h"
#include <EGL/eglplatform.h>
#include "libANGLE/Config.h"
// DXGISwapChain and DXGIFactory are typedef'd to specific required
// types. The HWND NativeWindow implementation requires IDXGISwapChain
......@@ -49,7 +50,7 @@ namespace rx
class NativeWindow
{
public:
explicit NativeWindow(EGLNativeWindowType window);
explicit NativeWindow(EGLNativeWindowType window, const egl::Config *config);
bool initialize();
bool getClientRect(LPRECT rect);
......@@ -66,6 +67,7 @@ class NativeWindow
EGLNativeWindowType mWindow;
#if defined(ANGLE_ENABLE_WINDOWS_STORE)
const egl::Config *mConfig;
std::shared_ptr<InspectableNativeWindow> mImpl;
#endif
......
......@@ -678,15 +678,13 @@ void Renderer11::populateRenderer11DeviceCaps()
egl::ConfigSet Renderer11::generateConfigs() const
{
static const GLenum colorBufferFormats[] =
{
static const GLenum colorBufferFormats[] = {
// 32-bit supported formats
GL_BGRA8_EXT,
GL_RGBA8_OES,
GL_BGRA8_EXT, GL_RGBA8_OES,
// 24-bit supported formats
GL_RGB8_OES,
// 16-bit supported formats
GL_RGBA4,
GL_RGB5_A1,
GL_RGB565,
GL_RGBA4, GL_RGB5_A1, GL_RGB565,
};
static const GLenum depthStencilBufferFormats[] =
......
......@@ -14,7 +14,8 @@
namespace rx
{
NativeWindow::NativeWindow(EGLNativeWindowType window) : mWindow(window)
NativeWindow::NativeWindow(EGLNativeWindowType window, const egl::Config *)
: mWindow(window)
{
}
......
......@@ -134,7 +134,13 @@ void CoreWindowNativeWindow::unregisterForSizeChangeEvents()
mSizeChangedEventToken.value = 0;
}
HRESULT CoreWindowNativeWindow::createSwapChain(ID3D11Device *device, DXGIFactory *factory, DXGI_FORMAT format, unsigned int width, unsigned int height, DXGISwapChain **swapChain)
HRESULT CoreWindowNativeWindow::createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain)
{
if (device == NULL || factory == NULL || swapChain == NULL || width == 0 || height == 0)
{
......@@ -152,6 +158,7 @@ HRESULT CoreWindowNativeWindow::createSwapChain(ID3D11Device *device, DXGIFactor
swapChainDesc.BufferCount = 2;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
*swapChain = nullptr;
......
......@@ -25,7 +25,13 @@ class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enabl
~CoreWindowNativeWindow();
bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) override;
HRESULT createSwapChain(ID3D11Device *device, DXGIFactory *factory, DXGI_FORMAT format, unsigned int width, unsigned int height, DXGISwapChain **swapChain) override;
HRESULT createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain) override;
protected:
HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) override;
......
......@@ -11,9 +11,10 @@
namespace rx
{
NativeWindow::NativeWindow(EGLNativeWindowType window)
NativeWindow::NativeWindow(EGLNativeWindowType window, const egl::Config *config)
{
mWindow = window;
mConfig = config;
}
bool NativeWindow::initialize()
......@@ -83,7 +84,9 @@ HRESULT NativeWindow::createSwapChain(ID3D11Device *device, DXGIFactory *factory
{
if (mImpl)
{
return mImpl->createSwapChain(device, factory, format, width, height, swapChain);
bool containsAlpha = (mConfig->alphaSize > 0);
return mImpl->createSwapChain(device, factory, format, width, height, containsAlpha,
swapChain);
}
return E_UNEXPECTED;
......
......@@ -43,7 +43,13 @@ class InspectableNativeWindow
virtual ~InspectableNativeWindow(){}
virtual bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) = 0;
virtual HRESULT createSwapChain(ID3D11Device *device, DXGIFactory *factory, DXGI_FORMAT format, unsigned int width, unsigned int height, DXGISwapChain **swapChain) = 0;
virtual HRESULT createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain) = 0;
bool getClientRect(RECT *rect)
{
......
......@@ -146,7 +146,13 @@ void SwapChainPanelNativeWindow::unregisterForSizeChangeEvents()
mSizeChangedEventToken.value = 0;
}
HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device, DXGIFactory *factory, DXGI_FORMAT format, unsigned int width, unsigned int height, DXGISwapChain **swapChain)
HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain)
{
if (device == NULL || factory == NULL || swapChain == NULL || width == 0 || height == 0)
{
......@@ -164,7 +170,8 @@ HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device, DXGIFa
swapChainDesc.BufferCount = 2;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
swapChainDesc.AlphaMode =
containsAlpha ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE;
*swapChain = nullptr;
......
......@@ -19,7 +19,13 @@ class SwapChainPanelNativeWindow : public InspectableNativeWindow, public std::e
~SwapChainPanelNativeWindow();
bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) override;
HRESULT createSwapChain(ID3D11Device *device, DXGIFactory *factory, DXGI_FORMAT format, unsigned int width, unsigned int height, DXGISwapChain **swapChain) override;
HRESULT createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain) override;
protected:
HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) override;
......
......@@ -342,8 +342,7 @@ TEST_F(EGLSurfaceTest, ResizeD3DWindow)
// support GL_RGB565
TEST_F(EGLSurfaceTest, CreateWithEGLConfig5650Support)
{
const char *extensionsString = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
if (strstr(extensionsString, "EGL_ANGLE_platform_angle_d3d") == nullptr)
if (!ANGLETest::eglDisplayExtensionEnabled(EGL_NO_DISPLAY, "EGL_ANGLE_platform_angle_d3d"))
{
std::cout << "D3D Platform not supported in ANGLE" << std::endl;
return;
......@@ -372,7 +371,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig5650Support)
initializeSurface(config);
eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
drawWithProgram(program);
......@@ -384,8 +383,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig5650Support)
// support GL_RGBA4
TEST_F(EGLSurfaceTest, CreateWithEGLConfig4444Support)
{
const char *extensionsString = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
if (strstr(extensionsString, "EGL_ANGLE_platform_angle_d3d") == nullptr)
if (!ANGLETest::eglDisplayExtensionEnabled(EGL_NO_DISPLAY, "EGL_ANGLE_platform_angle_d3d"))
{
std::cout << "D3D Platform not supported in ANGLE" << std::endl;
return;
......@@ -414,7 +412,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig4444Support)
initializeSurface(config);
eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
drawWithProgram(program);
......@@ -426,8 +424,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig4444Support)
// support GL_RGB5_A1
TEST_F(EGLSurfaceTest, CreateWithEGLConfig5551Support)
{
const char *extensionsString = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
if (strstr(extensionsString, "EGL_ANGLE_platform_angle_d3d") == nullptr)
if (!ANGLETest::eglDisplayExtensionEnabled(EGL_NO_DISPLAY, "EGL_ANGLE_platform_angle_d3d"))
{
std::cout << "D3D Platform not supported in ANGLE" << std::endl;
return;
......@@ -456,7 +453,48 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig5551Support)
initializeSurface(config);
eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
ASSERT_TRUE(eglGetError() == EGL_SUCCESS);
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
drawWithProgram(program);
EXPECT_GL_NO_ERROR();
glDeleteProgram(program);
}
// Test creating a surface that supports a EGLConfig without alpha support
TEST_F(EGLSurfaceTest, CreateWithEGLConfig8880Support)
{
if (!ANGLETest::eglDisplayExtensionEnabled(EGL_NO_DISPLAY, "EGL_ANGLE_platform_angle_d3d"))
{
std::cout << "D3D Platform not supported in ANGLE" << std::endl;
return;
}
const EGLint configAttributes[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 0,
EGL_DEPTH_SIZE, 0,
EGL_STENCIL_SIZE, 0,
EGL_SAMPLE_BUFFERS, 0,
EGL_NONE
};
initializeDisplay(EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE);
EGLConfig config;
if (EGLWindow::FindEGLConfig(mDisplay, configAttributes, &config) == EGL_FALSE)
{
std::cout << "EGLConfig for a GL_RGB8_OES surface is not supported, skipping test"
<< std::endl;
return;
}
initializeSurface(config);
eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
drawWithProgram(program);
......
......@@ -27,6 +27,7 @@ class D3D11InputLayoutCacheTest : public ANGLETest
setWindowWidth(64);
setWindowHeight(64);
setConfigRedBits(8);
setConfigAlphaBits(8);
}
GLuint makeProgramWithAttribCount(unsigned int attribCount)
......
......@@ -68,6 +68,7 @@ class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters>
static bool InitTestWindow();
static bool DestroyTestWindow();
static void SetWindowVisible(bool isVisible);
static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
protected:
virtual void SetUp();
......@@ -78,7 +79,6 @@ class ANGLETest : public ::testing::TestWithParam<angle::PlatformParameters>
static void drawQuad(GLuint program, const std::string& positionAttribName, GLfloat quadDepth, GLfloat quadScale = 1.0f);
static GLuint compileShader(GLenum type, const std::string &source);
static bool extensionEnabled(const std::string &extName);
static bool eglDisplayExtensionEnabled(EGLDisplay display, const std::string &extName);
static bool eglClientExtensionEnabled(const std::string &extName);
void setWindowWidth(int width);
......
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