2
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
6
// entry_points_wgl.cpp: Implements the exported WGL functions.
8
#include "entry_points_wgl.h"
10
#include "common/debug.h"
11
#include "common/event_tracer.h"
12
#include "common/utilities.h"
13
#include "common/version.h"
14
#include "libANGLE/Context.h"
15
#include "libANGLE/Display.h"
16
#include "libANGLE/EGLSync.h"
17
#include "libANGLE/Surface.h"
18
#include "libANGLE/Texture.h"
19
#include "libANGLE/Thread.h"
20
#include "libANGLE/entry_points_utils.h"
21
#include "libANGLE/queryutils.h"
22
#include "libANGLE/validationEGL.h"
23
#include "libGL/proc_table_wgl.h"
24
#include "libGLESv2/global_state.h"
32
bool CompareProc(const ProcEntry &a, const char *b)
34
return strcmp(a.first, b) < 0;
37
void ClipConfigs(const std::vector<const Config *> &filteredConfigs,
38
EGLConfig *output_configs,
42
EGLint result_size = static_cast<EGLint>(filteredConfigs.size());
45
result_size = std::max(std::min(result_size, config_size), 0);
46
for (EGLint i = 0; i < result_size; i++)
48
output_configs[i] = const_cast<Config *>(filteredConfigs[i]);
51
*num_config = result_size;
53
} // anonymous namespace
58
int GL_APIENTRY wglChoosePixelFormat(HDC hDc, const PIXELFORMATDESCRIPTOR *pPfd)
64
int GL_APIENTRY wglDescribePixelFormat(HDC hdc, int ipfd, UINT cjpfd, PIXELFORMATDESCRIPTOR *ppfd)
69
ppfd->dwFlags = ppfd->dwFlags | PFD_DRAW_TO_WINDOW;
70
ppfd->dwFlags = ppfd->dwFlags | PFD_SUPPORT_OPENGL;
71
ppfd->dwFlags = ppfd->dwFlags | PFD_GENERIC_ACCELERATED;
72
ppfd->dwFlags = ppfd->dwFlags | PFD_DOUBLEBUFFER;
73
ppfd->iPixelType = PFD_TYPE_RGBA;
74
ppfd->cColorBits = 24;
79
ppfd->cDepthBits = 24;
80
ppfd->cStencilBits = 8;
86
UINT GL_APIENTRY wglGetEnhMetaFilePixelFormat(HENHMETAFILE hemf,
88
PIXELFORMATDESCRIPTOR *ppfd)
94
int GL_APIENTRY wglGetPixelFormat(HDC hdc)
100
BOOL GL_APIENTRY wglSetPixelFormat(HDC hdc, int ipfd, const PIXELFORMATDESCRIPTOR *ppfd)
106
BOOL GL_APIENTRY wglSwapBuffers(HDC hdc)
108
Thread *thread = egl::GetCurrentThread();
109
egl::Display *display = egl::Display::GetExistingDisplayFromNativeDisplay(hdc);
111
ANGLE_EGL_TRY_RETURN(thread, display->getWGLSurface()->swap(thread->getContext()),
112
"wglSwapBuffers", display->getWGLSurface(), FALSE);
116
BOOL GL_APIENTRY wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
122
HGLRC GL_APIENTRY wglCreateContext(HDC hDc)
124
Thread *thread = egl::GetCurrentThread();
126
std::vector<EGLAttrib> displayAttributes;
127
displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
128
GLenum platformType = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
129
displayAttributes.push_back(platformType);
130
displayAttributes.push_back(EGL_NONE);
132
const auto &attribMapDisplay = AttributeMap::CreateFromAttribArray(displayAttributes.data());
134
egl::Display *display = egl::Display::GetDisplayFromNativeDisplay(hDc, attribMapDisplay);
136
ANGLE_EGL_TRY_RETURN(thread, display->initialize(), "wglCreateContext", display, nullptr);
138
thread->setAPI(EGL_OPENGL_API);
141
const EGLint configAttributes[] = {EGL_NONE};
146
AttributeMap attribMapConfig = AttributeMap::CreateFromIntArray(configAttributes);
147
ClipConfigs(display->chooseConfig(attribMapConfig), &config, 1, &configCount);
149
Config *configuration = static_cast<Config *>(config);
151
// Initialize surface
152
std::vector<EGLint> surfaceAttributes;
153
surfaceAttributes.push_back(EGL_NONE);
154
surfaceAttributes.push_back(EGL_NONE);
155
AttributeMap surfAttributes = AttributeMap::CreateFromIntArray(&surfaceAttributes[0]);
157
// Create first window surface
158
egl::Surface *surface = nullptr;
159
ANGLE_EGL_TRY_RETURN(
161
display->createWindowSurface(configuration, WindowFromDC(hDc), surfAttributes, &surface),
162
"wglCreateContext", display, nullptr);
164
// Initialize context
165
EGLint contextAttibutes[] = {EGL_CONTEXT_CLIENT_VERSION, 4, EGL_CONTEXT_MINOR_VERSION, 6,
168
gl::Context *sharedGLContext = static_cast<gl::Context *>(nullptr);
169
AttributeMap ctxAttributes = AttributeMap::CreateFromIntArray(contextAttibutes);
171
gl::Context *context = nullptr;
173
ANGLE_EGL_TRY_RETURN(thread,
174
display->createContext(configuration, sharedGLContext, EGL_OPENGL_API,
175
ctxAttributes, &context),
176
"wglCreateContext", display, nullptr);
178
return reinterpret_cast<HGLRC>(context);
181
HGLRC GL_APIENTRY wglCreateLayerContext(HDC hDc, int level)
187
BOOL GL_APIENTRY wglDeleteContext(HGLRC oldContext)
193
BOOL GL_APIENTRY wglDescribeLayerPlane(HDC hDc,
197
LAYERPLANEDESCRIPTOR *plpd)
203
HGLRC GL_APIENTRY wglGetCurrentContext()
209
HDC GL_APIENTRY wglGetCurrentDC()
216
wglGetLayerPaletteEntries(HDC hdc, int iLayerPlane, int iStart, int cEntries, COLORREF *pcr)
222
PROC GL_APIENTRY wglGetProcAddress(LPCSTR lpszProc)
224
ANGLE_SCOPED_GLOBAL_LOCK();
225
FUNC_EVENT("const char *procname = \"%s\"", lpszProc);
226
egl::Thread *thread = egl::GetCurrentThread();
229
std::lower_bound(&g_procTable[0], &g_procTable[g_numProcs], lpszProc, CompareProc);
231
thread->setSuccess();
233
if (entry == &g_procTable[g_numProcs] || strcmp(entry->first, lpszProc) != 0)
238
return entry->second;
241
BOOL GL_APIENTRY wglMakeCurrent(HDC hDc, HGLRC newContext)
243
Thread *thread = egl::GetCurrentThread();
244
egl::Display *display = egl::Display::GetExistingDisplayFromNativeDisplay(hDc);
245
const gl::Context *context =
246
GetContextIfValid(display, reinterpret_cast<gl::Context *>(newContext));
248
// If display or context are invalid, make thread's current rendering context not current
251
gl::Context *oldContext = thread->getContext();
254
ANGLE_EGL_TRY_RETURN(thread, oldContext->unMakeCurrent(display), "wglMakeCurrent",
255
GetContextIfValid(display, oldContext), EGL_FALSE);
257
SetContextCurrent(thread, nullptr);
261
egl::Surface *surface = display->getWGLSurface();
262
Surface *previousDraw = thread->getCurrentDrawSurface();
263
Surface *previousRead = thread->getCurrentReadSurface();
264
gl::Context *previousContext = thread->getContext();
266
if (previousDraw != surface || previousRead != surface || previousContext != context)
268
ANGLE_EGL_TRY_RETURN(
270
display->makeCurrent(thread, surface, surface, const_cast<gl::Context *>(context)),
271
"wglMakeCurrent", GetContextIfValid(display, context), EGL_FALSE);
273
SetContextCurrent(thread, const_cast<gl::Context *>(context));
279
BOOL GL_APIENTRY wglRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
286
wglSetLayerPaletteEntries(HDC hdc, int iLayerPlane, int iStart, int cEntries, const COLORREF *pcr)
292
BOOL GL_APIENTRY wglShareLists(HGLRC hrcSrvShare, HGLRC hrcSrvSource)
298
BOOL GL_APIENTRY wglSwapLayerBuffers(HDC hdc, UINT fuFlags)
304
BOOL GL_APIENTRY wglUseFontBitmapsA(HDC hDC, DWORD first, DWORD count, DWORD listBase)
310
BOOL GL_APIENTRY wglUseFontBitmapsW(HDC hDC, DWORD first, DWORD count, DWORD listBase)
316
BOOL GL_APIENTRY wglUseFontOutlinesA(HDC hDC,
323
LPGLYPHMETRICSFLOAT lpgmf)
329
BOOL GL_APIENTRY wglUseFontOutlinesW(HDC hDC,
336
LPGLYPHMETRICSFLOAT lpgmf)