Commit 45808a17 by Geoff Lang

Use WGL_ARB_pixel_format to choose the pixel format when available.

BUG=angleproject:890 Change-Id: If10ea7e1cb670bb3cd6fdcf40344d1c1e0acd862 Reviewed-on: https://chromium-review.googlesource.com/291650Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 1b94d432
...@@ -199,7 +199,20 @@ egl::Error DisplayWGL::initialize(egl::Display *display) ...@@ -199,7 +199,20 @@ egl::Error DisplayWGL::initialize(egl::Display *display)
return egl::Error(EGL_NOT_INITIALIZED, "Failed to get the device context of the intermediate OpenGL window."); return egl::Error(EGL_NOT_INITIALIZED, "Failed to get the device context of the intermediate OpenGL window.");
} }
mPixelFormat = ChoosePixelFormat(mDeviceContext, &pixelFormatDescriptor); if (mFunctionsWGL->choosePixelFormatARB)
{
std::vector<int> attribs = wgl::GetDefaultPixelFormatAttributes(false);
UINT matchingFormats = 0;
mFunctionsWGL->choosePixelFormatARB(mDeviceContext, &attribs[0], nullptr, 1u, &mPixelFormat,
&matchingFormats);
}
if (mPixelFormat == 0)
{
mPixelFormat = ChoosePixelFormat(mDeviceContext, &pixelFormatDescriptor);
}
if (mPixelFormat == 0) if (mPixelFormat == 0)
{ {
return egl::Error(EGL_NOT_INITIALIZED, "Could not find a compatible pixel format for the intermediate OpenGL window."); return egl::Error(EGL_NOT_INITIALIZED, "Could not find a compatible pixel format for the intermediate OpenGL window.");
...@@ -340,17 +353,6 @@ SurfaceImpl *DisplayWGL::createPixmapSurface(const egl::Config *configuration, ...@@ -340,17 +353,6 @@ SurfaceImpl *DisplayWGL::createPixmapSurface(const egl::Config *configuration,
return nullptr; return nullptr;
} }
static int QueryWGLFormatAttrib(HDC dc, int format, int attribName, const FunctionsWGL *functions)
{
int result = 0;
if (functions->getPixelFormatAttribivARB == nullptr ||
!functions->getPixelFormatAttribivARB(dc, format, 0, 1, &attribName, &result))
{
return 0;
}
return result;
}
egl::Error DisplayWGL::getDevice(DeviceImpl **device) egl::Error DisplayWGL::getDevice(DeviceImpl **device)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
...@@ -377,6 +379,11 @@ egl::ConfigSet DisplayWGL::generateConfigs() const ...@@ -377,6 +379,11 @@ egl::ConfigSet DisplayWGL::generateConfigs() const
PIXELFORMATDESCRIPTOR pixelFormatDescriptor; PIXELFORMATDESCRIPTOR pixelFormatDescriptor;
DescribePixelFormat(mDeviceContext, mPixelFormat, sizeof(pixelFormatDescriptor), &pixelFormatDescriptor); DescribePixelFormat(mDeviceContext, mPixelFormat, sizeof(pixelFormatDescriptor), &pixelFormatDescriptor);
auto getAttrib = [this](int attrib)
{
return wgl::QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, attrib, mFunctionsWGL);
};
egl::Config config; egl::Config config;
config.renderTargetFormat = GL_RGBA8; // TODO: use the bit counts to determine the format config.renderTargetFormat = GL_RGBA8; // TODO: use the bit counts to determine the format
config.depthStencilFormat = GL_DEPTH24_STENCIL8; // TODO: use the bit counts to determine the format config.depthStencilFormat = GL_DEPTH24_STENCIL8; // TODO: use the bit counts to determine the format
...@@ -387,17 +394,17 @@ egl::ConfigSet DisplayWGL::generateConfigs() const ...@@ -387,17 +394,17 @@ egl::ConfigSet DisplayWGL::generateConfigs() const
config.luminanceSize = 0; config.luminanceSize = 0;
config.alphaSize = pixelFormatDescriptor.cAlphaBits; config.alphaSize = pixelFormatDescriptor.cAlphaBits;
config.alphaMaskSize = 0; config.alphaMaskSize = 0;
config.bindToTextureRGB = (QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_BIND_TO_TEXTURE_RGB_ARB, mFunctionsWGL) == TRUE); config.bindToTextureRGB = (getAttrib(WGL_BIND_TO_TEXTURE_RGB_ARB) == TRUE);
config.bindToTextureRGBA = (QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_BIND_TO_TEXTURE_RGBA_ARB, mFunctionsWGL) == TRUE); config.bindToTextureRGBA = (getAttrib(WGL_BIND_TO_TEXTURE_RGBA_ARB) == TRUE);
config.colorBufferType = EGL_RGB_BUFFER; config.colorBufferType = EGL_RGB_BUFFER;
config.configCaveat = EGL_NONE; config.configCaveat = EGL_NONE;
config.conformant = EGL_OPENGL_ES2_BIT | (supportsES3 ? EGL_OPENGL_ES3_BIT_KHR : 0); config.conformant = EGL_OPENGL_ES2_BIT | (supportsES3 ? EGL_OPENGL_ES3_BIT_KHR : 0);
config.depthSize = pixelFormatDescriptor.cDepthBits; config.depthSize = pixelFormatDescriptor.cDepthBits;
config.level = 0; config.level = 0;
config.matchNativePixmap = EGL_NONE; config.matchNativePixmap = EGL_NONE;
config.maxPBufferWidth = QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_MAX_PBUFFER_WIDTH_ARB, mFunctionsWGL); config.maxPBufferWidth = getAttrib(WGL_MAX_PBUFFER_WIDTH_ARB);
config.maxPBufferHeight = QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_MAX_PBUFFER_HEIGHT_ARB, mFunctionsWGL); config.maxPBufferHeight = getAttrib(WGL_MAX_PBUFFER_HEIGHT_ARB);
config.maxPBufferPixels = QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_MAX_PBUFFER_PIXELS_ARB, mFunctionsWGL); config.maxPBufferPixels = getAttrib(WGL_MAX_PBUFFER_PIXELS_ARB);
config.maxSwapInterval = maxSwapInterval; config.maxSwapInterval = maxSwapInterval;
config.minSwapInterval = minSwapInterval; config.minSwapInterval = minSwapInterval;
config.nativeRenderable = EGL_TRUE; // Direct rendering config.nativeRenderable = EGL_TRUE; // Direct rendering
...@@ -407,9 +414,11 @@ egl::ConfigSet DisplayWGL::generateConfigs() const ...@@ -407,9 +414,11 @@ egl::ConfigSet DisplayWGL::generateConfigs() const
config.sampleBuffers = 0; // FIXME: enumerate multi-sampling config.sampleBuffers = 0; // FIXME: enumerate multi-sampling
config.samples = 0; config.samples = 0;
config.stencilSize = pixelFormatDescriptor.cStencilBits; config.stencilSize = pixelFormatDescriptor.cStencilBits;
config.surfaceType = ((pixelFormatDescriptor.dwFlags & PFD_DRAW_TO_WINDOW) ? EGL_WINDOW_BIT : 0) | config.surfaceType =
((QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_DRAW_TO_PBUFFER_ARB, mFunctionsWGL) == TRUE) ? EGL_PBUFFER_BIT : 0) | ((pixelFormatDescriptor.dwFlags & PFD_DRAW_TO_WINDOW) ? EGL_WINDOW_BIT : 0) |
EGL_SWAP_BEHAVIOR_PRESERVED_BIT; ((getAttrib(WGL_DRAW_TO_PBUFFER_ARB) == TRUE) ? EGL_PBUFFER_BIT : 0) |
((getAttrib(WGL_SWAP_METHOD_ARB) == WGL_SWAP_COPY_ARB) ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT
: 0);
config.transparentType = EGL_NONE; config.transparentType = EGL_NONE;
config.transparentRedValue = 0; config.transparentRedValue = 0;
config.transparentGreenValue = 0; config.transparentGreenValue = 0;
......
...@@ -121,8 +121,16 @@ void FunctionsWGL::initialize(HMODULE glModule, HDC context) ...@@ -121,8 +121,16 @@ void FunctionsWGL::initialize(HMODULE glModule, HDC context)
} }
// Load the wgl extension functions by checking if the context supports the extension first // Load the wgl extension functions by checking if the context supports the extension first
// WGL_ARB_create_context
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_create_context", "wglCreateContextAttribsARB", &createContextAttribsARB); GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_create_context", "wglCreateContextAttribsARB", &createContextAttribsARB);
// WGL_ARB_pixel_format
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format", "wglGetPixelFormatAttribivARB", &getPixelFormatAttribivARB); GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format", "wglGetPixelFormatAttribivARB", &getPixelFormatAttribivARB);
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format", "wglGetPixelFormatAttribfvARB", &getPixelFormatAttribfvARB);
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_ARB_pixel_format", "wglChoosePixelFormatARB", &choosePixelFormatARB);
// WGL_EXT_swap_control
GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_EXT_swap_control", "wglSwapIntervalEXT", &swapIntervalEXT); GetWGLExtensionProcAddress(glModule, getProcAddress, extensions, "WGL_EXT_swap_control", "wglSwapIntervalEXT", &swapIntervalEXT);
// WGL_ARB_pbuffer // WGL_ARB_pbuffer
......
...@@ -42,11 +42,21 @@ class FunctionsWGL : angle::NonCopyable ...@@ -42,11 +42,21 @@ class FunctionsWGL : angle::NonCopyable
PFNWGLSWAPLAYERBUFFERSPROC swapLayerBuffers; PFNWGLSWAPLAYERBUFFERSPROC swapLayerBuffers;
PFNWGLSWAPMULTIPLEBUFFERSPROC swapMultipleBuffers; PFNWGLSWAPMULTIPLEBUFFERSPROC swapMultipleBuffers;
// Extension functions, may be NULL // WGL_EXT_extensions_string
PFNWGLCREATECONTEXTATTRIBSARBPROC createContextAttribsARB;
PFNWGLGETPIXELFORMATATTRIBIVARBPROC getPixelFormatAttribivARB;
PFNWGLGETEXTENSIONSSTRINGEXTPROC getExtensionStringEXT; PFNWGLGETEXTENSIONSSTRINGEXTPROC getExtensionStringEXT;
// WGL_ARB_extensions_string
PFNWGLGETEXTENSIONSSTRINGARBPROC getExtensionStringARB; PFNWGLGETEXTENSIONSSTRINGARBPROC getExtensionStringARB;
// WGL_ARB_create_context
PFNWGLCREATECONTEXTATTRIBSARBPROC createContextAttribsARB;
// WGL_ARB_pixel_format
PFNWGLGETPIXELFORMATATTRIBIVARBPROC getPixelFormatAttribivARB;
PFNWGLGETPIXELFORMATATTRIBFVARBPROC getPixelFormatAttribfvARB;
PFNWGLCHOOSEPIXELFORMATARBPROC choosePixelFormatARB;
// WGL_EXT_swap_control
PFNWGLSWAPINTERVALEXTPROC swapIntervalEXT; PFNWGLSWAPINTERVALEXTPROC swapIntervalEXT;
// WGL_ARB_pbuffer // WGL_ARB_pbuffer
......
...@@ -15,13 +15,17 @@ ...@@ -15,13 +15,17 @@
namespace rx namespace rx
{ {
WindowSurfaceWGL::WindowSurfaceWGL(EGLNativeWindowType window, int pixelFormat, HGLRC wglContext, const FunctionsWGL *functions) WindowSurfaceWGL::WindowSurfaceWGL(EGLNativeWindowType window,
int pixelFormat,
HGLRC wglContext,
const FunctionsWGL *functions)
: SurfaceGL(), : SurfaceGL(),
mPixelFormat(pixelFormat), mPixelFormat(pixelFormat),
mWGLContext(wglContext), mWGLContext(wglContext),
mWindow(window), mWindow(window),
mDeviceContext(nullptr), mDeviceContext(nullptr),
mFunctionsWGL(functions) mFunctionsWGL(functions),
mSwapBehavior(0)
{ {
} }
...@@ -61,6 +65,21 @@ egl::Error WindowSurfaceWGL::initialize() ...@@ -61,6 +65,21 @@ egl::Error WindowSurfaceWGL::initialize()
return egl::Error(EGL_NOT_INITIALIZED, "Pixel format of the NativeWindow and NativeDisplayType must match."); return egl::Error(EGL_NOT_INITIALIZED, "Pixel format of the NativeWindow and NativeDisplayType must match.");
} }
// Check for the swap behavior of this pixel format
switch (
wgl::QueryWGLFormatAttrib(mDeviceContext, mPixelFormat, WGL_SWAP_METHOD_ARB, mFunctionsWGL))
{
case WGL_SWAP_COPY_ARB:
mSwapBehavior = EGL_BUFFER_PRESERVED;
break;
case WGL_SWAP_EXCHANGE_ARB:
case WGL_SWAP_UNDEFINED_ARB:
default:
mSwapBehavior = EGL_BUFFER_DESTROYED;
break;
}
return egl::Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
...@@ -147,7 +166,7 @@ EGLint WindowSurfaceWGL::isPostSubBufferSupported() const ...@@ -147,7 +166,7 @@ EGLint WindowSurfaceWGL::isPostSubBufferSupported() const
EGLint WindowSurfaceWGL::getSwapBehavior() const EGLint WindowSurfaceWGL::getSwapBehavior() const
{ {
return EGL_BUFFER_PRESERVED; return mSwapBehavior;
} }
} }
...@@ -49,6 +49,8 @@ class WindowSurfaceWGL : public SurfaceGL ...@@ -49,6 +49,8 @@ class WindowSurfaceWGL : public SurfaceGL
HDC mDeviceContext; HDC mDeviceContext;
const FunctionsWGL *mFunctionsWGL; const FunctionsWGL *mFunctionsWGL;
EGLint mSwapBehavior;
}; };
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "libANGLE/renderer/gl/wgl/wgl_utils.h" #include "libANGLE/renderer/gl/wgl/wgl_utils.h"
#include "libANGLE/renderer/gl/wgl/functionsWGL.h"
namespace rx namespace rx
{ {
...@@ -30,6 +32,54 @@ PIXELFORMATDESCRIPTOR GetDefaultPixelFormatDescriptor() ...@@ -30,6 +32,54 @@ PIXELFORMATDESCRIPTOR GetDefaultPixelFormatDescriptor()
return pixelFormatDescriptor; return pixelFormatDescriptor;
} }
std::vector<int> GetDefaultPixelFormatAttributes(bool preservedSwap)
{
std::vector<int> attribs;
attribs.push_back(WGL_DRAW_TO_WINDOW_ARB);
attribs.push_back(TRUE);
attribs.push_back(WGL_ACCELERATION_ARB);
attribs.push_back(WGL_FULL_ACCELERATION_ARB);
attribs.push_back(WGL_SUPPORT_OPENGL_ARB);
attribs.push_back(TRUE);
attribs.push_back(WGL_DOUBLE_BUFFER_ARB);
attribs.push_back(TRUE);
attribs.push_back(WGL_PIXEL_TYPE_ARB);
attribs.push_back(WGL_TYPE_RGBA_ARB);
attribs.push_back(WGL_COLOR_BITS_ARB);
attribs.push_back(24);
attribs.push_back(WGL_ALPHA_BITS_ARB);
attribs.push_back(8);
attribs.push_back(WGL_DEPTH_BITS_ARB);
attribs.push_back(24);
attribs.push_back(WGL_STENCIL_BITS_ARB);
attribs.push_back(8);
attribs.push_back(WGL_SWAP_METHOD_ARB);
attribs.push_back(preservedSwap ? WGL_SWAP_COPY_ARB : WGL_SWAP_UNDEFINED_ARB);
attribs.push_back(0);
return attribs;
}
int QueryWGLFormatAttrib(HDC dc, int format, int attribName, const FunctionsWGL *functions)
{
int result = 0;
if (functions->getPixelFormatAttribivARB == nullptr ||
!functions->getPixelFormatAttribivARB(dc, format, 0, 1, &attribName, &result))
{
return 0;
}
return result;
}
} }
} }
...@@ -9,16 +9,22 @@ ...@@ -9,16 +9,22 @@
#ifndef LIBANGLE_RENDERER_GL_WGL_WGLUTILS_H_ #ifndef LIBANGLE_RENDERER_GL_WGL_WGLUTILS_H_
#define LIBANGLE_RENDERER_GL_WGL_WGLUTILS_H_ #define LIBANGLE_RENDERER_GL_WGL_WGLUTILS_H_
#include <vector>
#include "common/platform.h" #include "common/platform.h"
namespace rx namespace rx
{ {
class FunctionsWGL;
namespace wgl namespace wgl
{ {
PIXELFORMATDESCRIPTOR GetDefaultPixelFormatDescriptor(); PIXELFORMATDESCRIPTOR GetDefaultPixelFormatDescriptor();
std::vector<int> GetDefaultPixelFormatAttributes(bool preservedSwap);
int QueryWGLFormatAttrib(HDC dc, int format, int attribName, const FunctionsWGL *functions);
} }
} }
......
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