Commit e19a8192 authored by Corentin Wallez's avatar Corentin Wallez Committed by Commit Bot

ui/gl: Remove WGL support on Windows

The WGL path hasn't been used in the last many years and
shouldn't be used in the future since ANGLE provides an EGL
implementation on top of D3D or GL depending on what's available.

Remove all WGL support code since it isn't needed anymore.

Bug: chromium:1133372
Change-Id: I1c23f3b17682082e43d7c6072c085a94735e4cf8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2434341
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarGeoff Lang <geofflang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811831}
parent 2db090d2
...@@ -307,18 +307,10 @@ component("gl") { ...@@ -307,18 +307,10 @@ component("gl") {
"direct_composition_surface_win.h", "direct_composition_surface_win.h",
"gl_angle_util_win.cc", "gl_angle_util_win.cc",
"gl_angle_util_win.h", "gl_angle_util_win.h",
"gl_bindings_autogen_wgl.cc",
"gl_bindings_autogen_wgl.h",
"gl_context_wgl.cc",
"gl_context_wgl.h",
"gl_image_d3d.cc", "gl_image_d3d.cc",
"gl_image_d3d.h", "gl_image_d3d.h",
"gl_image_dxgi.cc", "gl_image_dxgi.cc",
"gl_image_dxgi.h", "gl_image_dxgi.h",
"gl_surface_wgl.cc",
"gl_surface_wgl.h",
"gl_wgl_api_implementation.cc",
"gl_wgl_api_implementation.h",
"hdr_metadata_helper_win.cc", "hdr_metadata_helper_win.cc",
"hdr_metadata_helper_win.h", "hdr_metadata_helper_win.h",
"swap_chain_presenter.cc", "swap_chain_presenter.cc",
...@@ -576,7 +568,6 @@ test("gl_unittests") { ...@@ -576,7 +568,6 @@ test("gl_unittests") {
"gl_image_d3d_unittest.cc", "gl_image_d3d_unittest.cc",
"gl_image_dxgi_unittest.cc", "gl_image_dxgi_unittest.cc",
"hdr_metadata_helper_win_unittest.cc", "hdr_metadata_helper_win_unittest.cc",
"wgl_api_unittest.cc",
] ]
} }
......
...@@ -22,8 +22,6 @@ HEADER_PATHS = [ ...@@ -22,8 +22,6 @@ HEADER_PATHS = [
] ]
UNCONDITIONALLY_BOUND_EXTENSIONS = set([ UNCONDITIONALLY_BOUND_EXTENSIONS = set([
'WGL_ARB_extensions_string',
'WGL_EXT_extensions_string',
'GL_CHROMIUM_gles_depth_binding_hack', # crbug.com/448206 'GL_CHROMIUM_gles_depth_binding_hack', # crbug.com/448206
'GL_CHROMIUM_glgetstringi_hack', # crbug.com/470396 'GL_CHROMIUM_glgetstringi_hack', # crbug.com/470396
'GL_CHROMIUM_egl_khr_fence_sync_hack', # crbug.com/504758 'GL_CHROMIUM_egl_khr_fence_sync_hack', # crbug.com/504758
...@@ -2744,69 +2742,6 @@ EGL_FUNCTIONS = [ ...@@ -2744,69 +2742,6 @@ EGL_FUNCTIONS = [
'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags' }, 'arguments': 'EGLDisplay dpy, EGLSyncKHR sync, EGLint flags' },
] ]
WGL_FUNCTIONS = [
{ 'return_type': 'BOOL',
'names': ['wglChoosePixelFormatARB'],
'arguments':
'HDC dc, const int* int_attrib_list, const float* float_attrib_list, '
'UINT max_formats, int* formats, UINT* num_formats', },
{ 'return_type': 'BOOL',
'names': ['wglCopyContext'],
'arguments': 'HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask', },
{ 'return_type': 'HGLRC',
'names': ['wglCreateContext'],
'arguments': 'HDC hdc', },
{ 'return_type': 'HGLRC',
'names': ['wglCreateContextAttribsARB'],
'arguments': 'HDC hDC, HGLRC hShareContext, const int* attribList', },
{ 'return_type': 'HGLRC',
'names': ['wglCreateLayerContext'],
'arguments': 'HDC hdc, int iLayerPlane', },
{ 'return_type': 'HPBUFFERARB',
'names': ['wglCreatePbufferARB'],
'arguments': 'HDC hDC, int iPixelFormat, int iWidth, int iHeight, '
'const int* piAttribList', },
{ 'return_type': 'BOOL',
'names': ['wglDeleteContext'],
'arguments': 'HGLRC hglrc', },
{ 'return_type': 'BOOL',
'names': ['wglDestroyPbufferARB'],
'arguments': 'HPBUFFERARB hPbuffer', },
{ 'return_type': 'HGLRC',
'names': ['wglGetCurrentContext'],
'arguments': '', },
{ 'return_type': 'HDC',
'names': ['wglGetCurrentDC'],
'arguments': '', },
{ 'return_type': 'const char*',
'names': ['wglGetExtensionsStringARB'],
'arguments': 'HDC hDC', },
{ 'return_type': 'const char*',
'names': ['wglGetExtensionsStringEXT'],
'arguments': '', },
{ 'return_type': 'HDC',
'names': ['wglGetPbufferDCARB'],
'arguments': 'HPBUFFERARB hPbuffer', },
{ 'return_type': 'BOOL',
'names': ['wglMakeCurrent'],
'arguments': 'HDC hdc, HGLRC hglrc', },
{ 'return_type': 'BOOL',
'names': ['wglQueryPbufferARB'],
'arguments': 'HPBUFFERARB hPbuffer, int iAttribute, int* piValue', },
{ 'return_type': 'int',
'names': ['wglReleasePbufferDCARB'],
'arguments': 'HPBUFFERARB hPbuffer, HDC hDC', },
{ 'return_type': 'BOOL',
'names': ['wglShareLists'],
'arguments': 'HGLRC hglrc1, HGLRC hglrc2', },
{ 'return_type': 'BOOL',
'names': ['wglSwapIntervalEXT'],
'arguments': 'int interval', },
{ 'return_type': 'BOOL',
'names': ['wglSwapLayerBuffers'],
'arguments': 'HDC hdc, UINT fuPlanes', },
]
GLX_FUNCTIONS = [ GLX_FUNCTIONS = [
{ 'return_type': 'void', { 'return_type': 'void',
'names': ['glXBindTexImageEXT'], 'names': ['glXBindTexImageEXT'],
...@@ -2999,7 +2934,6 @@ FUNCTION_SETS = [ ...@@ -2999,7 +2934,6 @@ FUNCTION_SETS = [
'EGL_ANGLE_surface_d3d_texture_2d_share_handle', 'EGL_ANGLE_surface_d3d_texture_2d_share_handle',
], ],
], ],
[WGL_FUNCTIONS, 'wgl', ['noninclude/GL/wglext.h'], []],
[GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'noninclude/GL/glxext.h'], []], [GLX_FUNCTIONS, 'glx', ['GL/glx.h', 'noninclude/GL/glxext.h'], []],
] ]
...@@ -3800,7 +3734,7 @@ def ParseFunctionsFromHeader(header_file, extensions, versions): ...@@ -3800,7 +3734,7 @@ def ParseFunctionsFromHeader(header_file, extensions, versions):
version_start = re.compile( version_start = re.compile(
r'#ifndef GL_(ES_|)VERSION((?:_[0-9])+)$') r'#ifndef GL_(ES_|)VERSION((?:_[0-9])+)$')
extension_start = re.compile( extension_start = re.compile(
r'#ifndef ((?:GL|EGL|WGL|GLX)_[A-Z]+_[a-zA-Z]\w+)') r'#ifndef ((?:GL|EGL|GLX)_[A-Z]+_[a-zA-Z]\w+)')
extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(') extension_function = re.compile(r'.+\s+([a-z]+\w+)\s*\(')
typedef = re.compile(r'typedef .*') typedef = re.compile(r'typedef .*')
macro_start = re.compile(r'^#(if|ifdef|ifndef).*') macro_start = re.compile(r'^#(if|ifdef|ifndef).*')
......
...@@ -14,26 +14,12 @@ ...@@ -14,26 +14,12 @@
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#endif #endif
#if defined(OS_WIN)
#include "ui/gl/gl_surface_wgl.h"
#endif
#if defined(USE_EGL) #if defined(USE_EGL)
#include "ui/gl/gl_surface_egl.h" #include "ui/gl/gl_surface_egl.h"
#endif #endif
namespace gl { namespace gl {
#if defined(OS_WIN)
std::string DriverWGL::GetPlatformExtensions() {
const char* str = nullptr;
str = wglGetExtensionsStringARB(GLSurfaceWGL::GetDisplayDC());
if (str)
return str;
return wglGetExtensionsStringEXT();
}
#endif
#if defined(USE_EGL) #if defined(USE_EGL)
std::string DriverEGL::GetPlatformExtensions() { std::string DriverEGL::GetPlatformExtensions() {
EGLDisplay display = GLSurfaceEGL::GetHardwareDisplay(); EGLDisplay display = GLSurfaceEGL::GetHardwareDisplay();
......
...@@ -504,10 +504,6 @@ typedef uint64_t EGLuint64CHROMIUM; ...@@ -504,10 +504,6 @@ typedef uint64_t EGLuint64CHROMIUM;
#include "gl_bindings_autogen_egl.h" #include "gl_bindings_autogen_egl.h"
#endif #endif
#if defined(OS_WIN)
#include "gl_bindings_autogen_wgl.h"
#endif
#if defined(USE_GLX) #if defined(USE_GLX)
#include "gl_bindings_autogen_glx.h" #include "gl_bindings_autogen_glx.h"
#endif #endif
...@@ -537,20 +533,6 @@ struct GL_EXPORT CurrentGL { ...@@ -537,20 +533,6 @@ struct GL_EXPORT CurrentGL {
const GLVersionInfo* Version = nullptr; const GLVersionInfo* Version = nullptr;
}; };
#if defined(OS_WIN)
struct GL_EXPORT DriverWGL {
void InitializeStaticBindings();
void InitializeExtensionBindings();
void ClearBindings();
ProcsWGL fn;
ExtensionsWGL ext;
private:
static std::string GetPlatformExtensions();
};
#endif
#if defined(USE_EGL) #if defined(USE_EGL)
struct GL_EXPORT DriverEGL { struct GL_EXPORT DriverEGL {
void InitializeStaticBindings(); void InitializeStaticBindings();
...@@ -592,11 +574,6 @@ GL_EXPORT extern EGLApi* g_current_egl_context; ...@@ -592,11 +574,6 @@ GL_EXPORT extern EGLApi* g_current_egl_context;
GL_EXPORT extern DriverEGL g_driver_egl; GL_EXPORT extern DriverEGL g_driver_egl;
#endif #endif
#if defined(OS_WIN)
GL_EXPORT extern WGLApi* g_current_wgl_context;
GL_EXPORT extern DriverWGL g_driver_wgl;
#endif
#if defined(USE_GLX) #if defined(USE_GLX)
GL_EXPORT extern GLXApi* g_current_glx_context; GL_EXPORT extern GLXApi* g_current_glx_context;
GL_EXPORT extern DriverGLX g_driver_glx; GL_EXPORT extern DriverGLX g_driver_glx;
......
This diff is collapsed.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file is auto-generated from
// ui/gl/generate_bindings.py
// It's formatted by clang-format using chromium coding style:
// clang-format -i -style=chromium filename
// DO NOT EDIT!
#ifndef UI_GL_GL_BINDINGS_AUTOGEN_WGL_H_
#define UI_GL_GL_BINDINGS_AUTOGEN_WGL_H_
#include <string>
namespace gl {
class GLContext;
typedef BOOL(GL_BINDING_CALL* wglChoosePixelFormatARBProc)(
HDC dc,
const int* int_attrib_list,
const float* float_attrib_list,
UINT max_formats,
int* formats,
UINT* num_formats);
typedef BOOL(GL_BINDING_CALL* wglCopyContextProc)(HGLRC hglrcSrc,
HGLRC hglrcDst,
UINT mask);
typedef HGLRC(GL_BINDING_CALL* wglCreateContextProc)(HDC hdc);
typedef HGLRC(GL_BINDING_CALL* wglCreateContextAttribsARBProc)(
HDC hDC,
HGLRC hShareContext,
const int* attribList);
typedef HGLRC(GL_BINDING_CALL* wglCreateLayerContextProc)(HDC hdc,
int iLayerPlane);
typedef HPBUFFERARB(GL_BINDING_CALL* wglCreatePbufferARBProc)(
HDC hDC,
int iPixelFormat,
int iWidth,
int iHeight,
const int* piAttribList);
typedef BOOL(GL_BINDING_CALL* wglDeleteContextProc)(HGLRC hglrc);
typedef BOOL(GL_BINDING_CALL* wglDestroyPbufferARBProc)(HPBUFFERARB hPbuffer);
typedef HGLRC(GL_BINDING_CALL* wglGetCurrentContextProc)();
typedef HDC(GL_BINDING_CALL* wglGetCurrentDCProc)();
typedef const char*(GL_BINDING_CALL* wglGetExtensionsStringARBProc)(HDC hDC);
typedef const char*(GL_BINDING_CALL* wglGetExtensionsStringEXTProc)();
typedef HDC(GL_BINDING_CALL* wglGetPbufferDCARBProc)(HPBUFFERARB hPbuffer);
typedef BOOL(GL_BINDING_CALL* wglMakeCurrentProc)(HDC hdc, HGLRC hglrc);
typedef BOOL(GL_BINDING_CALL* wglQueryPbufferARBProc)(HPBUFFERARB hPbuffer,
int iAttribute,
int* piValue);
typedef int(GL_BINDING_CALL* wglReleasePbufferDCARBProc)(HPBUFFERARB hPbuffer,
HDC hDC);
typedef BOOL(GL_BINDING_CALL* wglShareListsProc)(HGLRC hglrc1, HGLRC hglrc2);
typedef BOOL(GL_BINDING_CALL* wglSwapIntervalEXTProc)(int interval);
typedef BOOL(GL_BINDING_CALL* wglSwapLayerBuffersProc)(HDC hdc, UINT fuPlanes);
struct ExtensionsWGL {
bool b_WGL_ARB_create_context;
bool b_WGL_ARB_extensions_string;
bool b_WGL_ARB_pbuffer;
bool b_WGL_ARB_pixel_format;
bool b_WGL_EXT_extensions_string;
bool b_WGL_EXT_swap_control;
};
struct ProcsWGL {
wglChoosePixelFormatARBProc wglChoosePixelFormatARBFn;
wglCopyContextProc wglCopyContextFn;
wglCreateContextProc wglCreateContextFn;
wglCreateContextAttribsARBProc wglCreateContextAttribsARBFn;
wglCreateLayerContextProc wglCreateLayerContextFn;
wglCreatePbufferARBProc wglCreatePbufferARBFn;
wglDeleteContextProc wglDeleteContextFn;
wglDestroyPbufferARBProc wglDestroyPbufferARBFn;
wglGetCurrentContextProc wglGetCurrentContextFn;
wglGetCurrentDCProc wglGetCurrentDCFn;
wglGetExtensionsStringARBProc wglGetExtensionsStringARBFn;
wglGetExtensionsStringEXTProc wglGetExtensionsStringEXTFn;
wglGetPbufferDCARBProc wglGetPbufferDCARBFn;
wglMakeCurrentProc wglMakeCurrentFn;
wglQueryPbufferARBProc wglQueryPbufferARBFn;
wglReleasePbufferDCARBProc wglReleasePbufferDCARBFn;
wglShareListsProc wglShareListsFn;
wglSwapIntervalEXTProc wglSwapIntervalEXTFn;
wglSwapLayerBuffersProc wglSwapLayerBuffersFn;
};
class GL_EXPORT WGLApi {
public:
WGLApi();
virtual ~WGLApi();
virtual void SetDisabledExtensions(const std::string& disabled_extensions) {}
virtual BOOL wglChoosePixelFormatARBFn(HDC dc,
const int* int_attrib_list,
const float* float_attrib_list,
UINT max_formats,
int* formats,
UINT* num_formats) = 0;
virtual BOOL wglCopyContextFn(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask) = 0;
virtual HGLRC wglCreateContextFn(HDC hdc) = 0;
virtual HGLRC wglCreateContextAttribsARBFn(HDC hDC,
HGLRC hShareContext,
const int* attribList) = 0;
virtual HGLRC wglCreateLayerContextFn(HDC hdc, int iLayerPlane) = 0;
virtual HPBUFFERARB wglCreatePbufferARBFn(HDC hDC,
int iPixelFormat,
int iWidth,
int iHeight,
const int* piAttribList) = 0;
virtual BOOL wglDeleteContextFn(HGLRC hglrc) = 0;
virtual BOOL wglDestroyPbufferARBFn(HPBUFFERARB hPbuffer) = 0;
virtual HGLRC wglGetCurrentContextFn() = 0;
virtual HDC wglGetCurrentDCFn() = 0;
virtual const char* wglGetExtensionsStringARBFn(HDC hDC) = 0;
virtual const char* wglGetExtensionsStringEXTFn() = 0;
virtual HDC wglGetPbufferDCARBFn(HPBUFFERARB hPbuffer) = 0;
virtual BOOL wglMakeCurrentFn(HDC hdc, HGLRC hglrc) = 0;
virtual BOOL wglQueryPbufferARBFn(HPBUFFERARB hPbuffer,
int iAttribute,
int* piValue) = 0;
virtual int wglReleasePbufferDCARBFn(HPBUFFERARB hPbuffer, HDC hDC) = 0;
virtual BOOL wglShareListsFn(HGLRC hglrc1, HGLRC hglrc2) = 0;
virtual BOOL wglSwapIntervalEXTFn(int interval) = 0;
virtual BOOL wglSwapLayerBuffersFn(HDC hdc, UINT fuPlanes) = 0;
};
} // namespace gl
#define wglChoosePixelFormatARB \
::gl::g_current_wgl_context->wglChoosePixelFormatARBFn
#define wglCopyContext ::gl::g_current_wgl_context->wglCopyContextFn
#define wglCreateContext ::gl::g_current_wgl_context->wglCreateContextFn
#define wglCreateContextAttribsARB \
::gl::g_current_wgl_context->wglCreateContextAttribsARBFn
#define wglCreateLayerContext \
::gl::g_current_wgl_context->wglCreateLayerContextFn
#define wglCreatePbufferARB ::gl::g_current_wgl_context->wglCreatePbufferARBFn
#define wglDeleteContext ::gl::g_current_wgl_context->wglDeleteContextFn
#define wglDestroyPbufferARB ::gl::g_current_wgl_context->wglDestroyPbufferARBFn
#define wglGetCurrentContext ::gl::g_current_wgl_context->wglGetCurrentContextFn
#define wglGetCurrentDC ::gl::g_current_wgl_context->wglGetCurrentDCFn
#define wglGetExtensionsStringARB \
::gl::g_current_wgl_context->wglGetExtensionsStringARBFn
#define wglGetExtensionsStringEXT \
::gl::g_current_wgl_context->wglGetExtensionsStringEXTFn
#define wglGetPbufferDCARB ::gl::g_current_wgl_context->wglGetPbufferDCARBFn
#define wglMakeCurrent ::gl::g_current_wgl_context->wglMakeCurrentFn
#define wglQueryPbufferARB ::gl::g_current_wgl_context->wglQueryPbufferARBFn
#define wglReleasePbufferDCARB \
::gl::g_current_wgl_context->wglReleasePbufferDCARBFn
#define wglShareLists ::gl::g_current_wgl_context->wglShareListsFn
#define wglSwapIntervalEXT ::gl::g_current_wgl_context->wglSwapIntervalEXTFn
#define wglSwapLayerBuffers ::gl::g_current_wgl_context->wglSwapLayerBuffersFn
#endif // UI_GL_GL_BINDINGS_AUTOGEN_WGL_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file implements the GLContextWGL and PbufferGLContext classes.
#include "ui/gl/gl_context_wgl.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/trace_event/trace_event.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface_wgl.h"
namespace gl {
GLContextWGL::GLContextWGL(GLShareGroup* share_group)
: GLContextReal(share_group), context_(nullptr) {
}
bool GLContextWGL::Initialize(GLSurface* compatible_surface,
const GLContextAttribs& attribs) {
// webgl_compatibility_context and disabling bind_generates_resource are not
// supported.
DCHECK(!attribs.webgl_compatibility_context &&
attribs.bind_generates_resource);
// Get the handle of another initialized context in the share group _before_
// setting context_. Otherwise this context will be considered initialized
// and could potentially be returned by GetHandle.
HGLRC share_handle = static_cast<HGLRC>(share_group()->GetHandle());
HDC device_context = static_cast<HDC>(compatible_surface->GetHandle());
bool has_wgl_create_context_arb =
strstr(wglGetExtensionsStringARB(device_context),
"WGL_ARB_create_context") != nullptr;
bool create_core_profile = has_wgl_create_context_arb &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableES3GLContext);
if (create_core_profile) {
std::pair<int, int> attempt_versions[] = {
{4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2},
};
for (const auto& version : attempt_versions) {
const int attribs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB,
version.first,
WGL_CONTEXT_MINOR_VERSION_ARB,
version.second,
WGL_CONTEXT_PROFILE_MASK_ARB,
WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0,
0,
};
context_ =
wglCreateContextAttribsARB(device_context, share_handle, attribs);
if (context_) {
break;
}
}
}
if (!context_) {
context_ = wglCreateContext(device_context);
}
if (!context_) {
LOG(ERROR) << "Failed to create GL context.";
Destroy();
return false;
}
if (share_handle) {
if (!wglShareLists(share_handle, context_)) {
LOG(ERROR) << "Could not share GL contexts.";
Destroy();
return false;
}
}
return true;
}
void GLContextWGL::Destroy() {
if (context_) {
wglDeleteContext(context_);
context_ = nullptr;
}
}
bool GLContextWGL::MakeCurrentImpl(GLSurface* surface) {
DCHECK(context_);
if (IsCurrent(surface))
return true;
ScopedReleaseCurrent release_current;
TRACE_EVENT0("gpu", "GLContextWGL::MakeCurrent");
if (!wglMakeCurrent(static_cast<HDC>(surface->GetHandle()), context_)) {
LOG(ERROR) << "Unable to make gl context current.";
return false;
}
// Set this as soon as the context is current, since we might call into GL.
BindGLApi();
SetCurrent(surface);
InitializeDynamicBindings();
if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current.";
return false;
}
release_current.Cancel();
return true;
}
void GLContextWGL::ReleaseCurrent(GLSurface* surface) {
if (!IsCurrent(surface))
return;
SetCurrent(nullptr);
wglMakeCurrent(nullptr, nullptr);
}
bool GLContextWGL::IsCurrent(GLSurface* surface) {
bool native_context_is_current =
wglGetCurrentContext() == context_;
// If our context is current then our notion of which GLContext is
// current must be correct. On the other hand, third-party code
// using OpenGL might change the current context.
DCHECK(!native_context_is_current || (GetRealCurrent() == this));
if (!native_context_is_current)
return false;
if (surface) {
if (wglGetCurrentDC() != surface->GetHandle())
return false;
}
return true;
}
void* GLContextWGL::GetHandle() {
return context_;
}
GLContextWGL::~GLContextWGL() {
Destroy();
}
} // namespace gl
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GL_GL_CONTEXT_WGL_H_
#define UI_GL_GL_CONTEXT_WGL_H_
#include <string>
#include "base/macros.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_export.h"
namespace gl {
class GLSurface;
// This class is a wrapper around a GL context.
class GL_EXPORT GLContextWGL : public GLContextReal {
public:
explicit GLContextWGL(GLShareGroup* share_group);
// Implement GLContext.
bool Initialize(GLSurface* compatible_surface,
const GLContextAttribs& attribs) override;
bool MakeCurrentImpl(GLSurface* surface) override;
void ReleaseCurrent(GLSurface* surface) override;
bool IsCurrent(GLSurface* surface) override;
void* GetHandle() override;
private:
~GLContextWGL() override;
void Destroy();
HGLRC context_;
DISALLOW_COPY_AND_ASSIGN(GLContextWGL);
};
} // namespace gl
#endif // UI_GL_GL_CONTEXT_WGL_H_
...@@ -100,10 +100,6 @@ base::ThreadLocalPointer<CurrentGL>* g_current_gl_context_tls = NULL; ...@@ -100,10 +100,6 @@ base::ThreadLocalPointer<CurrentGL>* g_current_gl_context_tls = NULL;
EGLApi* g_current_egl_context; EGLApi* g_current_egl_context;
#endif #endif
#if defined(OS_WIN)
WGLApi* g_current_wgl_context;
#endif
#if defined(USE_GLX) #if defined(USE_GLX)
GLXApi* g_current_glx_context; GLXApi* g_current_glx_context;
#endif #endif
......
This diff is collapsed.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GL_GL_SURFACE_WGL_H_
#define UI_GL_GL_SURFACE_WGL_H_
#include "base/macros.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_export.h"
#include "ui/gl/gl_surface.h"
namespace gl {
// Base interface for WGL surfaces.
class GL_EXPORT GLSurfaceWGL : public GLSurface {
public:
GLSurfaceWGL();
// Implement GLSurface.
void* GetDisplay() override;
static bool InitializeOneOff();
static bool InitializeExtensionSettingsOneOff();
static void InitializeOneOffForTesting();
static HDC GetDisplayDC();
protected:
~GLSurfaceWGL() override;
private:
DISALLOW_COPY_AND_ASSIGN(GLSurfaceWGL);
static bool initialized_;
};
// A surface used to render to a view.
class GL_EXPORT NativeViewGLSurfaceWGL : public GLSurfaceWGL {
public:
explicit NativeViewGLSurfaceWGL(gfx::AcceleratedWidget window);
// Implement GLSurface.
bool Initialize(GLSurfaceFormat format) override;
void Destroy() override;
bool Resize(const gfx::Size& size,
float scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha) override;
bool Recreate() override;
bool IsOffscreen() override;
gfx::SwapResult SwapBuffers(PresentationCallback callback) override;
gfx::Size GetSize() override;
void* GetHandle() override;
GLSurfaceFormat GetFormat() override;
void SetVSyncEnabled(bool enabled) override;
private:
~NativeViewGLSurfaceWGL() override;
GLSurfaceFormat format_;
gfx::AcceleratedWidget window_;
gfx::AcceleratedWidget child_window_;
HDC device_context_;
DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceWGL);
};
// A surface used to render to an offscreen pbuffer.
class GL_EXPORT PbufferGLSurfaceWGL : public GLSurfaceWGL {
public:
explicit PbufferGLSurfaceWGL(const gfx::Size& size);
// Implement GLSurface.
bool Initialize(GLSurfaceFormat format) override;
void Destroy() override;
bool IsOffscreen() override;
gfx::SwapResult SwapBuffers(PresentationCallback callback) override;
gfx::Size GetSize() override;
void* GetHandle() override;
GLSurfaceFormat GetFormat() override;
private:
~PbufferGLSurfaceWGL() override;
gfx::Size size_;
HDC device_context_;
void* pbuffer_;
DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceWGL);
};
} // namespace gl
#endif // UI_GL_GL_SURFACE_WGL_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gl/gl_wgl_api_implementation.h"
#include "base/command_line.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_implementation_wrapper.h"
#include "ui/gl/gl_surface_wgl.h"
namespace gl {
RealWGLApi* g_real_wgl = nullptr;
GL_IMPL_WRAPPER_TYPE(WGL) * g_wgl_wrapper = nullptr;
void InitializeStaticGLBindingsWGL() {
g_driver_wgl.InitializeStaticBindings();
if (!g_wgl_wrapper) {
auto real_api = std::make_unique<RealWGLApi>();
real_api->Initialize(&g_driver_wgl);
g_wgl_wrapper = new GL_IMPL_WRAPPER_TYPE(WGL)(std::move(real_api));
}
g_current_wgl_context = g_wgl_wrapper->api();
}
void ClearBindingsWGL() {
delete g_wgl_wrapper;
g_wgl_wrapper = nullptr;
g_current_wgl_context = nullptr;
g_driver_wgl.ClearBindings();
}
WGLApi::WGLApi() {
}
WGLApi::~WGLApi() {
}
WGLApiBase::WGLApiBase() : driver_(nullptr) {}
WGLApiBase::~WGLApiBase() {
}
void WGLApiBase::InitializeBase(DriverWGL* driver) {
driver_ = driver;
}
RealWGLApi::RealWGLApi() {
}
RealWGLApi::~RealWGLApi() {
}
void RealWGLApi::Initialize(DriverWGL* driver) {
InitializeBase(driver);
}
void RealWGLApi::SetDisabledExtensions(const std::string& disabled_extensions) {
disabled_exts_.clear();
filtered_ext_exts_ = "";
filtered_arb_exts_ = "";
if (!disabled_extensions.empty()) {
disabled_exts_ =
base::SplitString(disabled_extensions, ", ;",
base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
}
}
const char* RealWGLApi::wglGetExtensionsStringARBFn(HDC hDC) {
if (filtered_arb_exts_.size())
return filtered_arb_exts_.c_str();
if (!driver_->fn.wglGetExtensionsStringARBFn)
return nullptr;
const char* str = WGLApiBase::wglGetExtensionsStringARBFn(hDC);
if (!str)
return nullptr;
filtered_arb_exts_ = FilterGLExtensionList(str, disabled_exts_);
return filtered_arb_exts_.c_str();
}
const char* RealWGLApi::wglGetExtensionsStringEXTFn() {
if (filtered_ext_exts_.size())
return filtered_ext_exts_.c_str();
if (!driver_->fn.wglGetExtensionsStringEXTFn)
return nullptr;
const char* str = WGLApiBase::wglGetExtensionsStringEXTFn();
if (!str)
return nullptr;
filtered_ext_exts_ = FilterGLExtensionList(str, disabled_exts_);
return filtered_ext_exts_.c_str();
}
LogWGLApi::LogWGLApi(WGLApi* wgl_api) : wgl_api_(wgl_api) {}
LogWGLApi::~LogWGLApi() {}
void LogWGLApi::SetDisabledExtensions(const std::string& disabled_extensions) {
if (wgl_api_) {
wgl_api_->SetDisabledExtensions(disabled_extensions);
}
}
TraceWGLApi::~TraceWGLApi() {
}
void TraceWGLApi::SetDisabledExtensions(
const std::string& disabled_extensions) {
if (wgl_api_) {
wgl_api_->SetDisabledExtensions(disabled_extensions);
}
}
bool GetGLWindowSystemBindingInfoWGL(GLWindowSystemBindingInfo* info) {
const char* extensions = wglGetExtensionsStringEXT();
*info = GLWindowSystemBindingInfo();
if (extensions)
info->extensions = extensions;
return true;
}
void SetDisabledExtensionsWGL(const std::string& disabled_extensions) {
DCHECK(g_current_wgl_context);
DCHECK(GLContext::TotalGLContexts() == 0);
g_current_wgl_context->SetDisabledExtensions(disabled_extensions);
}
bool InitializeExtensionSettingsOneOffWGL() {
return GLSurfaceWGL::InitializeExtensionSettingsOneOff();
}
} // namespace gl
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GL_GL_WGL_API_IMPLEMENTATION_H_
#define UI_GL_GL_WGL_API_IMPLEMENTATION_H_
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_export.h"
namespace gl {
struct GLWindowSystemBindingInfo;
GL_EXPORT void InitializeStaticGLBindingsWGL();
GL_EXPORT void ClearBindingsWGL();
GL_EXPORT bool GetGLWindowSystemBindingInfoWGL(GLWindowSystemBindingInfo* info);
GL_EXPORT void SetDisabledExtensionsWGL(const std::string& disabled_extensions);
GL_EXPORT bool InitializeExtensionSettingsOneOffWGL();
class GL_EXPORT WGLApiBase : public WGLApi {
public:
// Include the auto-generated part of this class. We split this because
// it means we can easily edit the non-auto generated parts right here in
// this file instead of having to edit some template or the code generator.
#include "gl_bindings_api_autogen_wgl.h"
protected:
WGLApiBase();
~WGLApiBase() override;
void InitializeBase(DriverWGL* driver);
DriverWGL* driver_;
};
class GL_EXPORT RealWGLApi : public WGLApiBase {
public:
RealWGLApi();
~RealWGLApi() override;
void Initialize(DriverWGL* driver);
void SetDisabledExtensions(const std::string& disabled_extensions) override;
const char* wglGetExtensionsStringARBFn(HDC hDC) override;
const char* wglGetExtensionsStringEXTFn() override;
private:
std::vector<std::string> disabled_exts_;
std::string filtered_arb_exts_;
std::string filtered_ext_exts_;
};
// Logs debug information for every WGL call.
class GL_EXPORT LogWGLApi : public WGLApi {
public:
LogWGLApi(WGLApi* wgl_api);
~LogWGLApi() override;
void SetDisabledExtensions(const std::string& disabled_extensions) override;
// Include the auto-generated part of this class. We split this because
// it means we can easily edit the non-auto generated parts right here in
// this file instead of having to edit some template or the code generator.
#include "gl_bindings_api_autogen_wgl.h"
private:
WGLApi* wgl_api_;
};
// Inserts a TRACE for every WGL call.
class GL_EXPORT TraceWGLApi : public WGLApi {
public:
TraceWGLApi(WGLApi* wgl_api) : wgl_api_(wgl_api) { }
~TraceWGLApi() override;
void SetDisabledExtensions(const std::string& disabled_extensions) override;
// Include the auto-generated part of this class. We split this because
// it means we can easily edit the non-auto generated parts right here in
// this file instead of having to edit some template or the code generator.
#include "gl_bindings_api_autogen_wgl.h"
private:
WGLApi* wgl_api_;
};
} // namespace gl
#endif // UI_GL_GL_WGL_API_IMPLEMENTATION_H_
...@@ -10,15 +10,12 @@ ...@@ -10,15 +10,12 @@
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_context_egl.h" #include "ui/gl/gl_context_egl.h"
#include "ui/gl/gl_context_stub.h" #include "ui/gl/gl_context_stub.h"
#include "ui/gl/gl_context_wgl.h"
#include "ui/gl/gl_egl_api_implementation.h" #include "ui/gl/gl_egl_api_implementation.h"
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_share_group.h" #include "ui/gl/gl_share_group.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "ui/gl/gl_surface_egl.h" #include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_stub.h" #include "ui/gl/gl_surface_stub.h"
#include "ui/gl/gl_surface_wgl.h"
#include "ui/gl/gl_wgl_api_implementation.h"
#include "ui/gl/vsync_provider_win.h" #include "ui/gl/vsync_provider_win.h"
namespace gl { namespace gl {
...@@ -27,7 +24,6 @@ namespace init { ...@@ -27,7 +24,6 @@ namespace init {
std::vector<GLImplementation> GetAllowedGLImplementations() { std::vector<GLImplementation> GetAllowedGLImplementations() {
std::vector<GLImplementation> impls; std::vector<GLImplementation> impls;
impls.push_back(kGLImplementationEGLANGLE); impls.push_back(kGLImplementationEGLANGLE);
impls.push_back(kGLImplementationDesktopGL);
impls.push_back(kGLImplementationSwiftShaderGL); impls.push_back(kGLImplementationSwiftShaderGL);
return impls; return impls;
} }
...@@ -35,8 +31,6 @@ std::vector<GLImplementation> GetAllowedGLImplementations() { ...@@ -35,8 +31,6 @@ std::vector<GLImplementation> GetAllowedGLImplementations() {
bool GetGLWindowSystemBindingInfo(const GLVersionInfo& gl_info, bool GetGLWindowSystemBindingInfo(const GLVersionInfo& gl_info,
GLWindowSystemBindingInfo* info) { GLWindowSystemBindingInfo* info) {
switch (GetGLImplementation()) { switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
return GetGLWindowSystemBindingInfoWGL(info);
case kGLImplementationEGLANGLE: case kGLImplementationEGLANGLE:
return GetGLWindowSystemBindingInfoEGL(info); return GetGLWindowSystemBindingInfoEGL(info);
default: default:
...@@ -53,9 +47,6 @@ scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, ...@@ -53,9 +47,6 @@ scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group,
case kGLImplementationEGLANGLE: case kGLImplementationEGLANGLE:
return InitializeGLContext(new GLContextEGL(share_group), return InitializeGLContext(new GLContextEGL(share_group),
compatible_surface, attribs); compatible_surface, attribs);
case kGLImplementationDesktopGL:
return InitializeGLContext(new GLContextWGL(share_group),
compatible_surface, attribs);
case kGLImplementationMockGL: case kGLImplementationMockGL:
return new GLContextStub(share_group); return new GLContextStub(share_group);
case kGLImplementationStubGL: { case kGLImplementationStubGL: {
...@@ -79,9 +70,6 @@ scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { ...@@ -79,9 +70,6 @@ scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) {
return InitializeGLSurface(base::MakeRefCounted<NativeViewGLSurfaceEGL>( return InitializeGLSurface(base::MakeRefCounted<NativeViewGLSurfaceEGL>(
window, std::make_unique<VSyncProviderWin>(window))); window, std::make_unique<VSyncProviderWin>(window)));
} }
case kGLImplementationDesktopGL:
return InitializeGLSurface(
base::MakeRefCounted<NativeViewGLSurfaceWGL>(window));
case kGLImplementationMockGL: case kGLImplementationMockGL:
case kGLImplementationStubGL: case kGLImplementationStubGL:
return new GLSurfaceStub; return new GLSurfaceStub;
...@@ -104,9 +92,6 @@ scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat( ...@@ -104,9 +92,6 @@ scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat(
return InitializeGLSurfaceWithFormat(new PbufferGLSurfaceEGL(size), return InitializeGLSurfaceWithFormat(new PbufferGLSurfaceEGL(size),
format); format);
} }
case kGLImplementationDesktopGL:
return InitializeGLSurfaceWithFormat(
new PbufferGLSurfaceWGL(size), format);
case kGLImplementationMockGL: case kGLImplementationMockGL:
case kGLImplementationStubGL: case kGLImplementationStubGL:
return new GLSurfaceStub; return new GLSurfaceStub;
...@@ -120,9 +105,6 @@ void SetDisabledExtensionsPlatform(const std::string& disabled_extensions) { ...@@ -120,9 +105,6 @@ void SetDisabledExtensionsPlatform(const std::string& disabled_extensions) {
GLImplementation implementation = GetGLImplementation(); GLImplementation implementation = GetGLImplementation();
DCHECK_NE(kGLImplementationNone, implementation); DCHECK_NE(kGLImplementationNone, implementation);
switch (implementation) { switch (implementation) {
case kGLImplementationDesktopGL:
SetDisabledExtensionsWGL(disabled_extensions);
break;
case kGLImplementationEGLANGLE: case kGLImplementationEGLANGLE:
SetDisabledExtensionsEGL(disabled_extensions); SetDisabledExtensionsEGL(disabled_extensions);
break; break;
...@@ -139,8 +121,6 @@ bool InitializeExtensionSettingsOneOffPlatform() { ...@@ -139,8 +121,6 @@ bool InitializeExtensionSettingsOneOffPlatform() {
GLImplementation implementation = GetGLImplementation(); GLImplementation implementation = GetGLImplementation();
DCHECK_NE(kGLImplementationNone, implementation); DCHECK_NE(kGLImplementationNone, implementation);
switch (implementation) { switch (implementation) {
case kGLImplementationDesktopGL:
return InitializeExtensionSettingsOneOffWGL();
case kGLImplementationEGLANGLE: case kGLImplementationEGLANGLE:
return InitializeExtensionSettingsOneOffEGL(); return InitializeExtensionSettingsOneOffEGL();
case kGLImplementationSwiftShaderGL: case kGLImplementationSwiftShaderGL:
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
#include "ui/gl/gl_egl_api_implementation.h" #include "ui/gl/gl_egl_api_implementation.h"
#include "ui/gl/gl_gl_api_implementation.h" #include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_surface_egl.h" #include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_wgl.h"
#include "ui/gl/gl_wgl_api_implementation.h"
#include "ui/gl/vsync_provider_win.h" #include "ui/gl/vsync_provider_win.h"
namespace gl { namespace gl {
...@@ -113,83 +111,12 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) { ...@@ -113,83 +111,12 @@ bool InitializeStaticEGLInternal(GLImplementation implementation) {
return true; return true;
} }
bool InitializeStaticWGLInternal() {
base::NativeLibrary library =
base::LoadNativeLibrary(base::FilePath(L"opengl32.dll"), nullptr);
if (!library) {
DVLOG(1) << "opengl32.dll not found";
return false;
}
GLGetProcAddressProc get_proc_address =
reinterpret_cast<GLGetProcAddressProc>(
base::GetFunctionPointerFromNativeLibrary(library,
"wglGetProcAddress"));
if (!get_proc_address) {
LOG(ERROR) << "wglGetProcAddress not found.";
base::UnloadNativeLibrary(library);
return false;
}
SetGLGetProcAddressProc(get_proc_address);
AddGLNativeLibrary(library);
SetGLImplementation(kGLImplementationDesktopGL);
// Initialize GL surface and get some functions needed for the context
// creation below.
if (!GLSurfaceWGL::InitializeOneOff()) {
LOG(ERROR) << "GLSurfaceWGL::InitializeOneOff failed.";
return false;
}
wglCreateContextProc wglCreateContextFn =
reinterpret_cast<wglCreateContextProc>(
GetGLProcAddress("wglCreateContext"));
wglDeleteContextProc wglDeleteContextFn =
reinterpret_cast<wglDeleteContextProc>(
GetGLProcAddress("wglDeleteContext"));
wglMakeCurrentProc wglMakeCurrentFn =
reinterpret_cast<wglMakeCurrentProc>(GetGLProcAddress("wglMakeCurrent"));
// Create a temporary GL context to bind to entry points. This is needed
// because wglGetProcAddress is specified to return nullptr for all queries
// if a context is not current in MSDN documentation, and the static
// bindings may contain functions that need to be queried with
// wglGetProcAddress. OpenGL wiki further warns that other error values
// than nullptr could also be returned from wglGetProcAddress on some
// implementations, so we need to clear the WGL bindings and reinitialize
// them after the context creation.
HGLRC gl_context = wglCreateContextFn(GLSurfaceWGL::GetDisplayDC());
if (!gl_context) {
LOG(ERROR) << "Failed to create temporary context.";
return false;
}
if (!wglMakeCurrentFn(GLSurfaceWGL::GetDisplayDC(), gl_context)) {
LOG(ERROR) << "Failed to make temporary GL context current.";
wglDeleteContextFn(gl_context);
return false;
}
InitializeStaticGLBindingsGL();
InitializeStaticGLBindingsWGL();
wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(gl_context);
return true;
}
} // namespace } // namespace
bool InitializeGLOneOffPlatform() { bool InitializeGLOneOffPlatform() {
VSyncProviderWin::InitializeOneOff(); VSyncProviderWin::InitializeOneOff();
switch (GetGLImplementation()) { switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
if (!GLSurfaceWGL::InitializeOneOff()) {
LOG(ERROR) << "GLSurfaceWGL::InitializeOneOff failed.";
return false;
}
break;
case kGLImplementationSwiftShaderGL: case kGLImplementationSwiftShaderGL:
case kGLImplementationEGLANGLE: case kGLImplementationEGLANGLE:
if (!GLSurfaceEGL::InitializeOneOff(EGLDisplayPlatform(GetDC(nullptr)))) { if (!GLSurfaceEGL::InitializeOneOff(EGLDisplayPlatform(GetDC(nullptr)))) {
...@@ -222,8 +149,6 @@ bool InitializeStaticGLBindings(GLImplementation implementation) { ...@@ -222,8 +149,6 @@ bool InitializeStaticGLBindings(GLImplementation implementation) {
case kGLImplementationSwiftShaderGL: case kGLImplementationSwiftShaderGL:
case kGLImplementationEGLANGLE: case kGLImplementationEGLANGLE:
return InitializeStaticEGLInternal(implementation); return InitializeStaticEGLInternal(implementation);
case kGLImplementationDesktopGL:
return InitializeStaticWGLInternal();
case kGLImplementationMockGL: case kGLImplementationMockGL:
case kGLImplementationStubGL: case kGLImplementationStubGL:
SetGLImplementation(implementation); SetGLImplementation(implementation);
...@@ -240,7 +165,6 @@ void ShutdownGLPlatform() { ...@@ -240,7 +165,6 @@ void ShutdownGLPlatform() {
GLSurfaceEGL::ShutdownOneOff(); GLSurfaceEGL::ShutdownOneOff();
ClearBindingsEGL(); ClearBindingsEGL();
ClearBindingsGL(); ClearBindingsGL();
ClearBindingsWGL();
} }
} // namespace init } // namespace init
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/command_line.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface_wgl.h"
#include "ui/gl/gl_wgl_api_implementation.h"
typedef std::pair<std::string, std::string> stringpair;
namespace gl {
class WGLApiTest : public testing::Test {
public:
void SetUp() override {
GLSurfaceWGL::InitializeOneOffForTesting();
fake_arb_extension_string_ = "";
fake_ext_extension_string_ = "";
g_driver_wgl.ClearBindings();
g_driver_wgl.fn.wglGetExtensionsStringARBFn = &FakeGetExtensionsStringARB;
g_driver_wgl.fn.wglGetExtensionsStringEXTFn = &FakeGetExtensionsStringEXT;
SetGLImplementation(kGLImplementationDesktopGL);
SetGLGetProcAddressProc(&FakeGLGetProcAddress);
}
void TearDown() override {
g_current_wgl_context = nullptr;
api_.reset(nullptr);
g_driver_wgl.ClearBindings();
fake_ext_extension_string_ = "";
fake_arb_extension_string_ = "";
}
void InitializeAPI(const char* disabled_extensions) {
api_ = std::make_unique<RealWGLApi>();
g_current_wgl_context = api_.get();
api_->Initialize(&g_driver_wgl);
if (disabled_extensions) {
SetDisabledExtensionsWGL(disabled_extensions);
}
g_driver_wgl.InitializeExtensionBindings();
}
void SetFakeEXTExtensionString(const char* fake_string) {
fake_ext_extension_string_ = fake_string;
}
void SetFakeARBExtensionString(const char* fake_string) {
fake_arb_extension_string_ = fake_string;
}
stringpair GetExtensions() {
auto stringify = [](const char* str) -> std::string {
return str ? str : "";
};
return stringpair(
stringify(wglGetExtensionsStringARB(NULL)),
stringify(wglGetExtensionsStringEXT()));
}
static GLFunctionPointerType WINAPI FakeGLGetProcAddress(const char* proc) {
return NULL;
}
static const char* GL_BINDING_CALL FakeGetExtensionsStringARB(HDC dc) {
return fake_arb_extension_string_;
}
static const char* GL_BINDING_CALL FakeGetExtensionsStringEXT() {
return fake_ext_extension_string_;
}
protected:
static const char* fake_ext_extension_string_;
static const char* fake_arb_extension_string_;
std::unique_ptr<RealWGLApi> api_;
};
const char* WGLApiTest::fake_ext_extension_string_ = "";
const char* WGLApiTest::fake_arb_extension_string_ = "";
TEST_F(WGLApiTest, DisabledExtensionBitTest) {
static const char* kFakeExtensions = "WGL_ARB_extensions_string";
static const char* kFakeDisabledExtensions = "WGL_ARB_extensions_string";
InitializeAPI(nullptr);
EXPECT_FALSE(g_driver_wgl.ext.b_WGL_ARB_extensions_string);
// NULL simulates not being able to resolve wglGetExtensionsStringARB
SetFakeARBExtensionString(nullptr);
SetFakeEXTExtensionString(kFakeExtensions);
InitializeAPI(nullptr);
EXPECT_TRUE(g_driver_wgl.ext.b_WGL_ARB_extensions_string);
InitializeAPI(kFakeExtensions);
EXPECT_FALSE(g_driver_wgl.ext.b_WGL_ARB_extensions_string);
SetFakeARBExtensionString("");
SetFakeEXTExtensionString(kFakeExtensions);
InitializeAPI(nullptr);
// We expect false here, because wglGetExtensionsStringARB
// always takes precedence over wglGetExtensionsStringEXT
// if it is available.
EXPECT_FALSE(g_driver_wgl.ext.b_WGL_ARB_extensions_string);
SetFakeARBExtensionString(kFakeExtensions);
SetFakeEXTExtensionString("");
InitializeAPI(nullptr);
EXPECT_TRUE(g_driver_wgl.ext.b_WGL_ARB_extensions_string);
InitializeAPI(kFakeDisabledExtensions);
EXPECT_FALSE(g_driver_wgl.ext.b_WGL_ARB_extensions_string);
}
TEST_F(WGLApiTest, DisabledExtensionStringTest) {
static const char* kFakeExtensions = "EGL_EXT_1 EGL_EXT_2"
" EGL_EXT_3 EGL_EXT_4";
static const char* kFakeDisabledExtensions =
"EGL_EXT_1,EGL_EXT_2,EGL_FAKE";
static const char* kFilteredExtensions = "EGL_EXT_3 EGL_EXT_4";
SetFakeARBExtensionString(kFakeExtensions);
SetFakeEXTExtensionString(kFakeExtensions);
InitializeAPI(nullptr);
EXPECT_EQ(stringpair(kFakeExtensions, kFakeExtensions),
GetExtensions());
InitializeAPI(kFakeDisabledExtensions);
EXPECT_EQ(stringpair(kFilteredExtensions, kFilteredExtensions),
GetExtensions());
}
} // namespace gl
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