Path: blob/main_old/src/libGL/entry_points_wgl.cpp
1693 views
//1// Copyright 2019 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// entry_points_wgl.cpp: Implements the exported WGL functions.67#include "entry_points_wgl.h"89#include "common/angle_version.h"10#include "common/debug.h"11#include "common/event_tracer.h"12#include "common/utilities.h"13#include "libANGLE/Context.h"14#include "libANGLE/Display.h"15#include "libANGLE/EGLSync.h"16#include "libANGLE/Surface.h"17#include "libANGLE/Texture.h"18#include "libANGLE/Thread.h"19#include "libANGLE/entry_points_utils.h"20#include "libANGLE/queryutils.h"21#include "libANGLE/validationEGL.h"22#include "libGL/proc_table_wgl.h"23#include "libGLESv2/global_state.h"2425using namespace wgl;26using namespace egl;2728namespace29{3031bool CompareProc(const ProcEntry &a, const char *b)32{33return strcmp(a.first, b) < 0;34}3536void ClipConfigs(const std::vector<const Config *> &filteredConfigs,37EGLConfig *output_configs,38EGLint config_size,39EGLint *num_config)40{41EGLint result_size = static_cast<EGLint>(filteredConfigs.size());42if (output_configs)43{44result_size = std::max(std::min(result_size, config_size), 0);45for (EGLint i = 0; i < result_size; i++)46{47output_configs[i] = const_cast<Config *>(filteredConfigs[i]);48}49}50*num_config = result_size;51}52} // anonymous namespace5354#define WGL_EVENT(EP, FMT, ...) EVENT(nullptr, WGL##EP, FMT, __VA_ARGS__)5556extern "C" {5758// WGL 1.059int GL_APIENTRY wglChoosePixelFormat(HDC hDc, const PIXELFORMATDESCRIPTOR *pPfd)60{61UNIMPLEMENTED();62return 1;63}6465int GL_APIENTRY wglDescribePixelFormat(HDC hdc, int ipfd, UINT cjpfd, PIXELFORMATDESCRIPTOR *ppfd)66{67UNIMPLEMENTED();68if (ppfd)69{70ppfd->dwFlags = ppfd->dwFlags | PFD_DRAW_TO_WINDOW;71ppfd->dwFlags = ppfd->dwFlags | PFD_SUPPORT_OPENGL;72ppfd->dwFlags = ppfd->dwFlags | PFD_GENERIC_ACCELERATED;73ppfd->dwFlags = ppfd->dwFlags | PFD_DOUBLEBUFFER;74ppfd->iPixelType = PFD_TYPE_RGBA;75ppfd->cColorBits = 24;76ppfd->cRedBits = 8;77ppfd->cGreenBits = 8;78ppfd->cBlueBits = 8;79ppfd->cAlphaBits = 8;80ppfd->cDepthBits = 24;81ppfd->cStencilBits = 8;82ppfd->nVersion = 1;83}84return 1;85}8687UINT GL_APIENTRY wglGetEnhMetaFilePixelFormat(HENHMETAFILE hemf,88UINT cbBuffer,89PIXELFORMATDESCRIPTOR *ppfd)90{91UNIMPLEMENTED();92return 1u;93}9495int GL_APIENTRY wglGetPixelFormat(HDC hdc)96{97UNIMPLEMENTED();98return 1;99}100101BOOL GL_APIENTRY wglSetPixelFormat(HDC hdc, int ipfd, const PIXELFORMATDESCRIPTOR *ppfd)102{103UNIMPLEMENTED();104return TRUE;105}106107BOOL GL_APIENTRY wglSwapBuffers(HDC hdc)108{109Thread *thread = egl::GetCurrentThread();110egl::Display *display = egl::Display::GetExistingDisplayFromNativeDisplay(hdc);111112ANGLE_EGL_TRY_RETURN(thread, display->getWGLSurface()->swap(thread->getContext()),113"wglSwapBuffers", display->getWGLSurface(), FALSE);114return TRUE;115}116117BOOL GL_APIENTRY wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)118{119UNIMPLEMENTED();120return TRUE;121}122123HGLRC GL_APIENTRY wglCreateContext(HDC hDc)124{125Thread *thread = egl::GetCurrentThread();126127std::vector<EGLAttrib> displayAttributes;128displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);129GLenum platformType = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;130displayAttributes.push_back(platformType);131displayAttributes.push_back(EGL_NONE);132133const auto &attribMapDisplay = AttributeMap::CreateFromAttribArray(displayAttributes.data());134135egl::Display *display = egl::Display::GetDisplayFromNativeDisplay(hDc, attribMapDisplay);136137ANGLE_EGL_TRY_RETURN(thread, display->initialize(), "wglCreateContext", display, nullptr);138139thread->setAPI(EGL_OPENGL_API);140141// Default config142const EGLint configAttributes[] = {EGL_NONE};143144// Choose config145EGLint configCount;146EGLConfig config;147AttributeMap attribMapConfig = AttributeMap::CreateFromIntArray(configAttributes);148ClipConfigs(display->chooseConfig(attribMapConfig), &config, 1, &configCount);149150Config *configuration = static_cast<Config *>(config);151152// Initialize surface153std::vector<EGLint> surfaceAttributes;154surfaceAttributes.push_back(EGL_NONE);155surfaceAttributes.push_back(EGL_NONE);156AttributeMap surfAttributes = AttributeMap::CreateFromIntArray(&surfaceAttributes[0]);157158// Create first window surface159egl::Surface *surface = nullptr;160ANGLE_EGL_TRY_RETURN(161thread,162display->createWindowSurface(configuration, WindowFromDC(hDc), surfAttributes, &surface),163"wglCreateContext", display, nullptr);164165// Initialize context166EGLint contextAttibutes[] = {EGL_CONTEXT_CLIENT_VERSION, 4, EGL_CONTEXT_MINOR_VERSION, 6,167EGL_NONE};168169gl::Context *sharedGLContext = static_cast<gl::Context *>(nullptr);170AttributeMap ctxAttributes = AttributeMap::CreateFromIntArray(contextAttibutes);171172gl::Context *context = nullptr;173174ANGLE_EGL_TRY_RETURN(thread,175display->createContext(configuration, sharedGLContext, EGL_OPENGL_API,176ctxAttributes, &context),177"wglCreateContext", display, nullptr);178179return reinterpret_cast<HGLRC>(context);180}181182HGLRC GL_APIENTRY wglCreateLayerContext(HDC hDc, int level)183{184UNIMPLEMENTED();185return nullptr;186}187188BOOL GL_APIENTRY wglDeleteContext(HGLRC oldContext)189{190UNIMPLEMENTED();191return FALSE;192}193194BOOL GL_APIENTRY wglDescribeLayerPlane(HDC hDc,195int pixelFormat,196int layerPlane,197UINT nBytes,198LAYERPLANEDESCRIPTOR *plpd)199{200UNIMPLEMENTED();201return FALSE;202}203204HGLRC GL_APIENTRY wglGetCurrentContext()205{206UNIMPLEMENTED();207return nullptr;208}209210HDC GL_APIENTRY wglGetCurrentDC()211{212UNIMPLEMENTED();213return nullptr;214}215216int GL_APIENTRY217wglGetLayerPaletteEntries(HDC hdc, int iLayerPlane, int iStart, int cEntries, COLORREF *pcr)218{219UNIMPLEMENTED();220return 0;221}222223PROC GL_APIENTRY wglGetProcAddress(LPCSTR lpszProc)224{225ANGLE_SCOPED_GLOBAL_LOCK();226WGL_EVENT(GetProcAddress, "const char *procname = \"%s\"", lpszProc);227egl::Thread *thread = egl::GetCurrentThread();228229const ProcEntry *entry =230std::lower_bound(&g_procTable[0], &g_procTable[g_numProcs], lpszProc, CompareProc);231232thread->setSuccess();233234if (entry == &g_procTable[g_numProcs] || strcmp(entry->first, lpszProc) != 0)235{236return nullptr;237}238239return entry->second;240}241242BOOL GL_APIENTRY wglMakeCurrent(HDC hDc, HGLRC newContext)243{244Thread *thread = egl::GetCurrentThread();245egl::Display *display = egl::Display::GetExistingDisplayFromNativeDisplay(hDc);246const gl::Context *context =247GetContextIfValid(display, reinterpret_cast<gl::Context *>(newContext));248249ScopedSyncCurrentContextFromThread scopedSyncCurrent(thread);250251// If display or context are invalid, make thread's current rendering context not current252if (!context)253{254gl::Context *oldContext = thread->getContext();255if (oldContext)256{257ANGLE_EGL_TRY_RETURN(thread, oldContext->unMakeCurrent(display), "wglMakeCurrent",258GetContextIfValid(display, oldContext), EGL_FALSE);259thread->setCurrent(nullptr);260}261return TRUE;262}263264egl::Surface *surface = display->getWGLSurface();265Surface *previousDraw = thread->getCurrentDrawSurface();266Surface *previousRead = thread->getCurrentReadSurface();267gl::Context *previousContext = thread->getContext();268269if (previousDraw != surface || previousRead != surface || previousContext != context)270{271ANGLE_EGL_TRY_RETURN(thread,272display->makeCurrent(thread, previousContext, surface, surface,273const_cast<gl::Context *>(context)),274"wglMakeCurrent", GetContextIfValid(display, context), EGL_FALSE);275}276277return TRUE;278}279280BOOL GL_APIENTRY wglRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)281{282UNIMPLEMENTED();283return FALSE;284}285286int GL_APIENTRY287wglSetLayerPaletteEntries(HDC hdc, int iLayerPlane, int iStart, int cEntries, const COLORREF *pcr)288{289UNIMPLEMENTED();290return 0;291}292293BOOL GL_APIENTRY wglShareLists(HGLRC hrcSrvShare, HGLRC hrcSrvSource)294{295UNIMPLEMENTED();296return FALSE;297}298299BOOL GL_APIENTRY wglSwapLayerBuffers(HDC hdc, UINT fuFlags)300{301UNIMPLEMENTED();302return FALSE;303}304305BOOL GL_APIENTRY wglUseFontBitmapsA(HDC hDC, DWORD first, DWORD count, DWORD listBase)306{307UNIMPLEMENTED();308return FALSE;309}310311BOOL GL_APIENTRY wglUseFontBitmapsW(HDC hDC, DWORD first, DWORD count, DWORD listBase)312{313UNIMPLEMENTED();314return FALSE;315}316317BOOL GL_APIENTRY wglUseFontOutlinesA(HDC hDC,318DWORD first,319DWORD count,320DWORD listBase,321FLOAT deviation,322FLOAT extrusion,323int format,324LPGLYPHMETRICSFLOAT lpgmf)325{326UNIMPLEMENTED();327return FALSE;328}329330BOOL GL_APIENTRY wglUseFontOutlinesW(HDC hDC,331DWORD first,332DWORD count,333DWORD listBase,334FLOAT deviation,335FLOAT extrusion,336int format,337LPGLYPHMETRICSFLOAT lpgmf)338{339UNIMPLEMENTED();340return FALSE;341}342343} // extern "C"344345346