Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrGLMakeNativeInterface_win.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8#if defined(SK_BUILD_FOR_WIN)
9
11
15
16#include <memory>
17#include <type_traits>
18
19#if defined(_M_ARM64)
20
22
23#else
24/*
25 * Windows makes the GL funcs all be __stdcall instead of __cdecl :(
26 * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall.
27 * Otherwise, a springboard would be needed that hides the calling convention.
28 */
30 if (nullptr == wglGetCurrentContext()) {
31 return nullptr;
32 }
33
34 struct FreeModule { void operator()(HMODULE m) { (void)FreeLibrary(m); } };
35 std::unique_ptr<typename std::remove_pointer<HMODULE>::type, FreeModule> module(
36 LoadLibraryA("opengl32.dll"));
37 if (!module) {
38 return nullptr;
39 }
40 const GrGLGetProc win_get_gl_proc = [](void* ctx, const char* name) {
41 SkASSERT(wglGetCurrentContext());
42 if (GrGLFuncPtr p = (GrGLFuncPtr)GetProcAddress((HMODULE)ctx, name)) {
43 return p;
44 }
45 if (GrGLFuncPtr p = (GrGLFuncPtr)wglGetProcAddress(name)) {
46 return p;
47 }
48 return (GrGLFuncPtr)nullptr;
49 };
50
51 GrGLGetStringFn* getString =
52 (GrGLGetStringFn*)win_get_gl_proc((void*)module.get(), "glGetString");
53 if (!getString) {
54 return nullptr;
55 }
56 const char* verStr = reinterpret_cast<const char*>(getString(GR_GL_VERSION));
58
59 if (GR_IS_GR_GL_ES(standard)) {
60 return GrGLMakeAssembledGLESInterface((void*)module.get(), win_get_gl_proc);
61 } else if (GR_IS_GR_GL(standard)) {
62 return GrGLMakeAssembledGLInterface((void*)module.get(), win_get_gl_proc);
63 }
64 return nullptr;
65}
66
67#endif // ARM64
68
69#endif//defined(SK_BUILD_FOR_WIN)
SK_API sk_sp< const GrGLInterface > GrGLMakeAssembledGLInterface(void *ctx, GrGLGetProc get)
GrGLFuncPtr(* GrGLGetProc)(void *ctx, const char name[])
SK_API sk_sp< const GrGLInterface > GrGLMakeAssembledGLESInterface(void *ctx, GrGLGetProc get)
#define GR_GL_VERSION
const GrGLubyte *GR_GL_FUNCTION_TYPE(GrGLenum name) GrGLGetStringFn
SK_API sk_sp< const GrGLInterface > GrGLMakeNativeInterface()
void(* GrGLFuncPtr)()
GrGLStandard
Definition GrGLTypes.h:19
#define GR_IS_GR_GL(standard)
Definition GrGLTypes.h:48
#define GR_IS_GR_GL_ES(standard)
Definition GrGLTypes.h:49
GrGLStandard GrGLGetStandardInUseFromString(const char *versionString)
Definition GrGLUtil.cpp:31
#define SkASSERT(cond)
Definition SkAssert.h:116
const char * name
Definition fuchsia.cc:50
HINSTANCE HMODULE